@@ -13,10 +13,17 @@ final class AnalyticsHubViewModelTests: XCTestCase {
1313 func test_cards_viewmodels_show_correct_data_after_updating_from_network( ) async {
1414 // Given
1515 let vm = AnalyticsHubViewModel ( siteID: 123 , statsTimeRange: . thisMonth, stores: stores)
16- let stats = OrderStatsV4 . fake ( ) . copy ( totals : . fake ( ) . copy ( totalOrders : 15 , totalItemsSold : 5 , grossRevenue : 62 ) )
16+
1717 stores. whenReceivingAction ( ofType: StatsActionV4 . self) { action in
18- if case let . retrieveCustomStats( _, _, _, _, _, _, completion) = action {
18+ switch action {
19+ case let . retrieveCustomStats( _, _, _, _, _, _, completion) :
20+ let stats = OrderStatsV4 . fake ( ) . copy ( totals: . fake( ) . copy ( totalOrders: 15 , totalItemsSold: 5 , grossRevenue: 62 ) )
1921 completion ( . success( stats) )
22+ case let . retrieveTopEarnerStats( _, _, _, _, _, _, _, completion) :
23+ let topEarners = TopEarnerStats . fake ( ) . copy ( items: [ . fake( ) ] )
24+ completion ( . success( topEarners) )
25+ default :
26+ break
2027 }
2128 }
2229
@@ -31,14 +38,20 @@ final class AnalyticsHubViewModelTests: XCTestCase {
3138 XCTAssertEqual ( vm. revenueCard. leadingValue, " $62 " )
3239 XCTAssertEqual ( vm. ordersCard. leadingValue, " 15 " )
3340 XCTAssertEqual ( vm. productCard. itemsSold, " 5 " )
41+ XCTAssertEqual ( vm. productCard. itemsSoldData. count, 1 )
3442 }
3543
3644 func test_cards_viewmodels_show_sync_error_after_getting_error_from_network( ) async {
3745 // Given
3846 let vm = AnalyticsHubViewModel ( siteID: 123 , statsTimeRange: . thisMonth, stores: stores)
3947 stores. whenReceivingAction ( ofType: StatsActionV4 . self) { action in
40- if case let . retrieveCustomStats( _, _, _, _, _, _, completion) = action {
48+ switch action {
49+ case let . retrieveCustomStats( _, _, _, _, _, _, completion) :
50+ completion ( . failure( NSError ( domain: " Test " , code: 1 ) ) )
51+ case let . retrieveTopEarnerStats( _, _, _, _, _, _, _, completion) :
4152 completion ( . failure( NSError ( domain: " Test " , code: 1 ) ) )
53+ default :
54+ break
4255 }
4356 }
4457
@@ -54,16 +67,22 @@ final class AnalyticsHubViewModelTests: XCTestCase {
5467 func test_cards_viewmodels_redacted_while_updating_from_network( ) async {
5568 // Given
5669 let vm = AnalyticsHubViewModel ( siteID: 123 , statsTimeRange: . thisMonth, stores: stores)
57- let stats = OrderStatsV4 . fake ( ) . copy ( totals: . fake( ) . copy ( totalOrders: 15 , totalItemsSold: 5 , grossRevenue: 62 ) )
5870 var loadingRevenueCard : AnalyticsReportCardViewModel ?
5971 var loadingOrdersCard : AnalyticsReportCardViewModel ?
6072 var loadingProductsCard : AnalyticsProductCardViewModel ?
6173 stores. whenReceivingAction ( ofType: StatsActionV4 . self) { action in
62- if case let . retrieveCustomStats( _, _, _, _, _, _, completion) = action {
74+ switch action {
75+ case let . retrieveCustomStats( _, _, _, _, _, _, completion) :
76+ let stats = OrderStatsV4 . fake ( ) . copy ( totals: . fake( ) . copy ( totalOrders: 15 , totalItemsSold: 5 , grossRevenue: 62 ) )
6377 loadingRevenueCard = vm. revenueCard
6478 loadingOrdersCard = vm. ordersCard
6579 loadingProductsCard = vm. productCard
6680 completion ( . success( stats) )
81+ case let . retrieveTopEarnerStats( _, _, _, _, _, _, _, completion) :
82+ let topEarners = TopEarnerStats . fake ( ) . copy ( items: [ . fake( ) ] )
83+ completion ( . success( topEarners) )
84+ default :
85+ break
6786 }
6887 }
6988
0 commit comments