@@ -348,12 +348,11 @@ final class UserExecutorTests: XCTestCase {
348
348
349
349
mocks. setAuthRequired ( true )
350
350
351
- _ = mocks. setUserManagerInternalUser ( externalId: userA_EUID)
351
+ let userA = mocks. setUserManagerInternalUser ( externalId: userA_EUID, onesignalId : userA_OSID )
352
352
// We need to use the user manager's executor because the onJWTUpdated callback won't fire on the mock executor
353
353
let executor = OneSignalUserManagerImpl . sharedInstance. userExecutor!
354
354
355
- let userAIdentityModel = OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: userA_OSID, OS_EXTERNAL_ID: userA_EUID] , changeNotifier: OSEventProducer ( ) )
356
- userAIdentityModel. jwtBearerToken = userA_InvalidJwtToken
355
+ userA. identityModel. jwtBearerToken = userA_InvalidJwtToken
357
356
358
357
MockUserRequests . setUnauthorizedFetchUserFailureResponses ( with: mocks. client, onesignalId: userA_OSID)
359
358
MockUserRequests . setUnauthorizedCreateUserFailureResponses ( with: mocks. client, externalId: userA_EUID)
@@ -364,8 +363,8 @@ final class UserExecutorTests: XCTestCase {
364
363
}
365
364
366
365
/* When */
367
- executor. fetchUser ( onesignalId: userA_OSID, identityModel: userAIdentityModel )
368
- executor. createUser ( aliasLabel: OS_EXTERNAL_ID, aliasId: userA_EUID, identityModel: userAIdentityModel )
366
+ executor. fetchUser ( onesignalId: userA_OSID, identityModel: userA . identityModel )
367
+ executor. createUser ( aliasLabel: OS_EXTERNAL_ID, aliasId: userA_EUID, identityModel: userA . identityModel )
369
368
OneSignalCoreMocks . waitForBackgroundThreads ( seconds: 0.5 )
370
369
371
370
MockUserRequests . setDefaultFetchUserResponseForHydration ( with: mocks. client, externalId: userA_EUID)
@@ -379,24 +378,34 @@ final class UserExecutorTests: XCTestCase {
379
378
XCTAssertTrue ( mocks. client. hasExecutedRequestOfType ( OSRequestFetchUser . self) )
380
379
XCTAssertTrue ( mocks. client. hasExecutedRequestOfType ( OSRequestCreateUser . self) )
381
380
XCTAssertTrue ( invalidatedCallbackWasCalled)
382
- XCTAssertEqual ( mocks. client. networkRequestCount, 4 )
381
+ /*
382
+ Create and Fetch requests that fail
383
+ Create and Fetch requests that pass
384
+ Follow up Fetch made after the success of the Create request
385
+ */
386
+ XCTAssertEqual ( mocks. client. networkRequestCount, 5 )
383
387
}
384
388
389
+ /**
390
+ This test executes a Fetch on userA, and a Create on userB, encountering an unauthorized response for both requests.
391
+ The test next updates the JWT token for userA only.
392
+ It expects only the Fetch userA request to be sent next.
393
+ */
385
394
func testUserRequests_RetryRequests_OnTokenUpdate_ForOnlyUpdatedUser( ) {
386
395
/* Setup */
387
396
let mocks = Mocks ( )
388
397
389
398
mocks. setAuthRequired ( true )
390
399
391
- _ = mocks. setUserManagerInternalUser ( externalId: userA_EUID)
400
+ let userA = mocks. setUserManagerInternalUser ( externalId: userA_EUID, onesignalId : userA_OSID )
392
401
// We need to use the user manager's executor because the onJWTUpdated callback won't fire on the mock executor
393
402
let executor = OneSignalUserManagerImpl . sharedInstance. userExecutor!
394
403
395
- let userAIdentityModel = OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: userA_OSID, OS_EXTERNAL_ID: userA_EUID] , changeNotifier: OSEventProducer ( ) )
396
- userAIdentityModel. jwtBearerToken = userA_InvalidJwtToken
404
+ userA. identityModel. jwtBearerToken = userA_InvalidJwtToken
397
405
398
406
let userBIdentityModel = OSIdentityModel ( aliases: [ OS_ONESIGNAL_ID: userB_OSID, OS_EXTERNAL_ID: userB_EUID] , changeNotifier: OSEventProducer ( ) )
399
407
userBIdentityModel. jwtBearerToken = userA_InvalidJwtToken
408
+ OneSignalUserManagerImpl . sharedInstance. addIdentityModelToRepo ( userBIdentityModel)
400
409
401
410
MockUserRequests . setUnauthorizedFetchUserFailureResponses ( with: mocks. client, onesignalId: userA_OSID)
402
411
MockUserRequests . setUnauthorizedCreateUserFailureResponses ( with: mocks. client, externalId: userB_EUID)
@@ -407,7 +416,7 @@ final class UserExecutorTests: XCTestCase {
407
416
}
408
417
409
418
/* When */
410
- executor. fetchUser ( onesignalId: userA_OSID, identityModel: userAIdentityModel )
419
+ executor. fetchUser ( onesignalId: userA_OSID, identityModel: userA . identityModel )
411
420
executor. createUser ( aliasLabel: OS_EXTERNAL_ID, aliasId: userB_EUID, identityModel: userBIdentityModel)
412
421
OneSignalCoreMocks . waitForBackgroundThreads ( seconds: 0.5 )
413
422
0 commit comments