package com.fabledsword.minstrel.metadata

import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.jupiter.api.Test

class HomeArtistPrewarmerTest {
    private val provider = mockk<MetadataProvider>()

    @Test
    fun `warms at most the top eight distinct ids, once per session`() {
        every { provider.refreshArtist(any()) } returns mockk(relaxed = true)
        val prewarmer = HomeArtistPrewarmer(provider)

        // 10 ids with a duplicate and a blank -> 8 distinct non-blank warmed.
        prewarmer.warm(listOf("a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", ""))
        // Re-warm: already-warmed ids are skipped.
        prewarmer.warm(listOf("a1", "a2"))

        (1..8).forEach { i -> verify(exactly = 1) { provider.refreshArtist("a$i") } }
        verify(exactly = 0) { provider.refreshArtist("a9") }   // past the top-8 cap
        verify(exactly = 0) { provider.refreshArtist("") }     // blank skipped
    }
}
