-
Notifications
You must be signed in to change notification settings - Fork 265
[tests] In App Messaging tests basic infrastructure #1538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nan-li
wants to merge
10
commits into
main
Choose a base branch
from
tests_iam_module_v5
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c47b9e1
Add Swift `IAMIntegrationTests` test file
nan-li 22ee265
nit: remove unused methods `getTriggerValueForKey`
nan-li 0cdd45a
nit: remove methods from OSMessagingController header
nan-li b3cd370
Add description to `OSRequestGetInAppMessages`
nan-li 0768f8d
Add framework for `OneSignalInAppMessagesMocks`
nan-li ecdd49a
Make a `MockMessagingController`
nan-li 64c25b6
Move `UIApplication+OneSignal` from OneSIgnal > OneSignalInAppMessages
nan-li dfbd6d4
Add `ConsistencyManagerTestHelpers` to tests
nan-li 9de20c7
Add / migrate one existing IAM integration test
nan-li 1df9783
wip
nan-li File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
386 changes: 373 additions & 13 deletions
386
iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
iOS_SDK/OneSignalSDK/OneSignalInAppMessagesMocks/.swiftlint.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
disabled_rules: | ||
- identifier_name |
112 changes: 112 additions & 0 deletions
112
iOS_SDK/OneSignalSDK/OneSignalInAppMessagesMocks/IAMTestHelpers.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
Modified MIT License | ||
|
||
Copyright 2024 OneSignal | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
1. The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
2. All copies of substantial portions of the Software may only be used in connection | ||
with services provided by OneSignal. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
import Foundation | ||
import OneSignalInAppMessages | ||
|
||
let OS_TEST_MESSAGE_ID = "a4b3gj7f-d8cc-11e4-bed1-df8f05be55ba" | ||
let OS_TEST_MESSAGE_VARIANT_ID = "m8dh7234f-d8cc-11e4-bed1-df8f05be55ba" | ||
let OS_TEST_ENGLISH_VARIANT_ID = "11e4-bed1-df8f05be55ba-m8dh7234f-d8cc" | ||
|
||
let OS_DUMMY_HTML = "<html><h1>Hello World</h1></html>" | ||
|
||
@objc | ||
public class IAMTestHelpers: NSObject { | ||
|
||
static var messageIdIncrementer = 0 | ||
|
||
/// Convert OSTriggerOperatorType enum to string | ||
private static func OS_OPERATOR_TO_STRING(_ type: Int32) -> String { | ||
// Trigger operator strings | ||
let OS_OPERATOR_STRINGS: [String] = [ | ||
"greater", | ||
"less", | ||
"equal", | ||
"not_equal", | ||
"less_or_equal", | ||
"greater_or_equal", | ||
"exists", | ||
"not_exists", | ||
"in" | ||
] | ||
|
||
return OS_OPERATOR_STRINGS[Int(type)] | ||
} | ||
|
||
/// Returns the JSON of a minimal in-app message that can be used as a building block. | ||
@objc | ||
public static func defaultMessageJson() -> [String: Any] { | ||
messageIdIncrementer += 1 | ||
return [ | ||
"id": String(format: "%@_%i", OS_TEST_MESSAGE_ID, messageIdIncrementer), | ||
"variants": [ | ||
"ios": [ | ||
"default": OS_TEST_MESSAGE_VARIANT_ID, | ||
"en": OS_TEST_ENGLISH_VARIANT_ID | ||
], | ||
"all": [ | ||
"default": "should_never_be_used_by_any_test" | ||
] | ||
], | ||
"triggers": [] | ||
] | ||
} | ||
|
||
/// Returns the JSON of an in-app message with trigger. | ||
@objc | ||
public static func messageWithTriggerJson(property: String, triggerId: String, type: Int32, value: Any) -> [String: Any] { | ||
var testMessage = self.defaultMessageJson() | ||
|
||
testMessage["triggers"] = [ | ||
[ | ||
[ | ||
"kind": property, | ||
"property": property, | ||
"operator": OS_OPERATOR_TO_STRING(type), | ||
"value": value, | ||
"id": triggerId | ||
] | ||
] | ||
] | ||
return testMessage | ||
} | ||
|
||
@objc | ||
public static func fetchMessagesResponse(messages: [[String: Any]]) -> [String: Any] { | ||
return [ | ||
"in_app_messages": messages | ||
] | ||
} | ||
|
||
/// Returns the JSON of a preview or test in-app message. | ||
@objc | ||
public static func testMessagePreviewJson() -> [String: Any] { | ||
var message = self.defaultMessageJson() | ||
message["is_preview"] = true | ||
return message | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
iOS_SDK/OneSignalSDK/OneSignalInAppMessagesMocks/MockMessagingController.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Modified MIT License | ||
|
||
Copyright 2025 OneSignal | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
1. The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
2. All copies of substantial portions of the Software may only be used in connection | ||
with services provided by OneSignal. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <OneSignalCore/OneSignalCore.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface MockMessagingController : NSObject | ||
+ (NSArray <OSInAppMessage *> *)messageDisplayQueue; // TODO: may need to be changed to return OSInAppMessageInternal | ||
+ (BOOL)isInAppMessageShowing; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
48 changes: 48 additions & 0 deletions
48
iOS_SDK/OneSignalSDK/OneSignalInAppMessagesMocks/MockMessagingController.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Modified MIT License | ||
|
||
Copyright 2025 OneSignal | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
1. The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
2. All copies of substantial portions of the Software may only be used in connection | ||
with services provided by OneSignal. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#import "MockMessagingController.h" | ||
#import "OSMessagingController.h" | ||
|
||
@interface OSMessagingController () | ||
@property (strong, nonatomic, nonnull) NSMutableArray <OSInAppMessageInternal *> *messageDisplayQueue; | ||
@end | ||
|
||
@implementation MockMessagingController | ||
+ (void)resetState { | ||
// TODO: reseting OSMessagingController state between tests | ||
} | ||
|
||
+ (NSArray *)messageDisplayQueue { | ||
return OSMessagingController.sharedInstance.messageDisplayQueue; | ||
} | ||
|
||
+ (BOOL)isInAppMessageShowing { | ||
return OSMessagingController.sharedInstance.isInAppMessageShowing; | ||
} | ||
|
||
@end |
38 changes: 38 additions & 0 deletions
38
iOS_SDK/OneSignalSDK/OneSignalInAppMessagesMocks/OneSignalInAppMessagesMocks.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Modified MIT License | ||
|
||
Copyright 2025 OneSignal | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
1. The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
2. All copies of substantial portions of the Software may only be used in connection | ||
with services provided by OneSignal. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
//! Project version number for OneSignalInAppMessagesMocks. | ||
FOUNDATION_EXPORT double OneSignalInAppMessagesMocksVersionNumber; | ||
|
||
//! Project version string for OneSignalInAppMessagesMocks. | ||
FOUNDATION_EXPORT const unsigned char OneSignalInAppMessagesMocksVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <OneSignalInAppMessagesMocks/PublicHeader.h> | ||
|
||
#import <OneSignalInAppMessagesMocks/MockMessagingController.h> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to address this now?