package dev.fyloz.trial.colorrecipesexplorer.service

import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.spy
import dev.fyloz.trial.colorrecipesexplorer.model.*
import dev.fyloz.trial.colorrecipesexplorer.repository.RecipeStepRepository
import org.junit.jupiter.api.Nested
import kotlin.test.assertEquals

class RecipeStepServiceTest :
    AbstractModelServiceTest<RecipeStep, RecipeStepService, RecipeStepRepository>() {
    override val repository: RecipeStepRepository = mock()
    override val service: RecipeStepService = spy(RecipeStepServiceImpl(repository))

    override val entity: RecipeStep = recipeStep(id = 0L, recipe = TODO(), message = "message")
    override val anotherEntity: RecipeStep = recipeStep(id = 1L, recipe = TODO(), message = "another message")

    @Nested
    inner class CreateForRecipe {
        fun `returns a correct RecipeStep`() {
            val step = recipeStep(null, entity.recipe, entity.message)

            val found = service.createForRecipe(entity.recipe!!, entity.message)

            assertEquals(step, found)
        }
    }

    @Nested
    inner class CreateAllForRecipe {
        fun `returns all correct RecipeSteps`() {
            val steps = listOf(
                recipeStep(null, entity.recipe, entity.message),
                recipeStep(null, entity.recipe, anotherEntity.message)
            )
            val messages = steps.map { it.message }

            val found = service.createAllForRecipe(entity.recipe!!, messages)

            assertEquals(steps, found)
        }
    }
}
