@@ -3,10 +3,12 @@ package com.ecwid.apiclient.v3.jsontransformer.gson
33import com.ecwid.apiclient.v3.dto.common.NullableUpdatedValue
44import com.ecwid.apiclient.v3.dto.order.request.UpdatedOrder
55import com.ecwid.apiclient.v3.dto.product.request.UpdatedProduct
6+ import com.ecwid.apiclient.v3.dto.product.result.FetchedProduct
67import com.ecwid.apiclient.v3.impl.ParsedResponseWithExt
78import com.google.gson.JsonParser
89import org.junit.jupiter.api.Assertions.assertEquals
910import org.junit.jupiter.api.Test
11+ import kotlin.test.assertNull
1012
1113internal 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'}}"
0 commit comments