From 4c875ecd9f02da4a311327d608ceaa4fb5b73879 Mon Sep 17 00:00:00 2001 From: "roman.ivshin" Date: Tue, 3 Nov 2026 15:55:22 +0400 Subject: [PATCH] ECOM-64901 - add orderBy field's support to variations for GET requests only --- .../dto/variation/result/FetchedVariation.kt | 1 + .../gson/GsonTransformerTest.kt | 27 +++++++++++++++++++ .../v3/rule/NonUpdatablePropertyRules.kt | 1 + .../FetchedVariationRules.kt | 1 + 4 files changed, 30 insertions(+) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt index 67108e4d2..ae3f81a2f 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/variation/result/FetchedVariation.kt @@ -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( diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/jsontransformer/gson/GsonTransformerTest.kt b/src/test/kotlin/com/ecwid/apiclient/v3/jsontransformer/gson/GsonTransformerTest.kt index 16969bae5..40b4e9635 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/jsontransformer/gson/GsonTransformerTest.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/jsontransformer/gson/GsonTransformerTest.kt @@ -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 { @@ -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'}}" diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonUpdatablePropertyRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonUpdatablePropertyRules.kt index 3d3e180cc..7c804bccc 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonUpdatablePropertyRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NonUpdatablePropertyRules.kt @@ -281,6 +281,7 @@ val nonUpdatablePropertyRules: List> = listOf( ReadOnly(FetchedVariation::id), Ignored(FetchedVariation::combinationNumber), + ReadOnly(FetchedVariation::orderBy), Ignored(FetchedVariation.Option::nameTranslated), Ignored(FetchedVariation.Option::valueTranslated), Ignored(FetchedVariation::smallThumbnailUrl), diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedVariationRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedVariationRules.kt index 0f5457c0e..a56574441 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedVariationRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/nullablepropertyrules/FetchedVariationRules.kt @@ -7,6 +7,7 @@ import com.ecwid.apiclient.v3.rule.NullablePropertyRule.AllowNullable import com.ecwid.apiclient.v3.rule.NullablePropertyRule.IgnoreNullable val fetchedVariationTypeNullablePropertyRules: List> = listOf( + AllowNullable(FetchedVariation::orderBy), IgnoreNullable(FetchedVariation::attributes), AllowNullable(FetchedVariation::borderInfo), IgnoreNullable(FetchedVariation::compareToPrice),