From 589e6d3399372c2b8f7102d9976d7d0a68b1f826 Mon Sep 17 00:00:00 2001 From: Vladislav Kadiaev Date: Tue, 19 May 2026 19:03:04 +0400 Subject: [PATCH] ECOM-16792 - add all parent categories ids to fetched product --- .../v3/dto/product/result/FetchedProduct.kt | 1 + .../gson/GsonTransformerTest.kt | 19 +++++++++++++++++++ .../v3/rule/NullablePropertyRules.kt | 3 +++ 3 files changed, 23 insertions(+) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt index ba127ce59..f0c31b351 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/product/result/FetchedProduct.kt @@ -196,6 +196,7 @@ data class FetchedProduct( val enabled: Boolean = true, val name: String = "", val nameTranslated: String = "", + val ancestorIds: List? = null, ) data class TaxInfo( 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 780d29497..16969bae5 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 @@ -3,10 +3,12 @@ package com.ecwid.apiclient.v3.jsontransformer.gson 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.impl.ParsedResponseWithExt import com.google.gson.JsonParser import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import kotlin.test.assertNull internal class GsonTransformerTest { @@ -230,6 +232,23 @@ internal class GsonTransformerTest { ) } + @Test + fun `test deserialization of FetchedProduct CategoryInfo with ancestorIds`() { + val json = """{"categories": [{"id": 42, "enabled": true, "name": "Cat", "nameTranslated": "", "ancestorIds": [1, 7]}]}""" + val product = transformer.deserialize(json, FetchedProduct::class.java) + assertEquals( + listOf(FetchedProduct.CategoryInfo(id = 42, enabled = true, name = "Cat", nameTranslated = "", ancestorIds = listOf(1L, 7L))), + product.categories + ) + } + + @Test + fun `test deserialization of FetchedProduct CategoryInfo without ancestorIds defaults to null`() { + val json = """{"categories": [{"id": 42, "enabled": true, "name": "Cat", "nameTranslated": ""}]}""" + val product = transformer.deserialize(json, FetchedProduct::class.java) + assertNull(product.categories?.first()?.ancestorIds) + } + @Test fun `deserializeOrNull of broken ParsedResponseWithExt`() { val json = "'testField': {'baseField': 'base', 'extField': 'ext'}}" diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt index 42d29f5ef..5feb38472 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt @@ -13,6 +13,7 @@ import com.ecwid.apiclient.v3.dto.order.result.DeletedOrder import com.ecwid.apiclient.v3.dto.payment.PaymentAppRequest import com.ecwid.apiclient.v3.dto.product.request.ProductInventoryUpdateRequest import com.ecwid.apiclient.v3.dto.product.request.ProductUpdateRequest +import com.ecwid.apiclient.v3.dto.product.result.FetchedProduct.CategoryInfo import com.ecwid.apiclient.v3.dto.product.result.GetProductFiltersResult import com.ecwid.apiclient.v3.dto.product.result.ProductInventoryUpdateResult import com.ecwid.apiclient.v3.dto.productreview.request.UpdatedProductReviewStatus @@ -161,6 +162,8 @@ val otherNullablePropertyRules: List> = listOf( AllowNullable(CustomerGroupsSearchRequest::keyword), AllowNullable(CustomerGroupsSearchRequest::customerGroupIds), + + AllowNullable(CategoryInfo::ancestorIds) ) val nullablePropertyRules: List> = listOf(