Skip to content

Commit 0d908b9

Browse files
committed
Add description fields to POS entities
1 parent 2ad06b2 commit 0d908b9

File tree

10 files changed

+59
-1
lines changed

10 files changed

+59
-1
lines changed

Modules/Sources/Fakes/Networking.generated.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ extension Networking.POSProduct {
753753
productID: .fake(),
754754
name: .fake(),
755755
productTypeKey: .fake(),
756+
fullDescription: .fake(),
757+
shortDescription: .fake(),
756758
sku: .fake(),
757759
globalUniqueID: .fake(),
758760
price: .fake(),
@@ -776,6 +778,7 @@ extension Networking.POSProductVariation {
776778
productVariationID: .fake(),
777779
attributes: .fake(),
778780
image: .fake(),
781+
fullDescription: .fake(),
779782
sku: .fake(),
780783
globalUniqueID: .fake(),
781784
price: .fake(),

Modules/Sources/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,8 @@ extension Networking.POSProduct {
12461246
productID: CopiableProp<Int64> = .copy,
12471247
name: CopiableProp<String> = .copy,
12481248
productTypeKey: CopiableProp<String> = .copy,
1249+
fullDescription: NullableCopiableProp<String> = .copy,
1250+
shortDescription: NullableCopiableProp<String> = .copy,
12491251
sku: NullableCopiableProp<String> = .copy,
12501252
globalUniqueID: NullableCopiableProp<String> = .copy,
12511253
price: CopiableProp<String> = .copy,
@@ -1261,6 +1263,8 @@ extension Networking.POSProduct {
12611263
let productID = productID ?? self.productID
12621264
let name = name ?? self.name
12631265
let productTypeKey = productTypeKey ?? self.productTypeKey
1266+
let fullDescription = fullDescription ?? self.fullDescription
1267+
let shortDescription = shortDescription ?? self.shortDescription
12641268
let sku = sku ?? self.sku
12651269
let globalUniqueID = globalUniqueID ?? self.globalUniqueID
12661270
let price = price ?? self.price
@@ -1277,6 +1281,8 @@ extension Networking.POSProduct {
12771281
productID: productID,
12781282
name: name,
12791283
productTypeKey: productTypeKey,
1284+
fullDescription: fullDescription,
1285+
shortDescription: shortDescription,
12801286
sku: sku,
12811287
globalUniqueID: globalUniqueID,
12821288
price: price,
@@ -1298,6 +1304,7 @@ extension Networking.POSProductVariation {
12981304
productVariationID: CopiableProp<Int64> = .copy,
12991305
attributes: CopiableProp<[ProductVariationAttribute]> = .copy,
13001306
image: NullableCopiableProp<ProductImage> = .copy,
1307+
fullDescription: NullableCopiableProp<String> = .copy,
13011308
sku: NullableCopiableProp<String> = .copy,
13021309
globalUniqueID: NullableCopiableProp<String> = .copy,
13031310
price: CopiableProp<String> = .copy,
@@ -1311,6 +1318,7 @@ extension Networking.POSProductVariation {
13111318
let productVariationID = productVariationID ?? self.productVariationID
13121319
let attributes = attributes ?? self.attributes
13131320
let image = image ?? self.image
1321+
let fullDescription = fullDescription ?? self.fullDescription
13141322
let sku = sku ?? self.sku
13151323
let globalUniqueID = globalUniqueID ?? self.globalUniqueID
13161324
let price = price ?? self.price
@@ -1325,6 +1333,7 @@ extension Networking.POSProductVariation {
13251333
productVariationID: productVariationID,
13261334
attributes: attributes,
13271335
image: image,
1336+
fullDescription: fullDescription,
13281337
sku: sku,
13291338
globalUniqueID: globalUniqueID,
13301339
price: price,

Modules/Sources/Networking/Model/POSProduct.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
1212
public let productID: Int64
1313
public let name: String
1414
public let productTypeKey: String
15+
public let fullDescription: String?
16+
public let shortDescription: String?
1517
public let sku: String?
1618
public let globalUniqueID: String?
1719

@@ -44,6 +46,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
4446
productID: Int64,
4547
name: String,
4648
productTypeKey: String,
49+
fullDescription: String?,
50+
shortDescription: String?,
4751
sku: String?,
4852
globalUniqueID: String?,
4953
price: String,
@@ -58,6 +62,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
5862
self.productID = productID
5963
self.name = name
6064
self.productTypeKey = productTypeKey
65+
self.fullDescription = fullDescription
66+
self.shortDescription = shortDescription
6167
self.sku = sku
6268
self.globalUniqueID = globalUniqueID
6369

@@ -92,6 +98,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
9298
let productID = try container.decode(Int64.self, forKey: .productID)
9399
let name = try container.decode(String.self, forKey: .name)
94100
let productTypeKey = try container.decode(String.self, forKey: .productTypeKey)
101+
let fullDescription = try container.decodeIfPresent(String.self, forKey: .fullDescription)
102+
let shortDescription = try container.decodeIfPresent(String.self, forKey: .shortDescription)
95103
let sku = container.failsafeDecodeIfPresent(
96104
targetType: String.self,
97105
forKey: .sku,
@@ -119,6 +127,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
119127
productID: productID,
120128
name: name,
121129
productTypeKey: productTypeKey,
130+
fullDescription: fullDescription,
131+
shortDescription: shortDescription,
122132
sku: sku,
123133
globalUniqueID: globalUniqueID,
124134
price: price,
@@ -149,6 +159,8 @@ private extension POSProduct {
149159
case productID = "id"
150160
case name
151161
case productTypeKey = "type"
162+
case fullDescription = "description"
163+
case shortDescription = "short_description"
152164
case sku
153165
case globalUniqueID = "global_unique_id"
154166
case price

Modules/Sources/Networking/Model/POSProductVariation.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
1717
public let attributes: [ProductVariationAttribute]
1818
public let image: ProductImage?
1919

20+
public let fullDescription: String?
2021
public let sku: String?
2122
public let globalUniqueID: String?
2223

@@ -36,6 +37,7 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
3637
productVariationID: Int64,
3738
attributes: [ProductVariationAttribute],
3839
image: ProductImage?,
40+
fullDescription: String?,
3941
sku: String?,
4042
globalUniqueID: String?,
4143
price: String,
@@ -48,6 +50,7 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
4850
self.productVariationID = productVariationID
4951
self.attributes = attributes
5052
self.image = image
53+
self.fullDescription = fullDescription
5154
self.sku = sku
5255
self.globalUniqueID = globalUniqueID
5356
self.price = price
@@ -71,6 +74,7 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
7174
let productID = try container.decode(Int64.self, forKey: .productID)
7275
let attributes = try container.decode([ProductVariationAttribute].self, forKey: .attributes)
7376
let image = try container.decodeIfPresent(ProductImage.self, forKey: .image)
77+
let fullDescription = try container.decodeIfPresent(String.self, forKey: .fullDescription)
7478
let sku = container.failsafeDecodeIfPresent(
7579
targetType: String.self,
7680
forKey: .sku,
@@ -103,6 +107,7 @@ public struct POSProductVariation: Codable, Equatable, GeneratedCopiable, Genera
103107
productVariationID: productVariationID,
104108
attributes: attributes,
105109
image: image,
110+
fullDescription: fullDescription,
106111
sku: sku,
107112
globalUniqueID: globalUniqueID,
108113
price: price,
@@ -133,6 +138,7 @@ private extension POSProductVariation {
133138
case attributes
134139
case image
135140
case price
141+
case fullDescription = "description"
136142
case sku
137143
case globalUniqueID = "global_unique_id"
138144
case downloadable

Modules/Sources/Networking/Remote/POSCatalogSyncRemote.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private extension POSProduct {
189189
productVariationID: productID,
190190
attributes: variationAttributes,
191191
image: firstImage,
192+
fullDescription: fullDescription,
192193
sku: sku,
193194
globalUniqueID: globalUniqueID,
194195
price: price,

Modules/Sources/Yosemite/PointOfSale/Items/POSProductOrVariationResolver.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ private extension POSProduct {
8383
productVariationID: productID,
8484
attributes: try attributes.compactMap { try $0.toProductVariationAttribute() },
8585
image: images.first,
86+
fullDescription: fullDescription,
8687
sku: sku,
8788
globalUniqueID: globalUniqueID,
8889
price: price,

Modules/Tests/NetworkingTests/Remote/POSCatalogSyncRemoteTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct POSCatalogSyncRemoteTests {
4444
#expect(firstProduct.siteID == sampleSiteID)
4545
#expect(firstProduct.productID == 168)
4646
#expect(firstProduct.name == "Beanie")
47+
#expect(firstProduct.fullDescription != nil)
48+
#expect(firstProduct.shortDescription != nil)
4749
}
4850

4951
@Test func loadProducts_relays_networking_error() async throws {
@@ -427,6 +429,7 @@ struct POSCatalogSyncRemoteTests {
427429
#expect(variation.sku == "")
428430
#expect(variation.globalUniqueID == "")
429431
#expect(variation.price == "330.34")
432+
#expect(variation.fullDescription != nil)
430433
#expect(variation.attributes.count == 3)
431434
#expect(variation.image?.src == "https://example.com/wp-content/uploads/2025/08/img-quae.png")
432435
#expect(variation.attributes == [
@@ -471,4 +474,20 @@ struct POSCatalogSyncRemoteTests {
471474
try await remote.downloadCatalog(for: sampleSiteID, downloadURL: downloadURL)
472475
}
473476
}
477+
478+
@Test func posProductVariation_provides_field_names_for_request() {
479+
let fieldNames = POSProductVariation.requestFields
480+
#expect(fieldNames.contains("id"))
481+
#expect(fieldNames.contains("parent_id"))
482+
#expect(fieldNames.contains("attributes"))
483+
#expect(fieldNames.contains("image"))
484+
#expect(fieldNames.contains("price"))
485+
#expect(fieldNames.contains("sku"))
486+
#expect(fieldNames.contains("global_unique_id"))
487+
#expect(fieldNames.contains("downloadable"))
488+
#expect(fieldNames.contains("description"))
489+
#expect(fieldNames.contains("manage_stock"))
490+
#expect(fieldNames.contains("stock_quantity"))
491+
#expect(fieldNames.contains("stock_status"))
492+
}
474493
}

Modules/Tests/NetworkingTests/Remote/POSProductsNetworkingTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ struct POSProductsNetworkingTests {
183183
#expect(fieldNames.contains("id"))
184184
#expect(fieldNames.contains("name"))
185185
#expect(fieldNames.contains("type"))
186+
#expect(fieldNames.contains("description"))
187+
#expect(fieldNames.contains("short_description"))
186188
#expect(fieldNames.contains("sku"))
187189
#expect(fieldNames.contains("global_unique_id"))
188190
#expect(fieldNames.contains("price"))
@@ -269,7 +271,7 @@ struct POSProductsNetworkingTests {
269271

270272
// When
271273
network.simulateResponse(requestUrlSuffix: "products", filename: "pos-products")
272-
let product = try await remote.loadPOSProductByGlobalUniqueIdentifier(for: sampleSiteID, globalUniqueID: globalUniqueID)
274+
_ = try await remote.loadPOSProductByGlobalUniqueIdentifier(for: sampleSiteID, globalUniqueID: globalUniqueID)
273275

274276
// Then
275277
let request = try #require(network.requestsForResponseData.first as? JetpackRequest)

Modules/Tests/NetworkingTests/Remote/ProductVariationsRemoteTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ final class ProductVariationsRemoteTests: XCTestCase {
172172
}
173173
XCTAssertEqual(firstVariation.productVariationID, 1275)
174174
XCTAssertEqual(firstVariation.productID, 10275)
175+
XCTAssertEqual(firstVariation.fullDescription, "<p>Nutty chocolate marble, 99% and organic.</p>\n")
175176
XCTAssertEqual(firstVariation.sku, "99%-nuts-marble")
176177
XCTAssertEqual(firstVariation.globalUniqueID, "12345")
177178

Modules/Tests/NetworkingTests/Responses/products-load-pos.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"name": "Beanie",
66
"type": "simple",
77
"sku": "Woo-beanie",
8+
"description": "",
9+
"short_description": "",
810
"price": "18",
911
"regular_price": "20",
1012
"sale_price": "18",
@@ -48,6 +50,8 @@
4850
"name": "Latte",
4951
"type": "variable",
5052
"sku": "200815216",
53+
"description": "",
54+
"short_description": "",
5155
"price": "7",
5256
"regular_price": "",
5357
"sale_price": "",

0 commit comments

Comments
 (0)