Skip to content

Commit 0065cd7

Browse files
Merge pull request #227 from woocommerce/issue/221-orders-list-empty
Fix: Empty Order List
2 parents 6eecb62 + bea9d5b commit 0065cd7

File tree

7 files changed

+745
-5
lines changed

7 files changed

+745
-5
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
B505F6D720BEE58800BB1B69 /* AccountRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6D620BEE58800BB1B69 /* AccountRemoteTests.swift */; };
5252
B505F6EA20BEFC3700BB1B69 /* MockupNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = B518662620A09BCC00037A38 /* MockupNetwork.swift */; };
5353
B505F6EC20BEFDC200BB1B69 /* Loader.swift in Sources */ = {isa = PBXBuildFile; fileRef = B518663420A0A2E800037A38 /* Loader.swift */; };
54+
B5147876211B9227007562E5 /* broken-orders-mark-2.json in Resources */ = {isa = PBXBuildFile; fileRef = B5147875211B9227007562E5 /* broken-orders-mark-2.json */; };
5455
B518662220A097C200037A38 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = B518662120A097C200037A38 /* Network.swift */; };
5556
B518662420A099BF00037A38 /* AlamofireNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = B518662320A099BF00037A38 /* AlamofireNetwork.swift */; };
5657
B518662A20A09C6F00037A38 /* OrdersRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B518662920A09C6F00037A38 /* OrdersRemoteTests.swift */; };
@@ -146,6 +147,7 @@
146147
B505F6D220BEE3A500BB1B69 /* AccountMapperTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountMapperTests.swift; sourceTree = "<group>"; };
147148
B505F6D420BEE4E600BB1B69 /* me.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = me.json; sourceTree = "<group>"; };
148149
B505F6D620BEE58800BB1B69 /* AccountRemoteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountRemoteTests.swift; sourceTree = "<group>"; };
150+
B5147875211B9227007562E5 /* broken-orders-mark-2.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "broken-orders-mark-2.json"; sourceTree = "<group>"; };
149151
B518662120A097C200037A38 /* Network.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = "<group>"; };
150152
B518662320A099BF00037A38 /* AlamofireNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlamofireNetwork.swift; sourceTree = "<group>"; };
151153
B518662620A09BCC00037A38 /* MockupNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockupNetwork.swift; sourceTree = "<group>"; };
@@ -398,6 +400,7 @@
398400
74C8F06F20EEC3A800B6EDC9 /* broken-notes.json */,
399401
74C8F06B20EEBD5D00B6EDC9 /* broken-order.json */,
400402
CE20179220E3EFA7005B4C18 /* broken-orders.json */,
403+
B5147875211B9227007562E5 /* broken-orders-mark-2.json */,
401404
B58D10C72114D21C00107ED4 /* generic_error.json */,
402405
B505F6D420BEE4E600BB1B69 /* me.json */,
403406
B58D10C92114D22E00107ED4 /* new-order-note.json */,
@@ -582,6 +585,7 @@
582585
B58D10CA2114D22E00107ED4 /* new-order-note.json in Resources */,
583586
74C8F06C20EEBD5D00B6EDC9 /* broken-order.json in Resources */,
584587
B58D10C82114D21D00107ED4 /* generic_error.json in Resources */,
588+
B5147876211B9227007562E5 /* broken-orders-mark-2.json in Resources */,
585589
743BF8BE21191B63008A9D87 /* site-visits.json in Resources */,
586590
B505F6D520BEE4E700BB1B69 /* me.json in Resources */,
587591
B5C6FCD620A3768900A4F8E4 /* order.json in Resources */,

Networking/Networking/Model/OrderItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public struct OrderItem: Decodable {
88
public let name: String
99
public let productID: Int
1010
public let quantity: Int
11-
public let sku: String
11+
public let sku: String?
1212
public let subtotal: String
1313
public let subtotalTax: String
1414
public let taxClass: String

Networking/NetworkingTests/Mapper/OrderListMapperTests.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ class OrderListMapperTests: XCTestCase {
107107
let orderModifiedString = format.string(from: brokenOrder.dateModified)
108108
XCTAssertEqual(orderModifiedString, todayCreatedString)
109109
}
110+
111+
/// Verifies that `broken-orders-mark-2` gets properly parsed: 6 Orders with 2 items each, and the SKU property should
112+
/// always be set to null.
113+
///
114+
/// Ref. Issue: https://github.com/woocommerce/woocommerce-ios/issues/221
115+
///
116+
func testOrderListWithBreakingFormatIsProperlyParsed() {
117+
let orders = mapLoadBrokenOrdersResponseMarkII()
118+
XCTAssertEqual(orders.count, 6)
119+
120+
for order in orders {
121+
XCTAssertEqual(order.items.count, 2)
122+
123+
for item in order.items {
124+
XCTAssertNil(item.sku)
125+
}
126+
}
127+
}
110128
}
111129

112130

@@ -130,9 +148,15 @@ private extension OrderListMapperTests {
130148
return mapOrders(from: "orders-load-all")
131149
}
132150

133-
/// Returns the OrderlistMapper output upon receiving `broken-order`
151+
/// Returns the OrderListMapper output upon receiving `broken-order`
134152
///
135153
func mapLoadBrokenOrderResponse() -> [Order] {
136154
return mapOrders(from: "broken-orders")
137155
}
156+
157+
/// Returns the OrderListMapper output upon receiving `broken-orders-mark-2`
158+
///
159+
func mapLoadBrokenOrdersResponseMarkII() -> [Order] {
160+
return mapOrders(from: "broken-orders-mark-2")
161+
}
138162
}

0 commit comments

Comments
 (0)