Skip to content

Commit 363c096

Browse files
authored
Add back attributes encoding to Product entity (#14046)
2 parents 2ad7a87 + 9c33873 commit 363c096

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

Networking/Networking/Model/Product/Product.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,9 @@ public struct Product: Codable, GeneratedCopiable, Equatable, GeneratedFakeable
746746
try container.encode(minAllowedQuantity, forKey: .minAllowedQuantity)
747747
try container.encode(groupOfQuantity, forKey: .groupOfQuantity)
748748

749+
// Attributes
750+
try container.encode(attributes, forKey: .attributes)
751+
749752
// Password
750753
try container.encode(password, forKey: .password)
751754

Networking/NetworkingTests/Mapper/ProductMapperTests.swift

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ final class ProductMapperTests: XCTestCase {
515515

516516
// Given
517517
let product = try XCTUnwrap(mapLoadSubscriptionProductResponse())
518-
let subscriptionSettings = try XCTUnwrap(product.subscription)
518+
_ = try XCTUnwrap(product.subscription)
519519

520520
// When
521521
let encoder = JSONEncoder()
@@ -549,6 +549,51 @@ final class ProductMapperTests: XCTestCase {
549549
XCTAssertEqual(encodedMetadata?[9]["key"] as? String, customFields[1].key)
550550
XCTAssertEqual(encodedMetadata?[9]["value"] as? String, customFields[1].value)
551551
}
552+
553+
/// Test that attributes are properly encoded.
554+
///
555+
func test_attributes_are_properly_encoded() throws {
556+
// Given
557+
let product = try XCTUnwrap(mapLoadProductResponse().first)
558+
559+
560+
// When
561+
let encoder = JSONEncoder()
562+
let encodedData = try encoder.encode(product)
563+
let encodedJSON = try JSONSerialization.jsonObject(with: encodedData, options: []) as? [String: Any]
564+
565+
// Then
566+
567+
let attribute1 = ProductAttribute(siteID: dummySiteID,
568+
attributeID: 0,
569+
name: "Color",
570+
position: 1,
571+
visible: true,
572+
variation: true,
573+
options: ["Purple", "Yellow", "Hot Pink", "Lime Green", "Teal"])
574+
575+
let attribute2 = ProductAttribute(siteID: dummySiteID,
576+
attributeID: 0,
577+
name: "Size",
578+
position: 0,
579+
visible: true,
580+
variation: true,
581+
options: ["Small", "Medium", "Large"])
582+
let attributes = [attribute1, attribute2]
583+
584+
XCTAssertNotNil(encodedJSON)
585+
let encodedAttributes = encodedJSON?["attributes"] as? [[String: Any]]
586+
XCTAssertEqual(encodedAttributes?.count, attributes.count)
587+
588+
// Verify all attributes are properly encoded
589+
for (index, attribute) in attributes.enumerated() {
590+
XCTAssertEqual(encodedAttributes?[index]["name"] as? String, attribute.name)
591+
XCTAssertEqual(encodedAttributes?[index]["position"] as? Int, attribute.position)
592+
XCTAssertEqual(encodedAttributes?[index]["visible"] as? Bool, attribute.visible)
593+
XCTAssertEqual(encodedAttributes?[index]["variation"] as? Bool, attribute.variation)
594+
XCTAssertEqual(encodedAttributes?[index]["options"] as? [String], attribute.options)
595+
}
596+
}
552597
}
553598

554599

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [*] Blaze: Schedule a reminder local notification asking to continue abandoned campaign creation flow. [https://github.com/woocommerce/woocommerce-ios/pull/13950]
1111
- [**] Fixed formatting issues for discount and cash payment input values when the device and store currency settings are different. [https://github.com/woocommerce/woocommerce-ios/pull/13979]
1212
- [*] Blaze: Handle tap on local notifications to open campaign creation. [https://github.com/woocommerce/woocommerce-ios/pull/13968]
13+
- [**] Fixed an issue that prevented users from adding prices to product variations. [https://github.com/woocommerce/woocommerce-ios/pull/14046]
1314
- [internal] Mobile Payments: Log errors from Stripe Terminal [https://github.com/woocommerce/woocommerce-ios/pull/13976]
1415

1516

0 commit comments

Comments
 (0)