Skip to content

Commit 5f5655d

Browse files
committed
Add / migrate one existing IAM integration test
* Attempt to migrate `testDisablingIAMs_stillCreatesMessageQueue_butPreventsMessageDisplay` to new tests, but behavior has changed. * It becomes `testPausingIAMs_doesNotCreateMessageQueue`
1 parent bfba7f4 commit 5f5655d

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

iOS_SDK/OneSignalSDK/OneSignalInAppMessagesTests/IAMIntegrationTests.swift

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,65 @@ with services provided by OneSignal.
2727

2828
import 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+
*/
3140
final 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
}

iOS_SDK/OneSignalSDK/UnitTests/InAppMessagingIntegrationTests.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,7 @@ of this software and associated documentation files (the "Software"), to deal
14221422
// XCTAssertTrue(action.promptActions[1].hasPrompted);
14231423
// }
14241424

1425+
/// ✅ Migrated to `testPausingIAMs_doesNotCreateMessageQueue`... This test statement below is no longer true as of `5.2.9`.
14251426
// - (void)testDisablingIAMs_stillCreatesMessageQueue_butPreventsMessageDisplay {
14261427
// let message = [OSInAppMessageTestHelper testMessageJsonWithTriggerPropertyName:OS_DYNAMIC_TRIGGER_KIND_SESSION_TIME withId:@"test_id1" withOperator:OSTriggerOperatorTypeLessThan withValue:@10.0];
14271428
// let registrationResponse = [OSInAppMessageTestHelper testRegistrationJsonWithMessages:@[message]];

0 commit comments

Comments
 (0)