@@ -39,9 +39,14 @@ final class AggregateDataHelperTests: XCTestCase {
3939 /// Verifies refunded products are combined and sorted correctly.
4040 ///
4141 func testRefundedProductsSortedSuccessfully( ) {
42+ let productID : Int64 = 1
43+ // The itemID (63 in this case) is relevant to retrieve the attributes. A refund order item has in its properties the refunded item id, to be used
44+ // to query the attibutes from the order items.
45+ let orderItems = [ MockOrderItem . sampleItem ( itemID: 63 , productID: productID, quantity: 3 , attributes: testOrderItemAttributes) ]
4246 let refunds = mapLoadAllRefundsResponse ( )
4347 let expectedProducts = expectedRefundedProducts ( )
44- guard let actualProducts = AggregateDataHelper . combineRefundedProducts ( from: refunds, orderItems: [ ] ) else {
48+
49+ guard let actualProducts = AggregateDataHelper . combineRefundedProducts ( from: refunds, orderItems: orderItems) else {
4550 XCTFail ( " Error: failed to combine products. " )
4651 return
4752 }
@@ -56,6 +61,7 @@ final class AggregateDataHelperTests: XCTestCase {
5661 XCTAssertEqual ( expected. quantity, actual. quantity)
5762 XCTAssertEqual ( expected. total, actual. total)
5863 XCTAssertEqual ( expected. sku, actual. sku)
64+ XCTAssertEqual ( expected. attributes, actual. attributes)
5965 }
6066 }
6167
@@ -79,8 +85,7 @@ final class AggregateDataHelperTests: XCTestCase {
7985 func test_AggregateOrderItem_has_attributes_from_OrderItem( ) {
8086 // Given
8187 let productID : Int64 = 1
82- let orderItemAttributes = [ OrderItemAttribute ( metaID: 170 , name: " Packaging " , value: " Yes " ) ]
83- let orderItems = [ MockOrderItem . sampleItem ( itemID: 62 , productID: productID, quantity: 3 , attributes: orderItemAttributes) ]
88+ let orderItems = [ MockOrderItem . sampleItem ( itemID: 62 , productID: productID, quantity: 3 , attributes: testOrderItemAttributes) ]
8489 let order = MockOrders ( ) . empty ( ) . copy ( items: orderItems)
8590 let refundItems = [ MockRefunds . sampleRefundItem ( productID: productID) ]
8691 let refunds = [ MockRefunds . sampleRefund ( items: refundItems) ]
@@ -90,12 +95,17 @@ final class AggregateDataHelperTests: XCTestCase {
9095
9196 // Then
9297 XCTAssertEqual ( aggregatedOrderItems. count, 1 )
93- XCTAssertEqual ( aggregatedOrderItems [ 0 ] . attributes, orderItemAttributes )
98+ XCTAssertEqual ( aggregatedOrderItems [ 0 ] . attributes, testOrderItemAttributes )
9499 }
95100}
96101
97102
98103private extension AggregateDataHelperTests {
104+ /// Used when testing that the item attributes are properly retrieved, for order items and refunds
105+ var testOrderItemAttributes : [ OrderItemAttribute ] {
106+ [ OrderItemAttribute ( metaID: 170 , name: " Packaging " , value: " Yes " ) ]
107+ }
108+
99109 /// Returns the OrderListMapper output upon receiving `filename` (Data Encoded)
100110 ///
101111 func mapOrders( from filename: String ) -> [ Order ] {
@@ -154,6 +164,8 @@ private extension AggregateDataHelperTests {
154164 )
155165 expectedArray. append ( item1)
156166
167+ /// We expect this item to have these attributes by passing an order item
168+ /// with the same refunded item id to the combineRefundedProducts function
157169 let item2 = AggregateOrderItem (
158170 productID: 21 ,
159171 variationID: 71 ,
@@ -162,7 +174,7 @@ private extension AggregateDataHelperTests {
162174 quantity: - 1 ,
163175 sku: " HOODIE-SHIP-YOUR-IDEA-BLACK-L " ,
164176 total: currencyFormatter. convertToDecimal ( " -31.50 " ) ?? NSDecimalNumber . zero,
165- attributes: [ ]
177+ attributes: testOrderItemAttributes
166178 )
167179 expectedArray. append ( item2)
168180
0 commit comments