Skip to content
Open
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
@@ -1,5 +1,6 @@
package org.wordpress.android.fluxc.model.pos

import com.google.gson.JsonElement
import com.google.gson.annotations.SerializedName

/**
Expand Down Expand Up @@ -49,7 +50,7 @@ data class WooPosVariationApiResponse(
val backordered: Boolean = false,

@SerializedName("attributes")
val attributes: List<VariationAttribute> = emptyList(),
val attributes: JsonElement? = null,

@SerializedName("image")
val image: VariationImage? = null,
Expand All @@ -60,17 +61,6 @@ data class WooPosVariationApiResponse(
@SerializedName("name")
val name: String = ""
) {
data class VariationAttribute(
@SerializedName("id")
val id: Long = 0L,

@SerializedName("name")
val name: String = "",

@SerializedName("option")
val option: String = ""
)

data class VariationImage(
@SerializedName("id")
val id: Long = 0L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun WooPosVariationApiResponse.mapToPosVariationModel(
stockStatus = this.stockStatus,
manageStock = this.manageStock,
backordered = this.backordered,
attributesJson = this.attributes.toString(),
attributesJson = this.attributes?.toString() ?: "[]",
imageUrl = this.image?.src ?: "",
status = this.status,
downloadable = this.downloadable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.fluxc.network.rest.wpcom.wc.product.pos

import com.google.gson.JsonParser
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.wordpress.android.fluxc.model.LocalOrRemoteId
Expand All @@ -26,10 +27,7 @@ class WooPosVariationMapperTest {
stockStatus = "instock",
manageStock = true,
backordered = false,
attributes = listOf(
WooPosVariationApiResponse.VariationAttribute(1, "Color", "Blue"),
WooPosVariationApiResponse.VariationAttribute(2, "Size", "Large")
),
attributes = JsonParser.parseString("""[{"id":1,"name":"Color","option":"Blue"},{"id":2,"name":"Size","option":"Large"}]"""),
image = WooPosVariationApiResponse.VariationImage(
id = 789,
src = "https://example.com/image.jpg",
Expand Down Expand Up @@ -105,7 +103,7 @@ class WooPosVariationMapperTest {
val response = WooPosVariationApiResponse(
id = 123L,
productId = 456L,
attributes = emptyList()
attributes = JsonParser.parseString("[]")
)

// When
Expand All @@ -121,11 +119,7 @@ class WooPosVariationMapperTest {
val response = WooPosVariationApiResponse(
id = 123L,
productId = 456L,
attributes = listOf(
WooPosVariationApiResponse.VariationAttribute(1, "Color", "Red"),
WooPosVariationApiResponse.VariationAttribute(2, "Size", "Medium"),
WooPosVariationApiResponse.VariationAttribute(3, "Material", "Cotton")
)
attributes = JsonParser.parseString("""[{"id":1,"name":"Color","option":"Red"},{"id":2,"name":"Size","option":"Medium"},{"id":3,"name":"Material","option":"Cotton"}]""")
)

// When
Expand Down
Loading