Move V0 responses to v0 package
This commit is contained in:
@@ -2,8 +2,8 @@ package gq.kirmanak.mealient.data.network
|
||||
|
||||
import gq.kirmanak.mealient.data.auth.AuthRepo
|
||||
import gq.kirmanak.mealient.data.baseurl.BaseURLStorage
|
||||
import gq.kirmanak.mealient.datasource.MealieDataSource
|
||||
import gq.kirmanak.mealient.datasource.models.NetworkError
|
||||
import gq.kirmanak.mealient.datasource.NetworkError
|
||||
import gq.kirmanak.mealient.datasource.v0.MealieDataSourceV0
|
||||
import gq.kirmanak.mealient.test.AuthImplTestData.TEST_AUTH_HEADER
|
||||
import gq.kirmanak.mealient.test.AuthImplTestData.TEST_BASE_URL
|
||||
import gq.kirmanak.mealient.test.RecipeImplTestData.GET_CAKE_RESPONSE
|
||||
@@ -18,7 +18,7 @@ import org.junit.Test
|
||||
import java.io.IOException
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class MealieDataSourceWrapperTest {
|
||||
class MealieDataSourceV0WrapperTest {
|
||||
|
||||
@MockK
|
||||
lateinit var baseURLStorage: BaseURLStorage
|
||||
@@ -27,14 +27,14 @@ class MealieDataSourceWrapperTest {
|
||||
lateinit var authRepo: AuthRepo
|
||||
|
||||
@MockK
|
||||
lateinit var mealieDataSource: MealieDataSource
|
||||
lateinit var mealieDataSourceV0: MealieDataSourceV0
|
||||
|
||||
lateinit var subject: MealieDataSourceWrapper
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockKAnnotations.init(this)
|
||||
subject = MealieDataSourceWrapper(baseURLStorage, authRepo, mealieDataSource)
|
||||
subject = MealieDataSourceWrapper(baseURLStorage, authRepo, mealieDataSourceV0)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,10 +42,10 @@ class MealieDataSourceWrapperTest {
|
||||
coEvery { baseURLStorage.requireBaseURL() } returns TEST_BASE_URL
|
||||
coEvery { authRepo.getAuthHeader() } returns null andThen TEST_AUTH_HEADER
|
||||
coEvery {
|
||||
mealieDataSource.requestRecipeInfo(eq(TEST_BASE_URL), isNull(), eq("cake"))
|
||||
mealieDataSourceV0.requestRecipeInfo(eq(TEST_BASE_URL), isNull(), eq("cake"))
|
||||
} throws NetworkError.Unauthorized(IOException())
|
||||
coEvery {
|
||||
mealieDataSource.requestRecipeInfo(eq(TEST_BASE_URL), eq(TEST_AUTH_HEADER), eq("cake"))
|
||||
mealieDataSourceV0.requestRecipeInfo(eq(TEST_BASE_URL), eq(TEST_AUTH_HEADER), eq("cake"))
|
||||
} returns GET_CAKE_RESPONSE
|
||||
subject.requestRecipeInfo("cake")
|
||||
coVerifyAll {
|
||||
@@ -6,7 +6,7 @@ import com.google.common.truth.Truth.assertThat
|
||||
import gq.kirmanak.mealient.data.recipes.db.RecipeStorage
|
||||
import gq.kirmanak.mealient.data.recipes.network.RecipeDataSource
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
|
||||
import gq.kirmanak.mealient.datasource.models.NetworkError.Unauthorized
|
||||
import gq.kirmanak.mealient.datasource.NetworkError.Unauthorized
|
||||
import gq.kirmanak.mealient.logging.Logger
|
||||
import gq.kirmanak.mealient.test.RecipeImplTestData.TEST_RECIPE_SUMMARIES
|
||||
import io.mockk.MockKAnnotations
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package gq.kirmanak.mealient.extensions
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeIngredient
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeInstruction
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeRequest
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeSettings
|
||||
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.datastore.recipe.AddRecipeDraft
|
||||
import org.junit.Test
|
||||
|
||||
@@ -22,19 +22,19 @@ class RemoteToLocalMappingsTest {
|
||||
areCommentsDisabled = true,
|
||||
)
|
||||
|
||||
val expected = AddRecipeRequest(
|
||||
val expected = AddRecipeRequestV0(
|
||||
name = "Recipe name",
|
||||
description = "Recipe description",
|
||||
recipeYield = "Recipe yield",
|
||||
recipeIngredient = listOf(
|
||||
AddRecipeIngredient(note = "Recipe ingredient 1"),
|
||||
AddRecipeIngredient(note = "Recipe ingredient 2")
|
||||
AddRecipeIngredientV0(note = "Recipe ingredient 1"),
|
||||
AddRecipeIngredientV0(note = "Recipe ingredient 2")
|
||||
),
|
||||
recipeInstructions = listOf(
|
||||
AddRecipeInstruction(text = "Recipe instruction 1"),
|
||||
AddRecipeInstruction(text = "Recipe instruction 2")
|
||||
AddRecipeInstructionV0(text = "Recipe instruction 1"),
|
||||
AddRecipeInstructionV0(text = "Recipe instruction 2")
|
||||
),
|
||||
settings = AddRecipeSettings(
|
||||
settings = AddRecipeSettingsV0(
|
||||
public = false,
|
||||
disableComments = true,
|
||||
)
|
||||
@@ -45,19 +45,19 @@ class RemoteToLocalMappingsTest {
|
||||
|
||||
@Test
|
||||
fun `when toDraft then fills fields correctly`() {
|
||||
val request = AddRecipeRequest(
|
||||
val request = AddRecipeRequestV0(
|
||||
name = "Recipe name",
|
||||
description = "Recipe description",
|
||||
recipeYield = "Recipe yield",
|
||||
recipeIngredient = listOf(
|
||||
AddRecipeIngredient(note = "Recipe ingredient 1"),
|
||||
AddRecipeIngredient(note = "Recipe ingredient 2")
|
||||
AddRecipeIngredientV0(note = "Recipe ingredient 1"),
|
||||
AddRecipeIngredientV0(note = "Recipe ingredient 2")
|
||||
),
|
||||
recipeInstructions = listOf(
|
||||
AddRecipeInstruction(text = "Recipe instruction 1"),
|
||||
AddRecipeInstruction(text = "Recipe instruction 2")
|
||||
AddRecipeInstructionV0(text = "Recipe instruction 1"),
|
||||
AddRecipeInstructionV0(text = "Recipe instruction 2")
|
||||
),
|
||||
settings = AddRecipeSettings(
|
||||
settings = AddRecipeSettingsV0(
|
||||
public = false,
|
||||
disableComments = true,
|
||||
)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package gq.kirmanak.mealient.test
|
||||
|
||||
import gq.kirmanak.mealient.database.recipe.entity.*
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeIngredientResponse
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeInstructionResponse
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeResponse
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeSummaryResponse
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeIngredientResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeInstructionResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeSummaryResponseV0
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
|
||||
object RecipeImplTestData {
|
||||
val RECIPE_SUMMARY_CAKE = GetRecipeSummaryResponse(
|
||||
val RECIPE_SUMMARY_CAKE = GetRecipeSummaryResponseV0(
|
||||
remoteId = 1,
|
||||
name = "Cake",
|
||||
slug = "cake",
|
||||
@@ -22,7 +22,7 @@ object RecipeImplTestData {
|
||||
dateUpdated = LocalDateTime.parse("2021-11-13T15:30:13"),
|
||||
)
|
||||
|
||||
val RECIPE_SUMMARY_PORRIDGE = GetRecipeSummaryResponse(
|
||||
val RECIPE_SUMMARY_PORRIDGE = GetRecipeSummaryResponseV0(
|
||||
remoteId = 2,
|
||||
name = "Porridge",
|
||||
slug = "porridge",
|
||||
@@ -59,7 +59,7 @@ object RecipeImplTestData {
|
||||
dateUpdated = LocalDateTime.parse("2021-10-13T17:35:23"),
|
||||
)
|
||||
|
||||
private val SUGAR_INGREDIENT = GetRecipeIngredientResponse(
|
||||
private val SUGAR_INGREDIENT = GetRecipeIngredientResponseV0(
|
||||
title = "Sugar",
|
||||
note = "2 oz of white sugar",
|
||||
unit = "",
|
||||
@@ -68,7 +68,7 @@ object RecipeImplTestData {
|
||||
quantity = 1
|
||||
)
|
||||
|
||||
val BREAD_INGREDIENT = GetRecipeIngredientResponse(
|
||||
val BREAD_INGREDIENT = GetRecipeIngredientResponseV0(
|
||||
title = "Bread",
|
||||
note = "2 oz of white bread",
|
||||
unit = "",
|
||||
@@ -77,7 +77,7 @@ object RecipeImplTestData {
|
||||
quantity = 2
|
||||
)
|
||||
|
||||
private val MILK_INGREDIENT = GetRecipeIngredientResponse(
|
||||
private val MILK_INGREDIENT = GetRecipeIngredientResponseV0(
|
||||
title = "Milk",
|
||||
note = "2 oz of white milk",
|
||||
unit = "",
|
||||
@@ -86,22 +86,22 @@ object RecipeImplTestData {
|
||||
quantity = 3
|
||||
)
|
||||
|
||||
val MIX_INSTRUCTION = GetRecipeInstructionResponse(
|
||||
val MIX_INSTRUCTION = GetRecipeInstructionResponseV0(
|
||||
title = "Mix",
|
||||
text = "Mix the ingredients"
|
||||
)
|
||||
|
||||
private val BAKE_INSTRUCTION = GetRecipeInstructionResponse(
|
||||
private val BAKE_INSTRUCTION = GetRecipeInstructionResponseV0(
|
||||
title = "Bake",
|
||||
text = "Bake the ingredients"
|
||||
)
|
||||
|
||||
private val BOIL_INSTRUCTION = GetRecipeInstructionResponse(
|
||||
private val BOIL_INSTRUCTION = GetRecipeInstructionResponseV0(
|
||||
title = "Boil",
|
||||
text = "Boil the ingredients"
|
||||
)
|
||||
|
||||
val GET_CAKE_RESPONSE = GetRecipeResponse(
|
||||
val GET_CAKE_RESPONSE = GetRecipeResponseV0(
|
||||
remoteId = 1,
|
||||
name = "Cake",
|
||||
slug = "cake",
|
||||
@@ -117,7 +117,7 @@ object RecipeImplTestData {
|
||||
recipeInstructions = listOf(MIX_INSTRUCTION, BAKE_INSTRUCTION)
|
||||
)
|
||||
|
||||
val GET_PORRIDGE_RESPONSE = GetRecipeResponse(
|
||||
val GET_PORRIDGE_RESPONSE = GetRecipeResponseV0(
|
||||
remoteId = 2,
|
||||
name = "Porridge",
|
||||
slug = "porridge",
|
||||
|
||||
@@ -2,7 +2,7 @@ package gq.kirmanak.mealient.ui.add
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import gq.kirmanak.mealient.data.add.AddRecipeRepo
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeRequest
|
||||
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(AddRecipeRequest())
|
||||
subject.preserve(AddRecipeRequest())
|
||||
coEvery { addRecipeRepo.addRecipeRequestFlow } returns flowOf(AddRecipeRequestV0())
|
||||
subject.preserve(AddRecipeRequestV0())
|
||||
coVerify(inverse = true) { addRecipeRepo.addRecipeRequestFlow }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when preservedAddRecipeRequest without loadPreservedRequest then empty`() = runTest {
|
||||
coEvery { addRecipeRepo.addRecipeRequestFlow } returns flowOf(AddRecipeRequest())
|
||||
coEvery { addRecipeRepo.addRecipeRequestFlow } returns flowOf(AddRecipeRequestV0())
|
||||
val actual = withTimeoutOrNull(10) { subject.preservedAddRecipeRequest.firstOrNull() }
|
||||
assertThat(actual).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when loadPreservedRequest then updates preservedAddRecipeRequest`() = runTest {
|
||||
val expected = AddRecipeRequest()
|
||||
val expected = AddRecipeRequestV0()
|
||||
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 = AddRecipeRequest()
|
||||
val expected = AddRecipeRequestV0()
|
||||
coEvery { addRecipeRepo.addRecipeRequestFlow } returns flowOf(expected)
|
||||
subject.clear()
|
||||
assertThat(subject.preservedAddRecipeRequest.first()).isSameInstanceAs(expected)
|
||||
|
||||
Reference in New Issue
Block a user