From 2e215b410e10795f9fa479eb93825018921a20b9 Mon Sep 17 00:00:00 2001 From: Nan Date: Tue, 13 Feb 2024 20:58:03 -0800 Subject: [PATCH] Delete old "user model" test files * Delete old "user model" test files `UserModelObjcTests.m and `UserModelSwiftTests.swift` - These weren't real tests --- .../OneSignal.xcodeproj/project.pbxproj | 8 - .../UnitTests/UserModelObjcTests.m | 210 ------------------ .../UnitTests/UserModelSwiftTests.swift | 196 ---------------- 3 files changed, 414 deletions(-) delete mode 100644 iOS_SDK/OneSignalSDK/UnitTests/UserModelObjcTests.m delete mode 100644 iOS_SDK/OneSignalSDK/UnitTests/UserModelSwiftTests.swift diff --git a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj index 78019bd5b..9194e4a7c 100644 --- a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj +++ b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj @@ -67,8 +67,6 @@ 3C14E39F2AFAE39B006ED053 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C14E39E2AFAE39B006ED053 /* PrivacyInfo.xcprivacy */; }; 3C14E3A12AFAE461006ED053 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C14E3A02AFAE461006ED053 /* PrivacyInfo.xcprivacy */; }; 3C14E3A42AFAE54C006ED053 /* OneSignalSwiftInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC08AFF2947D4E900C81DA3 /* OneSignalSwiftInterface.swift */; }; - 3C2C7DC4288E007E0020F9AE /* UserModelSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C2C7DC3288E007E0020F9AE /* UserModelSwiftTests.swift */; }; - 3C2C7DC6288E00AA0020F9AE /* UserModelObjcTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C2C7DC5288E00AA0020F9AE /* UserModelObjcTests.m */; }; 3C2C7DC8288F3C020020F9AE /* OSSubscriptionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C2C7DC7288F3C020020F9AE /* OSSubscriptionModel.swift */; }; 3C2D8A5928B4C4E300BE41F6 /* OSDelta.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C2D8A5828B4C4E300BE41F6 /* OSDelta.swift */; }; 3C44673E296D099D0039A49E /* OneSignalMobileProvision.m in Sources */ = {isa = PBXBuildFile; fileRef = 912411FD1E73342200E41FD7 /* OneSignalMobileProvision.m */; }; @@ -947,8 +945,6 @@ 3C14E39E2AFAE39B006ED053 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 3C14E3A02AFAE461006ED053 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; 3C2C7DC2288E007E0020F9AE /* UnitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UnitTests-Bridging-Header.h"; sourceTree = ""; }; - 3C2C7DC3288E007E0020F9AE /* UserModelSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserModelSwiftTests.swift; sourceTree = ""; }; - 3C2C7DC5288E00AA0020F9AE /* UserModelObjcTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UserModelObjcTests.m; sourceTree = ""; }; 3C2C7DC7288F3C020020F9AE /* OSSubscriptionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSSubscriptionModel.swift; sourceTree = ""; }; 3C2D8A5828B4C4E300BE41F6 /* OSDelta.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSDelta.swift; sourceTree = ""; }; 3C448B9B2936ADFD002F96BC /* OSBackgroundTaskHandlerImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSBackgroundTaskHandlerImpl.h; sourceTree = ""; }; @@ -1831,8 +1827,6 @@ 911E2CBB1E398AB3003112A4 /* UnitTests */ = { isa = PBXGroup; children = ( - 3C2C7DC5288E00AA0020F9AE /* UserModelObjcTests.m */, - 3C2C7DC3288E007E0020F9AE /* UserModelSwiftTests.swift */, 03CCCC802835D902004BF794 /* UNNotificationCenter */, 7A5A818324899050002E07C8 /* Models */, 03866CBE2378A5ED0009C1D8 /* Asserts */, @@ -3397,7 +3391,6 @@ 91F60F7D1E80E4E400706E60 /* UncaughtExceptionHandler.m in Sources */, 912412201E73342200E41FD7 /* OneSignalJailbreakDetection.m in Sources */, 03E56DD328405F4A006AA1DA /* OneSignalAppDelegateOverrider.m in Sources */, - 3C2C7DC4288E007E0020F9AE /* UserModelSwiftTests.swift in Sources */, 7ABAF9D82457DD620074DFA0 /* SessionManagerTests.m in Sources */, CA85C15320604AEA003AB529 /* RequestTests.m in Sources */, 9D34853A233D2E3600EB81C9 /* OneSignalLocationOverrider.m in Sources */, @@ -3444,7 +3437,6 @@ 912412401E73342200E41FD7 /* UIApplicationDelegate+OneSignal.m in Sources */, CACBAAAA218A65AE000ACAA5 /* InAppMessagingTests.m in Sources */, 3C9AD6D52B22A8C400BC1540 /* OneSignalLiveActivityController.m in Sources */, - 3C2C7DC6288E00AA0020F9AE /* UserModelObjcTests.m in Sources */, 4529DEDB1FA8284E00CEAB1D /* NSDataOverrider.m in Sources */, A662399326850DDE00D52FD8 /* LanguageTest.m in Sources */, DEA4B44E2888AF8900E9FE12 /* OneSignalUNUserNotificationCenterOverrider.m in Sources */, diff --git a/iOS_SDK/OneSignalSDK/UnitTests/UserModelObjcTests.m b/iOS_SDK/OneSignalSDK/UnitTests/UserModelObjcTests.m deleted file mode 100644 index 5d908c1c8..000000000 --- a/iOS_SDK/OneSignalSDK/UnitTests/UserModelObjcTests.m +++ /dev/null @@ -1,210 +0,0 @@ -/* - Modified MIT License - - Copyright 2022 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 -#import "OneSignalFramework.h" - -@interface UserModelObjcTests : XCTestCase - -@end - - -@interface OSPushSubscriptionTestObserver: NSObject -- (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState * _Nonnull)state; -@end - -@implementation OSPushSubscriptionTestObserver -- (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState * _Nonnull)state { - NSLog(@"🔥 UnitTest:onOSPushSubscriptionChanged :%@ :%@", state.previous, state.current); - -} -@end - -@implementation UserModelObjcTests - -- (void)setUp { - // Put setup code here. This method is called before the invocation of each test method in the class. - [super setUp]; -} - -- (void)tearDown { - // Put teardown code here. This method is called after the invocation of each test method in the class. - [super tearDown]; -} - -/** - This test lays out the public APIs of the user model - */ -- (void)testUserModelMethodAccess { - - // User Identity - [OneSignal login:@"foo"]; - [OneSignal login:@"foo" withToken:@"someToken"]; - [OneSignal login:@"foo" withToken:nil]; - - [OneSignal logout]; - - // Aliases - [OneSignal.User addAliasWithLabel:@"foo" id:@"foo1"]; - [OneSignal.User addAliases:@{@"foo": @"foo1", @"bar": @"bar2"}]; - [OneSignal.User removeAlias:@"foo"]; - [OneSignal.User removeAliases:@[@"foo", @"bar"]]; - - // Tags - [OneSignal.User addTagWithKey:@"foo" value:@"bar"]; - [OneSignal.User addTags:@{@"foo": @"foo1", @"bar": @"bar2"}]; - [OneSignal.User removeTag:@"foo"]; - [OneSignal.User removeTags:@[@"foo", @"bar"]]; - - // Email - [OneSignal.User addEmail:@"person@example.com"]; - [OneSignal.User removeEmail:@"person@example.com"]; - - // SMS - [OneSignal.User addSms:@"+15551231234"]; - [OneSignal.User removeSms:@"+15551231234"]; - - // Triggers - [OneSignal.InAppMessages addTrigger:@"foo" withValue:@"bar"]; - [OneSignal.InAppMessages addTriggers:@{@"foo": @"foo1", @"bar": @"bar2"}]; - [OneSignal.InAppMessages removeTrigger:@"foo"]; - [OneSignal.InAppMessages removeTriggers:@[@"foo", @"bar"]]; - [OneSignal.InAppMessages clearTriggers]; -} - -/** - This is to collect things that should not work, but do for now. - */ -- (void)testTheseShouldNotWork { - // Should not be settable - // OneSignal.user.pushSubscription.token = [NSUUID new]; // <- Confirmed that users can't set token - // OneSignal.user.pushSubscription.subscriptionId = [NSUUID new]; // <- Confirmed that users can't set subscriptionId -} - -/** - Test the access of properties and methods, and setting properties related to the push subscription. - */ -- (void)testPushSubscriptionPropertiesAccess { - // TODO: Fix these unit tests -// // Create a user and mock pushSubscription -// id user = OneSignal.user; -// [user testCreatePushSubscriptionWithSubscriptionId:[NSUUID new] token:[NSUUID new] enabled:false]; -// -// // Access properties of the pushSubscription -// NSUUID* subscriptionId = user.pushSubscription.subscriptionId; -// NSUUID* token = user.pushSubscription.token; -// bool enabled = user.pushSubscription.enabled; // BOOL or bool preferred? -// -// // Set the enabled property of the pushSubscription -// user.pushSubscription.enabled = true; -// -// // Create a push subscription observer -// OSPushSubscriptionTestObserver* observer = [OSPushSubscriptionTestObserver new]; - - // Push subscription observers are not user-scoped -// [OneSignal addSubscriptionObserver:observer]; -// [OneSignal removeSubscriptionObserver:observer]; -} - -/** - Test the model repo hook up via a login with external ID and setting alias. - Test the operation repo hookup as well and check the deltas being enqueued and flushed. - */ -- (void)testModelAndOperationRepositoryHookUpWithLoginAndSetAlias { - // login an user with external ID - [OneSignal login:@"user01"]; - - // Check that deltas for alias (Identity) are created correctly and enqueued. - NSLog(@"🔥 Unit Tests adding alias label_01: user_01"); - [OneSignal.User addAliasWithLabel:@"label_01" id:@"user_01"]; - [OneSignal.User removeAlias:@"nonexistent"]; - [OneSignal.User removeAlias:@"label_01"]; - [OneSignal.User addAliasWithLabel:@"label_02" id:@"user_02"]; - [OneSignal.User addAliases:@{@"test1": @"user1", @"test2": @"user2", @"test3": @"user3"}]; - [OneSignal.User removeAliases:@[@"test1", @"label_01", @"test2"]]; - - [OneSignal.User addTagWithKey:@"foo" value:@"bar"]; - - // Sleep to allow the flush to be called 1 time. - [NSThread sleepForTimeInterval:6.0f]; -} - -/** - Test login and logout and creation of guest users. - */ -- (void)testLoginLogout { - // A guest user is created when OneSignal.User is accessed - [OneSignal.User addEmail:@"test@email.com"]; - - // ... and more to be added -} - -/** - Test email and sms subscriptions. 2 Deltas are created for each add. - */ -- (void)testEmailAndSmsSubscriptions { - [OneSignal.User addEmail:@"test@example.com"]; - [OneSignal.User addSms:@"+15551231234"]; - - // Sleep to allow the flush to be called 1 time. - [NSThread sleepForTimeInterval:6.0f]; -} - -/** - Test setLocation lat long - */ -- (void)testSetLocation { - [OneSignalUserManagerImpl.sharedInstance setLocationWithLatitude:37.5 longitude:122.3]; -} - -/** - Temp tester. - */ -- (void)testTempTester { - - [OneSignal.Notifications requestPermission:^(BOOL accepted) { - NSLog(@"🔥 promptForPushNotificationsWithUserResponse: %d", accepted); - }]; - - [OneSignal.Notifications requestPermission:^(BOOL accepted) { - NSLog(@"🔥 promptForPushNotificationsWithUserResponse: %d", accepted); - } fallbackToSettings:true]; - - // IAM Pausing - [OneSignal.InAppMessages paused:true]; - BOOL paused = [OneSignal.InAppMessages paused]; -} - -- (void)testOnJwtExpired { - // TODO: Fix autocompletion. It isn't auto completing parameter names which makes this unreadable - [OneSignal.User onJwtExpiredWithExpiredHandler:^(NSString * _Nonnull externalId, void (^ _Nonnull completion)(NSString * _Nonnull)) { - NSString *newToken = externalId; - completion(newToken); - }]; -} - -@end diff --git a/iOS_SDK/OneSignalSDK/UnitTests/UserModelSwiftTests.swift b/iOS_SDK/OneSignalSDK/UnitTests/UserModelSwiftTests.swift deleted file mode 100644 index 9b9fb5f9b..000000000 --- a/iOS_SDK/OneSignalSDK/UnitTests/UserModelSwiftTests.swift +++ /dev/null @@ -1,196 +0,0 @@ -/* - Modified MIT License - - Copyright 2022 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 XCTest - -// Non-class type 'OSPushSubscriptionTestObserver' cannot conform to class protocol 'OSPushSubscriptionObserver' -// ^ Cannot use a struct for an OSPushSubscriptionObserver - -class OSPushSubscriptionTestObserver: OSPushSubscriptionObserver { - func onPushSubscriptionDidChange(state: OneSignalUser.OSPushSubscriptionChangedState) { - print("🔥 onPushSubscriptionDidChange \(state.previous) -> \(state.current)") - // dump(stateChanges.from) -> uncomment for more verbose log during testing - // dump(stateChanges.to) -> uncomment for more verbose log during testing - } -} - -class UserModelSwiftTests: XCTestCase { - - override func setUpWithError() throws { - // Put setup code here. This method is called before the invocation of each test method in the class. - try super.setUpWithError() - } - - override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. - try super.tearDownWithError() - } - - /** - This test lays out the public APIs of the user model - */ - func testUserModelMethodAccess() throws { - - // User Identity - OneSignal.login("foo") - OneSignal.login(externalId: "foo", token: "someToken") - OneSignal.login(externalId: "foo", token: nil) - OneSignal.logout() - - // Aliases - OneSignal.User.addAlias(label: "foo", id: "bar") - OneSignal.User.addAliases(["foo": "foo1", "bar": "bar2"]) - OneSignal.User.removeAlias("foo") - OneSignal.User.removeAliases(["foo", "bar"]) - - // Tags - OneSignal.User.addTag(key: "foo", value: "bar") - OneSignal.User.addTags(["foo": "foo1", "bar": "bar2"]) - OneSignal.User.removeTag("foo") - OneSignal.User.removeTags(["foo", "bar"]) - - // Email - OneSignal.User.addEmail("person@example.com") - _ = OneSignal.User.removeEmail("person@example.com") - - // SMS - OneSignal.User.addSms("+15551231234") - _ = OneSignal.User.removeSms("+15551231234") - - // Triggers - OneSignal.InAppMessages.addTrigger("foo", withValue: "bar") - OneSignal.InAppMessages.addTriggers(["foo": "foo1", "bar": "bar2"]) - OneSignal.InAppMessages.removeTrigger("foo") - OneSignal.InAppMessages.removeTriggers(["foo", "bar"]) - OneSignal.InAppMessages.clearTriggers() - - // OneSignal.InAppMessages.addClickListener(listener) - // OneSignal.InAppMessages.addLifecycleListener(listener) - } - - /** - This is to collect things that should not work, but do for now. - */ - func testTheseShouldNotWork() throws { - // Should not be settable - // OneSignal.user.pushSubscription.token = UUID() // <- Confirmed that users can't set token - // OneSignal.user.pushSubscription.subscriptionId = UUID() // <- Confirmed that users can't set subscriptionId - } - - /** - Test the access of properties and methods, and setting properties related to the push subscription. - */ - func testPushSubscriptionPropertiesAccess() throws { - // TODO: Fix these unit tests - -// // Create a user and mock pushSubscription -// let user = OneSignal.user -// user.testCreatePushSubscription(subscriptionId: UUID(), token: UUID(), enabled: false) -// -// // Access properties of the pushSubscription -// _ = user.pushSubscription.subscriptionId -// _ = user.pushSubscription.token -// _ = user.pushSubscription.enabled -// -// // Set the enabled property of the pushSubscription -// user.pushSubscription.enabled = true -// -// // Create a push subscription observer -// let observer = OSPushSubscriptionTestObserver() - - // Push subscription observers are not user-scoped - // TODO: UM The following does not build as of now - // OneSignal.addSubscriptionObserver(observer) - // OneSignal.removeSubscriptionObserver(observer) - } - - /** - Test the model repo hook up via a login with external ID and setting alias. - Test the operation repo hookup as well and check the deltas being enqueued and flushed. - */ - func testModelAndOperationRepositoryHookUpWithLoginAndSetAlias() throws { - // login an user with external ID - OneSignal.login("user01") - - // Check that deltas for alias (Identity) are created correctly and enqueued. - print("🔥 Unit Tests adding alias label_01: user_01") - OneSignal.User.addAlias(label: "label_01", id: "user_01") - OneSignal.User.removeAlias("nonexistent") - OneSignal.User.removeAlias("label_01") - OneSignal.User.addAlias(label: "label_02", id: "user_02") - OneSignal.User.addAliases(["test1": "user1", "test2": "user2", "test3": "user3"]) - OneSignal.User.removeAliases(["test1", "label_01", "test2"]) - - OneSignal.User.addTag(key: "foo", value: "bar") - - // Sleep to allow the flush to be called 1 time. - Thread.sleep(forTimeInterval: 6) - } - - /** - Test login and logout and creation of guest users. - */ - func testLoginLogout() throws { - // A guest user is created when OneSignal.User is accessed - OneSignal.User.addEmail("test@email.com") - // ... and more to be added - } - - /** - Test email and sms subscriptions. 2 Deltas are created for each add. - */ - func testEmailAndSmsSubscriptions() throws { - OneSignal.User.addEmail("test@example.com") - OneSignal.User.addSms("+15551231234") - - // Sleep to allow the flush to be called 1 time. - Thread.sleep(forTimeInterval: 6) - } - - /** - Temp test. - */ - func testTempTester() throws { - OneSignal.Notifications.requestPermission { accepted in - print("🔥 promptForPushNotificationsWithUserResponse: \(accepted)") - } - OneSignal.Notifications.requestPermission({ accepted in - print("🔥 promptForPushNotificationsWithUserResponse: \(accepted)") - }, fallbackToSettings: true) - - // IAM pausing - OneSignal.InAppMessages.paused = true - let paused = OneSignal.InAppMessages.paused - } - - func testJWTTokenExpired() { - OneSignal.User.onJwtExpired { externalId, completion in - let newToken = externalId + "newtokenbasedonexternalid" - completion(newToken) - } - } -}