Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MkhytarMkhoian/d75dc30f3d77e6466fd6a6ab8396896c to your computer and use it in GitHub Desktop.
Save MkhytarMkhoian/d75dc30f3d77e6466fd6a6ab8396896c to your computer and use it in GitHub Desktop.
class GetCategoriesFromIdsUseCaseTest {
private val categoriesRepository: CategoriesRepository = mockk(relaxed = true)
private val getCategoriesFromIdsUseCase = GetCategoriesFromIdsUseCase(
categoriesRepository = categoriesRepository
)
@Test
fun `On invoke should return correct list of categories`() = runTest {
// Given
val child1CategoryId = Category.CATEGORY_PRO
val child1: Category = mockk {
every { categoryId } returns child1CategoryId
}
val child2CategoryId = CategoryId(id = -faker.number().randomNumber())
val child2: Category = mockk {
every { categoryId } returns child2CategoryId
}
val categoryTreeIds: List<CategoryId> = listOf(
child1CategoryId,
child2CategoryId,
)
val map = mapOf(
child1CategoryId to child1,
child2CategoryId to child2,
)
coEvery { categoriesRepository.getCategories() } returns map
// When
val result = getCategoriesFromIdsUseCase(categoryTreeIds)
// Then
assertContains(result, child1)
assertContains(result, child2)
coVerify { categoriesRepository.getCategories() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment