Create separate model for v1 add recipe request
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package gq.kirmanak.mealient.extensions
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeIngredientV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeInstructionV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeRequestV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeSettingsV0
|
||||
import gq.kirmanak.mealient.data.add.AddRecipeInfo
|
||||
import gq.kirmanak.mealient.data.add.AddRecipeIngredientInfo
|
||||
import gq.kirmanak.mealient.data.add.AddRecipeInstructionInfo
|
||||
import gq.kirmanak.mealient.data.add.AddRecipeSettingsInfo
|
||||
import gq.kirmanak.mealient.datastore.recipe.AddRecipeDraft
|
||||
import org.junit.Test
|
||||
|
||||
@@ -22,42 +22,42 @@ class RemoteToLocalMappingsTest {
|
||||
areCommentsDisabled = true,
|
||||
)
|
||||
|
||||
val expected = AddRecipeRequestV0(
|
||||
val expected = AddRecipeInfo(
|
||||
name = "Recipe name",
|
||||
description = "Recipe description",
|
||||
recipeYield = "Recipe yield",
|
||||
recipeIngredient = listOf(
|
||||
AddRecipeIngredientV0(note = "Recipe ingredient 1"),
|
||||
AddRecipeIngredientV0(note = "Recipe ingredient 2")
|
||||
AddRecipeIngredientInfo(note = "Recipe ingredient 1"),
|
||||
AddRecipeIngredientInfo(note = "Recipe ingredient 2")
|
||||
),
|
||||
recipeInstructions = listOf(
|
||||
AddRecipeInstructionV0(text = "Recipe instruction 1"),
|
||||
AddRecipeInstructionV0(text = "Recipe instruction 2")
|
||||
AddRecipeInstructionInfo(text = "Recipe instruction 1"),
|
||||
AddRecipeInstructionInfo(text = "Recipe instruction 2")
|
||||
),
|
||||
settings = AddRecipeSettingsV0(
|
||||
settings = AddRecipeSettingsInfo(
|
||||
public = false,
|
||||
disableComments = true,
|
||||
)
|
||||
)
|
||||
|
||||
assertThat(input.toAddRecipeRequest()).isEqualTo(expected)
|
||||
assertThat(input.toAddRecipeInfo()).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when toDraft then fills fields correctly`() {
|
||||
val request = AddRecipeRequestV0(
|
||||
val request = AddRecipeInfo(
|
||||
name = "Recipe name",
|
||||
description = "Recipe description",
|
||||
recipeYield = "Recipe yield",
|
||||
recipeIngredient = listOf(
|
||||
AddRecipeIngredientV0(note = "Recipe ingredient 1"),
|
||||
AddRecipeIngredientV0(note = "Recipe ingredient 2")
|
||||
AddRecipeIngredientInfo(note = "Recipe ingredient 1"),
|
||||
AddRecipeIngredientInfo(note = "Recipe ingredient 2")
|
||||
),
|
||||
recipeInstructions = listOf(
|
||||
AddRecipeInstructionV0(text = "Recipe instruction 1"),
|
||||
AddRecipeInstructionV0(text = "Recipe instruction 2")
|
||||
AddRecipeInstructionInfo(text = "Recipe instruction 1"),
|
||||
AddRecipeInstructionInfo(text = "Recipe instruction 2")
|
||||
),
|
||||
settings = AddRecipeSettingsV0(
|
||||
settings = AddRecipeSettingsInfo(
|
||||
public = false,
|
||||
disableComments = true,
|
||||
)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gq.kirmanak.mealient.ui.add
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import gq.kirmanak.mealient.data.add.AddRecipeInfo
|
||||
import gq.kirmanak.mealient.data.add.AddRecipeRepo
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeRequestV0
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.coEvery
|
||||
@@ -61,21 +61,21 @@ class AddRecipeViewModelTest {
|
||||
|
||||
@Test
|
||||
fun `when preserve then doesn't update UI`() {
|
||||
coEvery { addRecipeRepo.addRecipeRequestFlow } returns flowOf(AddRecipeRequestV0())
|
||||
subject.preserve(AddRecipeRequestV0())
|
||||
coEvery { addRecipeRepo.addRecipeRequestFlow } returns flowOf(AddRecipeInfo())
|
||||
subject.preserve(AddRecipeInfo())
|
||||
coVerify(inverse = true) { addRecipeRepo.addRecipeRequestFlow }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when preservedAddRecipeRequest without loadPreservedRequest then empty`() = runTest {
|
||||
coEvery { addRecipeRepo.addRecipeRequestFlow } returns flowOf(AddRecipeRequestV0())
|
||||
coEvery { addRecipeRepo.addRecipeRequestFlow } returns flowOf(AddRecipeInfo())
|
||||
val actual = withTimeoutOrNull(10) { subject.preservedAddRecipeRequest.firstOrNull() }
|
||||
assertThat(actual).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when loadPreservedRequest then updates preservedAddRecipeRequest`() = runTest {
|
||||
val expected = AddRecipeRequestV0()
|
||||
val expected = AddRecipeInfo()
|
||||
coEvery { addRecipeRepo.addRecipeRequestFlow } returns flowOf(expected)
|
||||
subject.loadPreservedRequest()
|
||||
assertThat(subject.preservedAddRecipeRequest.first()).isSameInstanceAs(expected)
|
||||
@@ -83,7 +83,7 @@ class AddRecipeViewModelTest {
|
||||
|
||||
@Test
|
||||
fun `when clear then updates preservedAddRecipeRequest`() = runTest {
|
||||
val expected = AddRecipeRequestV0()
|
||||
val expected = AddRecipeInfo()
|
||||
coEvery { addRecipeRepo.addRecipeRequestFlow } returns flowOf(expected)
|
||||
subject.clear()
|
||||
assertThat(subject.preservedAddRecipeRequest.first()).isSameInstanceAs(expected)
|
||||
|
||||
Reference in New Issue
Block a user