Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ data class FetchedVariation(
val customsHsTariffCode: String? = null,
val subscriptionSettings: SubscriptionSettings? = null,
val alt: FetchedAlt? = null,
val orderBy: Int? = null,
) : ApiFetchedDTO, ApiResultDTO {

data class AttributeValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import com.ecwid.apiclient.v3.dto.common.NullableUpdatedValue
import com.ecwid.apiclient.v3.dto.order.request.UpdatedOrder
import com.ecwid.apiclient.v3.dto.product.request.UpdatedProduct
import com.ecwid.apiclient.v3.dto.product.result.FetchedProduct
import com.ecwid.apiclient.v3.dto.variation.result.FetchedVariation
import com.ecwid.apiclient.v3.impl.ParsedResponseWithExt
import com.google.gson.JsonParser
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import kotlin.test.assertNull

internal class GsonTransformerTest {
Expand Down Expand Up @@ -249,6 +252,30 @@ internal class GsonTransformerTest {
assertNull(product.categories?.first()?.ancestorIds)
}

@Test
fun `test deserialization of FetchedVariation with orderBy`() {
val json = """{"id": 123, "combinationNumber": 4, "orderBy": 2}"""

val variation = transformer.deserialize(json, FetchedVariation::class.java)

assertEquals(2, variation.orderBy)
assertEquals(4, variation.combinationNumber)
}

@ParameterizedTest
@ValueSource(
strings = [
"""{"id": 123, "combinationNumber": 4}""",
"""{"id": 123, "combinationNumber": 4, "orderBy": null}""",
]
)
fun `test deserialization of FetchedVariation without orderBy defaults to null`(json: String) {
val variation = transformer.deserialize(json, FetchedVariation::class.java)

assertNull(variation.orderBy)
assertEquals(4, variation.combinationNumber)
}

@Test
fun `deserializeOrNull of broken ParsedResponseWithExt`() {
val json = "'testField': {'baseField': 'base', 'extField': 'ext'}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ val nonUpdatablePropertyRules: List<NonUpdatablePropertyRule<*, *>> = listOf(

ReadOnly(FetchedVariation::id),
Ignored(FetchedVariation::combinationNumber),
ReadOnly(FetchedVariation::orderBy),
Ignored(FetchedVariation.Option::nameTranslated),
Ignored(FetchedVariation.Option::valueTranslated),
Ignored(FetchedVariation::smallThumbnailUrl),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable
import com.ecwid.apiclient.v3.rule.NullablePropertyRule.IgnoreNullable

val fetchedVariationTypeNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
AllowNullable(FetchedVariation::orderBy),
IgnoreNullable(FetchedVariation::attributes),
AllowNullable(FetchedVariation::borderInfo),
IgnoreNullable(FetchedVariation::compareToPrice),
Expand Down
Loading