package dev.fyloz.trial.colorrecipesexplorer.repository

import dev.fyloz.trial.colorrecipesexplorer.model.material
import dev.fyloz.trial.colorrecipesexplorer.model.mixMaterial
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager
import kotlin.test.assertFalse
import kotlin.test.assertTrue

@DataJpaTest
class MixMaterialRepositoryTest @Autowired constructor(
    private val mixMaterialRepository: MixMaterialRepository,
    val entityManager: TestEntityManager
) {
    private val material = material(id = 0L)
    private val mixMaterial = mixMaterial(id = 0L, material = material)
    private val anotherMixMaterial = mixMaterial(id = 1L, material = material(id = 1L))

    @Test
    fun `existsByMaterial() returns true when a mix material with the given material exists`() {
        entityManager.persist(mixMaterial)

        val exists = mixMaterialRepository.existsByMaterial(material)

        assertTrue(exists)
    }

    @Test
    fun `existsByMaterial() returns false when no mix material with the given material exists`() {
        entityManager.persist(anotherMixMaterial)

        val exists = mixMaterialRepository.existsByMaterial(material)

        assertFalse(exists)
    }
}
