package dev.fyloz.plannervio.core.service

import dev.fyloz.plannervio.core.model.Board
import dev.fyloz.plannervio.core.model.board
import dev.fyloz.plannervio.core.repository.IBoardRepository
import io.mockk.clearAllMocks
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.kodein.di.DI
import org.kodein.di.bind
import org.kodein.di.singleton
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class BoardServiceImplTest {
    private val di: DI = DI {
        bind<IBoardRepository>() with singleton { repository }
    }

    private val repository: IBoardRepository = mockk()
    private val service: IBoardService = BoardServiceImpl(di)

    @BeforeEach
    fun setUp() {
        clearAllMocks()
    }

    @Nested
    inner class GetBoards {
        @Test
        fun `all boards are included`() {
            val boards: List<Board> = listOf(
                    board(0L),
                    board(1L)
            )
            every { repository.findAll() } returns boards

            val found = service.getBoards()

            assertEquals(boards, found)
        }

        @Test
        fun `no boards are included`() {
            every { repository.findAll() } returns listOf()

            val found = service.getBoards()

            assertTrue { found.isEmpty() }
        }
    }
}
