Skip to content

Commit 7ac32a2

Browse files
committed
Add Swift IAMTestHelpers file
* Re-usable test helpers and mock functionality
1 parent 8482fcb commit 7ac32a2

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
37E6B2BB19D9CAF300D0C601 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 37E6B2BA19D9CAF300D0C601 /* UIKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
5656
3C0151922C2E298F0079E076 /* OneSignalInAppMessages.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEBAAE282A4211D900BF2C1C /* OneSignalInAppMessages.framework */; };
5757
3C01519C2C2E29F90079E076 /* IAMRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C01519B2C2E29F90079E076 /* IAMRequestTests.m */; };
58+
3C0C67172D493E5A00F80448 /* IAMTestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0C67162D493E5A00F80448 /* IAMTestHelpers.swift */; };
5859
3C0EF49E28A1DBCB00E5434B /* OSUserInternalImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0EF49D28A1DBCB00E5434B /* OSUserInternalImpl.swift */; };
5960
3C115165289A259500565C41 /* OneSignalOSCore.docc in Sources */ = {isa = PBXBuildFile; fileRef = 3C115164289A259500565C41 /* OneSignalOSCore.docc */; };
6061
3C115171289A259500565C41 /* OneSignalOSCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C115163289A259500565C41 /* OneSignalOSCore.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -1246,6 +1247,7 @@
12461247
37E6B2BA19D9CAF300D0C601 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
12471248
3C01518E2C2E298E0079E076 /* OneSignalInAppMessagesTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OneSignalInAppMessagesTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
12481249
3C01519B2C2E29F90079E076 /* IAMRequestTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IAMRequestTests.m; sourceTree = "<group>"; };
1250+
3C0C67162D493E5A00F80448 /* IAMTestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAMTestHelpers.swift; sourceTree = "<group>"; };
12491251
3C0EF49D28A1DBCB00E5434B /* OSUserInternalImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OSUserInternalImpl.swift; sourceTree = "<group>"; };
12501252
3C115161289A259500565C41 /* OneSignalOSCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OneSignalOSCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
12511253
3C115163289A259500565C41 /* OneSignalOSCore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalOSCore.h; sourceTree = "<group>"; };
@@ -2147,6 +2149,7 @@
21472149
isa = PBXGroup;
21482150
children = (
21492151
3C3FABD72D4898E500B7090D /* OneSignalInAppMessagesMocks.h */,
2152+
3C0C67162D493E5A00F80448 /* IAMTestHelpers.swift */,
21502153
);
21512154
path = OneSignalInAppMessagesMocks;
21522155
sourceTree = "<group>";
@@ -3812,6 +3815,7 @@
38123815
};
38133816
3C3FABC92D48985100B7090D = {
38143817
CreatedOnToolsVersion = 16.1;
3818+
LastSwiftMigration = 1610;
38153819
};
38163820
3C8544B52C5AEFF600F542A9 = {
38173821
CreatedOnToolsVersion = 15.2;
@@ -4260,6 +4264,7 @@
42604264
isa = PBXSourcesBuildPhase;
42614265
buildActionMask = 2147483647;
42624266
files = (
4267+
3C0C67172D493E5A00F80448 /* IAMTestHelpers.swift in Sources */,
42634268
);
42644269
runOnlyForDeploymentPostprocessing = 0;
42654270
};
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
Modified MIT License
3+
4+
Copyright 2024 OneSignal
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
1. The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
2. All copies of substantial portions of the Software may only be used in connection
17+
with services provided by OneSignal.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
*/
27+
28+
import Foundation
29+
@testable import OneSignalInAppMessages
30+
31+
let OS_TEST_MESSAGE_ID = "a4b3gj7f-d8cc-11e4-bed1-df8f05be55ba"
32+
let OS_TEST_MESSAGE_VARIANT_ID = "m8dh7234f-d8cc-11e4-bed1-df8f05be55ba"
33+
let OS_TEST_ENGLISH_VARIANT_ID = "11e4-bed1-df8f05be55ba-m8dh7234f-d8cc"
34+
35+
let OS_DUMMY_HTML = "<html><h1>Hello World</h1></html>"
36+
37+
@objc
38+
public class IAMTestHelpers: NSObject {
39+
/// Convert OSTriggerOperatorType enum to string
40+
private static func OS_OPERATOR_TO_STRING(_ type: Int32) -> String {
41+
// Trigger operator strings
42+
let OS_OPERATOR_STRINGS: [String] = [
43+
"greater",
44+
"less",
45+
"equal",
46+
"not_equal",
47+
"less_or_equal",
48+
"greater_or_equal",
49+
"exists",
50+
"not_exists",
51+
"in"
52+
]
53+
54+
return OS_OPERATOR_STRINGS[Int(type)]
55+
}
56+
57+
@objc
58+
public static func testDefaultMessageJson() -> [String: Any] {
59+
return [
60+
"id": String(format: "%@_%i", OS_TEST_MESSAGE_ID, UUID().uuidString),
61+
"variants": [
62+
"ios": [
63+
"default": OS_TEST_MESSAGE_VARIANT_ID,
64+
"en": OS_TEST_ENGLISH_VARIANT_ID
65+
],
66+
"all": [
67+
"default": "should_never_be_used_by_any_test"
68+
]
69+
],
70+
"triggers": []
71+
]
72+
}
73+
74+
@objc
75+
public static func testMessageJsonWithTrigger(property: String, triggerId: String, type: Int32, value: Any) -> [String: Any] {
76+
var testMessage = self.testDefaultMessageJson()
77+
78+
testMessage["triggers"] = [
79+
[
80+
[
81+
"kind": property,
82+
"property": property,
83+
"operator": OS_OPERATOR_TO_STRING(type),
84+
"value": value,
85+
"id": triggerId
86+
]
87+
]
88+
]
89+
return testMessage
90+
}
91+
92+
@objc
93+
public static func testFetchMessagesResponse(messages: [[String: Any]]) -> [String: Any] {
94+
return [
95+
"in_app_messages": messages
96+
]
97+
}
98+
}

0 commit comments

Comments
 (0)