Skip to content

Commit 583bea1

Browse files
authored
Merge pull request #556 from Ecwid/ECOM-16792
ECOM-16792 - add ancestor ids to CategoryInfo
2 parents 36fe43c + 589e6d3 commit 583bea1

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ data class FetchedProduct(
196196
val enabled: Boolean = true,
197197
val name: String = "",
198198
val nameTranslated: String = "",
199+
val ancestorIds: List<Long>? = null,
199200
)
200201

201202
data class TaxInfo(

src/test/kotlin/com/ecwid/apiclient/v3/jsontransformer/gson/GsonTransformerTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package com.ecwid.apiclient.v3.jsontransformer.gson
33
import com.ecwid.apiclient.v3.dto.common.NullableUpdatedValue
44
import com.ecwid.apiclient.v3.dto.order.request.UpdatedOrder
55
import com.ecwid.apiclient.v3.dto.product.request.UpdatedProduct
6+
import com.ecwid.apiclient.v3.dto.product.result.FetchedProduct
67
import com.ecwid.apiclient.v3.impl.ParsedResponseWithExt
78
import com.google.gson.JsonParser
89
import org.junit.jupiter.api.Assertions.assertEquals
910
import org.junit.jupiter.api.Test
11+
import kotlin.test.assertNull
1012

1113
internal class GsonTransformerTest {
1214

@@ -230,6 +232,23 @@ internal class GsonTransformerTest {
230232
)
231233
}
232234

235+
@Test
236+
fun `test deserialization of FetchedProduct CategoryInfo with ancestorIds`() {
237+
val json = """{"categories": [{"id": 42, "enabled": true, "name": "Cat", "nameTranslated": "", "ancestorIds": [1, 7]}]}"""
238+
val product = transformer.deserialize(json, FetchedProduct::class.java)
239+
assertEquals(
240+
listOf(FetchedProduct.CategoryInfo(id = 42, enabled = true, name = "Cat", nameTranslated = "", ancestorIds = listOf(1L, 7L))),
241+
product.categories
242+
)
243+
}
244+
245+
@Test
246+
fun `test deserialization of FetchedProduct CategoryInfo without ancestorIds defaults to null`() {
247+
val json = """{"categories": [{"id": 42, "enabled": true, "name": "Cat", "nameTranslated": ""}]}"""
248+
val product = transformer.deserialize(json, FetchedProduct::class.java)
249+
assertNull(product.categories?.first()?.ancestorIds)
250+
}
251+
233252
@Test
234253
fun `deserializeOrNull of broken ParsedResponseWithExt`() {
235254
val json = "'testField': {'baseField': 'base', 'extField': 'ext'}}"

src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.ecwid.apiclient.v3.dto.order.result.DeletedOrder
1313
import com.ecwid.apiclient.v3.dto.payment.PaymentAppRequest
1414
import com.ecwid.apiclient.v3.dto.product.request.ProductInventoryUpdateRequest
1515
import com.ecwid.apiclient.v3.dto.product.request.ProductUpdateRequest
16+
import com.ecwid.apiclient.v3.dto.product.result.FetchedProduct.CategoryInfo
1617
import com.ecwid.apiclient.v3.dto.product.result.GetProductFiltersResult
1718
import com.ecwid.apiclient.v3.dto.product.result.ProductInventoryUpdateResult
1819
import com.ecwid.apiclient.v3.dto.productreview.request.UpdatedProductReviewStatus
@@ -161,6 +162,8 @@ val otherNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
161162

162163
AllowNullable(CustomerGroupsSearchRequest::keyword),
163164
AllowNullable(CustomerGroupsSearchRequest::customerGroupIds),
165+
166+
AllowNullable(CategoryInfo::ancestorIds)
164167
)
165168

166169
val nullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(

0 commit comments

Comments
 (0)