Skip to content

Commit 720218a

Browse files
rachelmcrEcarrion
authored andcommitted
Add unit test for order sync failure tracking
1 parent aaed835 commit 720218a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Creation/NewOrderViewModelTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,32 @@ final class NewOrderViewModelTests: XCTestCase {
889889
XCTAssertTrue(analytics.receivedEvents.isEmpty)
890890
}
891891

892+
func test_sync_failure_tracked_when_sync_fails() {
893+
// Given
894+
let analytics = MockAnalyticsProvider()
895+
let stores = MockStoresManager(sessionManager: .testingInstance)
896+
let viewModel = NewOrderViewModel(siteID: sampleSiteID, stores: stores, analytics: WooAnalytics(analyticsProvider: analytics))
897+
898+
// When
899+
waitForExpectation { expectation in
900+
stores.whenReceivingAction(ofType: OrderAction.self) { action in
901+
switch action {
902+
case let .createOrder(_, _, onCompletion):
903+
onCompletion(.failure(NSError(domain: "Error", code: 0)))
904+
expectation.fulfill()
905+
default:
906+
XCTFail("Received unsupported action: \(action)")
907+
}
908+
}
909+
910+
// When remote sync is triggered
911+
viewModel.saveShippingLine(ShippingLine.fake())
912+
}
913+
914+
// Then
915+
XCTAssertTrue(analytics.receivedEvents.contains(WooAnalyticsStat.orderSyncFailed.rawValue))
916+
}
917+
892918
// MARK: -
893919

894920
func test_customer_note_section_is_updated_when_note_is_added_to_order() {

0 commit comments

Comments
 (0)