Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignalOSCoreMocks/OSCoreMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public class OSCoreMocks: NSObject {
public static func resetOperationRepo() {
OSOperationRepo.sharedInstance.reset()
}

/// Clears the file-backed `OSResilientStorage` identifier mirror between tests.
public static func resetResilientStorage() {
OSResilientStorage.setString(nil, forKey: OSResilientStorage.keySubscriptionId)
OSResilientStorage.setString(nil, forKey: OSResilientStorage.keyAppId)
OSResilientStorage.setString(nil, forKey: OSResilientStorage.keyReceiveReceiptsEnabled)
OSResilientStorage.setString(nil, forKey: OSResilientStorage.keyHasPriorSession)
// Force the async write queue to drain so the cleared state is on disk before the test runs.
_ = OSResilientStorage.snapshot()
}
}

extension OSOperationRepo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class OneSignalUserMocks: NSObject {
@objc
public static func reset() {
OSCoreMocks.resetOperationRepo()
OSCoreMocks.resetResilientStorage()
OneSignalUserManagerImpl.sharedInstance.reset()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ - (void)testSendPurchases {

MockOneSignalClient* client = [MockOneSignalClient new];

// 0. Purchases will be dropped if there is no user instance.
[OneSignalUserManagerImpl.sharedInstance start];

// 1. Set up mock responses for the anonymous user
// 0. Set up mock responses for the anonymous user and install the mock client BEFORE start()
[MockUserRequests setDefaultCreateAnonUserResponsesWith:client onesignalId:nil subscriptionId:nil];
[OneSignalCoreImpl setSharedClient:client];

// 1. Purchases will be dropped if there is no user instance, so create the user first.
[OneSignalUserManagerImpl.sharedInstance start];

/* When */

NSMutableArray* arrayOfPurchases = [NSMutableArray new];
Expand Down
Loading