diff --git a/Source/ARTLocalDevice.m b/Source/ARTLocalDevice.m index 4083ff4d6..aded00ba3 100644 --- a/Source/ARTLocalDevice.m +++ b/Source/ARTLocalDevice.m @@ -147,6 +147,9 @@ - (void)setAndPersistIdentityTokenDetails:(ARTDeviceIdentityTokenDetails *)token if (self.clientId == nil) { self.clientId = tokenDetails.clientId; } + if (tokenDetails == nil) { + self.clientId = nil; + } } - (BOOL)isRegistered { diff --git a/Test/Tests/PushActivationStateMachineTests.swift b/Test/Tests/PushActivationStateMachineTests.swift index 105cf240b..66799d4c7 100644 --- a/Test/Tests/PushActivationStateMachineTests.swift +++ b/Test/Tests/PushActivationStateMachineTests.swift @@ -822,8 +822,16 @@ class PushActivationStateMachineTests: XCTestCase { // RSH3g2 func test__054__Activation_state_machine__State_WaitingForDeregistration__on_Event_Deregistered() { - beforeEach__Activation_state_machine__State_WaitingForDeregistration() - + storage = MockDeviceStorage(startWith: ARTPushActivationStateWaitingForDeregistration(machine: initialStateMachine, logger: .init(core: MockInternalLogCore()))) + + let options = ARTClientOptions(key: "xxxx:xxxx") + options.clientId = "client1" + let rest = ARTRest(options: options) + rest.internal.storage = storage + stateMachine = ARTPushActivationStateMachine(rest: rest.internal, delegate: StateMachineDelegate(), logger: .init(core: MockInternalLogCore())) + + XCTAssertEqual(stateMachine.rest.device.clientId, "client1") + var deactivatedCallbackCalled = false let hook = stateMachine.testSuite_injectIntoMethod(after: NSSelectorFromString("callDeactivatedCallback:")) { deactivatedCallbackCalled = true @@ -841,6 +849,7 @@ class PushActivationStateMachineTests: XCTestCase { XCTAssertTrue(deactivatedCallbackCalled) XCTAssertTrue(setAndPersistIdentityTokenDetailsCalled) // RSH3g2a + XCTAssertNil(stateMachine.rest.device.clientId) XCTAssertNil(stateMachine.rest.device.identityTokenDetails) }