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 @@ -196,6 +196,7 @@ data class FetchedProduct(
val enabled: Boolean = true,
val name: String = "",
val nameTranslated: String = "",
val ancestorIds: List<Long>? = null,
)

data class TaxInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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'}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -161,6 +162,8 @@ val otherNullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(

AllowNullable(CustomerGroupsSearchRequest::keyword),
AllowNullable(CustomerGroupsSearchRequest::customerGroupIds),

AllowNullable(CategoryInfo::ancestorIds)
)

val nullablePropertyRules: List<NullablePropertyRule<*, *>> = listOf(
Expand Down
Loading