@@ -218,6 +218,49 @@ final class OrderStatsV4MapperTests: XCTestCase {
218218 XCTAssertNil ( nonZeroYearTotals. totalProducts)
219219 XCTAssertEqual ( nonZeroYearTotals. averageOrderValue, 266 )
220220 }
221+
222+ /// Verifies that all of the yearly unit OrderStatsV4 fields are parsed correctly
223+ /// if the response contains no data envelope.
224+ ///
225+ func test_yearly_unit_stat_fields_are_properly_parsed_without_data_envelope( ) {
226+ guard let yearlyStats = mapOrderStatsWithYearlyUnitResponseWithoutDataEnvelope ( ) else {
227+ XCTFail ( )
228+ return
229+ }
230+
231+ XCTAssertEqual ( yearlyStats. siteID, Constants . siteID)
232+ XCTAssertEqual ( yearlyStats. granularity, . yearly)
233+
234+ XCTAssertEqual ( yearlyStats. totals. totalOrders, 3 )
235+ XCTAssertEqual ( yearlyStats. totals. totalItemsSold, 5 )
236+ XCTAssertEqual ( yearlyStats. totals. grossRevenue, 800 )
237+ XCTAssertEqual ( yearlyStats. totals. totalCoupons, 0 )
238+ XCTAssertEqual ( yearlyStats. totals. couponDiscount, 0 )
239+ XCTAssertEqual ( yearlyStats. totals. refunds, 0 )
240+ XCTAssertEqual ( yearlyStats. totals. taxes, 0 )
241+ XCTAssertEqual ( yearlyStats. totals. shipping, 0 )
242+ XCTAssertEqual ( yearlyStats. totals. netRevenue, 800 )
243+ XCTAssertEqual ( yearlyStats. totals. totalProducts, 2 )
244+ XCTAssertEqual ( yearlyStats. totals. averageOrderValue, 266 )
245+
246+ XCTAssertEqual ( yearlyStats. intervals. count, 1 )
247+
248+ let nonZeroYear = yearlyStats. intervals [ 0 ]
249+ let nonZeroYearTotals = nonZeroYear. subtotals
250+
251+ XCTAssertEqual ( nonZeroYear. interval, " 2019 " )
252+
253+ XCTAssertEqual ( nonZeroYearTotals. totalOrders, 3 )
254+ XCTAssertEqual ( nonZeroYearTotals. grossRevenue, 800 )
255+ XCTAssertEqual ( nonZeroYearTotals. totalCoupons, 0 )
256+ XCTAssertEqual ( nonZeroYearTotals. couponDiscount, 0 )
257+ XCTAssertEqual ( nonZeroYearTotals. refunds, 0 )
258+ XCTAssertEqual ( nonZeroYearTotals. taxes, 0 )
259+ XCTAssertEqual ( nonZeroYearTotals. shipping, 0 )
260+ XCTAssertEqual ( nonZeroYearTotals. netRevenue, 800 )
261+ XCTAssertNil ( nonZeroYearTotals. totalProducts)
262+ XCTAssertEqual ( nonZeroYearTotals. averageOrderValue, 266 )
263+ }
221264}
222265
223266private extension OrderStatsV4MapperTests {
@@ -251,6 +294,12 @@ private extension OrderStatsV4MapperTests {
251294 return mapStatItems ( from: " order-stats-v4-year " , granularity: . yearly)
252295 }
253296
297+ /// Returns the OrderStatsV4Mapper output upon receiving `order-stats-v4-year-without-data`
298+ ///
299+ func mapOrderStatsWithYearlyUnitResponseWithoutDataEnvelope( ) -> OrderStatsV4 ? {
300+ return mapStatItems ( from: " order-stats-v4-year-without-data " , granularity: . yearly)
301+ }
302+
254303 /// Returns the OrderStatsV4Mapper output upon receiving `filename` (Data Encoded)
255304 ///
256305 func mapStatItems( from filename: String , granularity: StatsGranularityV4 ) -> OrderStatsV4 ? {
0 commit comments