@@ -27,17 +27,65 @@ with services provided by OneSignal.
2727
2828import XCTest
2929@testable import OneSignalInAppMessages
30+ import OneSignalOSCore
31+ import OneSignalUser
32+ import OneSignalCoreMocks
33+ import OneSignalOSCoreMocks
34+ import OneSignalUserMocks
35+ import OneSignalInAppMessagesMocks
3036
37+ /**
38+ These tests can include some Obj-C InAppMessagingIntegrationTests migrations.
39+ */
3140final class IAMIntegrationTests : XCTestCase {
3241 override func setUpWithError( ) throws {
33- // Put setup code here. This method is called before the invocation of each test method in the class.
34- }
35- override func tearDownWithError( ) throws {
36- // Put teardown code here. This method is called after the invocation of each test method in the class.
37- }
38- func testExample( ) throws {
42+ OneSignalCoreMocks . clearUserDefaults ( )
43+ OneSignalUserMocks . reset ( )
44+ OSConsistencyManager . shared. reset ( )
45+ // Temp. logging to help debug during testing
3946 OneSignalLog . setLogLevel ( . LL_VERBOSE)
40- OneSignalInAppMessages . getFromServer ( " foobar " )
41- OSMessagingController . sharedInstance ( )
47+ }
48+
49+ override func tearDownWithError( ) throws { }
50+
51+ /**
52+ Pausing IAMs will not evaluate messages.
53+ */
54+ func testPausingIAMs_doesNotCreateMessageQueue( ) throws {
55+ /* Setup */
56+
57+ let client = MockOneSignalClient ( )
58+ OneSignalCoreImpl . setSharedClient ( client)
59+
60+ // 1. App ID is set because there are guards against nil App ID
61+ OneSignalConfigManager . setAppId ( " test-app-id " )
62+
63+ // 2. Set up mock responses for the anonymous user, as the user needs an OSID
64+ MockUserRequests . setDefaultCreateAnonUserResponses ( with: client)
65+
66+ // 3. Set up mock responses for fetching IAMs
67+ let message = IAMTestHelpers . testMessageJsonWithTrigger ( property: " session_time " , triggerId: " test_id1 " , type: 1 , value: 10.0 )
68+ let response = IAMTestHelpers . testFetchMessagesResponse ( messages: [ message] )
69+ client. setMockResponseForRequest (
70+ request: " <OSRequestGetInAppMessages from apps/test-app-id/subscriptions/ \( testPushSubId) /iams> " ,
71+ response: response)
72+
73+ // 4. Unblock the Consistency Manager to allow fetching of IAMs
74+ ConsistencyManagerHelpers . setDefaultRywToken ( id: anonUserOSID)
75+
76+ // 5. Pausing should prevent messages from being evaluated and shown
77+ OneSignalInAppMessages . __paused ( true )
78+
79+ // 6. Start the user manager to generate a user instance
80+ OneSignalUserManagerImpl . sharedInstance. start ( )
81+ OneSignalCoreMocks . waitForBackgroundThreads ( seconds: 0.5 )
82+
83+ // 7. Fetch IAMs
84+ OneSignalInAppMessages . getFromServer ( testPushSubId)
85+ OneSignalCoreMocks . waitForBackgroundThreads ( seconds: 0.5 )
86+
87+ // Make sure no IAM is showing, and the queue has no IAMs
88+ XCTAssertFalse ( MockMessagingController . isInAppMessageShowing ( ) )
89+ XCTAssertEqual ( MockMessagingController . messageDisplayQueue ( ) . count, 0 ) ;
4290 }
4391}
0 commit comments