Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public class OneSignalUserMocks: NSObject {
// TODO: create mocked server responses to user requests
@objc
public static func reset() {
OSResilientStorage.setStrings([
OSResilientStorage.keyAppId: "",
OSResilientStorage.keySubscriptionId: "",
OSResilientStorage.keyReceiveReceiptsEnabled: "",
OSResilientStorage.keyHasPriorSession: ""
])
_ = OSResilientStorage.snapshot()
OSCoreMocks.resetOperationRepo()
OneSignalUserManagerImpl.sharedInstance.reset()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ final class UserExecutorTests: XCTestCase {

/* When */
let anonIdentityModel = OSIdentityModel(aliases: [OS_ONESIGNAL_ID: userA_OSID], changeNotifier: OSEventProducer())
let newIdentityModel = OSIdentityModel(aliases: [OS_EXTERNAL_ID: userA_EUID], changeNotifier: OSEventProducer())

// The current user needs to be the same, set it in the user manager
OneSignalUserManagerImpl.sharedInstance.identityModelStore.add(id: OS_IDENTITY_MODEL_KEY, model: newIdentityModel, hydrating: false)
let newIdentityModel = OneSignalUserMocks
.setUserManagerInternalUser(externalId: userA_EUID, onesignalId: nil)
.identityModel
mocks.userExecutor.identifyUser(externalId: userA_EUID, identityModelToIdentify: anonIdentityModel, identityModelToUpdate: newIdentityModel)

OneSignalCoreMocks.waitForBackgroundThreads(seconds: 0.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ - (void)testSendPurchases {
/* Setup */

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
[MockUserRequests setDefaultCreateAnonUserResponsesWith:client onesignalId:nil subscriptionId:nil];
[OneSignalCoreImpl setSharedClient:client];

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

/* When */

NSMutableArray* arrayOfPurchases = [NSMutableArray new];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,13 @@ final class OneSignalUserTests: XCTestCase {
let checkedUser = manager.currentUser(matching: userA.identityModel.modelId)
// A concurrent login switches the current user before the response is applied
let userB = OneSignalUserMocks.setUserManagerInternalUser(externalId: userB_EUID, onesignalId: userB_OSID)
let userBLanguage = userB.propertiesModel.language
checkedUser?.propertiesModel.hydrate(["language": "language-for-user-a"])

/* Then */
// The response's data went to the user it was for, and the new current user is untouched
XCTAssertEqual(userA.propertiesModel.language, "language-for-user-a")
XCTAssertNil(userB.propertiesModel.language)
XCTAssertEqual(userB.propertiesModel.language, userBLanguage)
XCTAssertEqual(manager._user?.identityModel.externalId, userB_EUID)
}

Expand Down
Loading