|
| 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