@@ -318,7 +318,25 @@ final class AppCoordinatorTests: XCTestCase {
318318 appCoordinator. start ( )
319319
320320 // Then
321- XCTAssertEqual ( analytics. receivedEvents, [ WooAnalyticsStat . loginOnboardingShown. rawValue] )
321+ _ = try XCTUnwrap ( analytics. receivedEvents. firstIndex ( where: { $0 == WooAnalyticsStat . loginOnboardingShown. rawValue} ) )
322+ }
323+
324+ func test_trackRestAPILoginExperimentVariation_is_tracked_after_presenting_onboarding( ) throws {
325+ // Given
326+ stores. deauthenticate ( )
327+ let analytics = MockAnalyticsProvider ( )
328+ let appCoordinator = makeCoordinator ( window: window,
329+ stores: stores,
330+ authenticationManager: authenticationManager,
331+ analytics: WooAnalytics ( analyticsProvider: analytics) )
332+
333+ // When
334+ appCoordinator. start ( )
335+
336+ // Then
337+ let indexOfEvent = try XCTUnwrap ( analytics. receivedEvents. firstIndex ( where: { $0 == " rest_api_login_experiment " } ) )
338+ let eventProperties = try XCTUnwrap ( analytics. receivedProperties [ indexOfEvent] )
339+ XCTAssertNotNil ( eventProperties [ " experiment_variant " ] as? String )
322340 }
323341
324342 // MARK: - Login reminder analytics
@@ -340,10 +358,12 @@ final class AppCoordinatorTests: XCTestCase {
340358 pushNotesManager. sendLocalNotificationResponse ( response)
341359
342360 // Then
343- XCTAssertEqual ( analytics. receivedEvents, [ WooAnalyticsStat . loginLocalNotificationTapped. rawValue] )
344- let actionPropertyValue = try XCTUnwrap ( analytics. receivedProperties. first ? [ " action " ] as? String )
361+ let indexOfEvent = try XCTUnwrap ( analytics. receivedEvents. firstIndex ( where: { $0 == WooAnalyticsStat . loginLocalNotificationTapped. rawValue} ) )
362+ let eventProperties = try XCTUnwrap ( analytics. receivedProperties [ indexOfEvent] )
363+
364+ let actionPropertyValue = try XCTUnwrap ( eventProperties [ " action " ] as? String )
345365 XCTAssertEqual ( actionPropertyValue, " contact_support " )
346- let typePropertyValue = try XCTUnwrap ( analytics . receivedProperties . first ? [ " type " ] as? String )
366+ let typePropertyValue = try XCTUnwrap ( eventProperties [ " type " ] as? String )
347367 XCTAssertEqual ( typePropertyValue, " site_address_error " )
348368 }
349369
@@ -364,10 +384,12 @@ final class AppCoordinatorTests: XCTestCase {
364384 pushNotesManager. sendLocalNotificationResponse ( response)
365385
366386 // Then
367- XCTAssertEqual ( analytics. receivedEvents, [ WooAnalyticsStat . loginLocalNotificationTapped. rawValue] )
368- let actionPropertyValue = try XCTUnwrap ( analytics. receivedProperties. first ? [ " action " ] as? String )
387+ let indexOfEvent = try XCTUnwrap ( analytics. receivedEvents. firstIndex ( where: { $0 == WooAnalyticsStat . loginLocalNotificationTapped. rawValue} ) )
388+ let eventProperties = try XCTUnwrap ( analytics. receivedProperties [ indexOfEvent] )
389+
390+ let actionPropertyValue = try XCTUnwrap ( eventProperties [ " action " ] as? String )
369391 XCTAssertEqual ( actionPropertyValue, " login_with_wpcom " )
370- let typePropertyValue = try XCTUnwrap ( analytics . receivedProperties . first ? [ " type " ] as? String )
392+ let typePropertyValue = try XCTUnwrap ( eventProperties [ " type " ] as? String )
371393 XCTAssertEqual ( typePropertyValue, " site_address_error " )
372394 }
373395
@@ -388,10 +410,12 @@ final class AppCoordinatorTests: XCTestCase {
388410 pushNotesManager. sendLocalNotificationResponse ( response)
389411
390412 // Then
391- XCTAssertEqual ( analytics. receivedEvents, [ WooAnalyticsStat . loginLocalNotificationTapped. rawValue] )
392- let actionPropertyValue = try XCTUnwrap ( analytics. receivedProperties. first ? [ " action " ] as? String )
413+ let indexOfEvent = try XCTUnwrap ( analytics. receivedEvents. firstIndex ( where: { $0 == WooAnalyticsStat . loginLocalNotificationTapped. rawValue} ) )
414+ let eventProperties = try XCTUnwrap ( analytics. receivedProperties [ indexOfEvent] )
415+
416+ let actionPropertyValue = try XCTUnwrap ( eventProperties [ " action " ] as? String )
393417 XCTAssertEqual ( actionPropertyValue, " default " )
394- let typePropertyValue = try XCTUnwrap ( analytics . receivedProperties . first ? [ " type " ] as? String )
418+ let typePropertyValue = try XCTUnwrap ( eventProperties [ " type " ] as? String )
395419 XCTAssertEqual ( typePropertyValue, " site_address_error " )
396420 }
397421
@@ -412,8 +436,10 @@ final class AppCoordinatorTests: XCTestCase {
412436 pushNotesManager. sendLocalNotificationResponse ( response)
413437
414438 // Then
415- XCTAssertEqual ( analytics. receivedEvents, [ WooAnalyticsStat . loginLocalNotificationDismissed. rawValue] )
416- let typePropertyValue = try XCTUnwrap ( analytics. receivedProperties. first ? [ " type " ] as? String )
439+ let indexOfEvent = try XCTUnwrap ( analytics. receivedEvents. firstIndex ( where: { $0 == WooAnalyticsStat . loginLocalNotificationDismissed. rawValue} ) )
440+ let eventProperties = try XCTUnwrap ( analytics. receivedProperties [ indexOfEvent] )
441+
442+ let typePropertyValue = try XCTUnwrap ( eventProperties [ " type " ] as? String )
417443 XCTAssertEqual ( typePropertyValue, " site_address_error " )
418444 }
419445}
0 commit comments