Skip to content

Commit

Permalink
Update push tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardopereira authored and Quintin Willison committed Oct 6, 2020
1 parent c6fe33f commit 8e80191
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions Spec/Push.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class Push : QuickSpec {
storage = MockDeviceStorage()
rest.internal.storage = storage
stateMachineDelegate = StateMachineDelegate()
rest.push.internal.activationMachine().delegate = stateMachineDelegate
rest.push.internal.createActivationStateMachine_nolock(stateMachineDelegate!)
}

// RSH2
describe("activation") {

// RSH2a
it("activate method should send a CalledActivate event to the state machine") {
defer { rest.push.internal.activationMachine().transitions = nil }
defer { rest.push.internal.activationMachine!.transitions = nil }
waitUntil(timeout: testTimeout) { done in
rest.push.internal.activationMachine().transitions = { event, _, _ in
rest.push.internal.activationMachine!.transitions = { event, _, _ in
if event is ARTPushActivationEventCalledActivate {
done()
}
Expand All @@ -47,9 +47,9 @@ class Push : QuickSpec {

// RSH2b
it("deactivate method should send a CalledDeactivate event to the state machine") {
defer { rest.push.internal.activationMachine().transitions = nil }
defer { rest.push.internal.activationMachine!.transitions = nil }
waitUntil(timeout: testTimeout) { done in
rest.push.internal.activationMachine().transitions = { event, _, _ in
rest.push.internal.activationMachine!.transitions = { event, _, _ in
if event is ARTPushActivationEventCalledDeactivate {
done()
}
Expand All @@ -60,7 +60,7 @@ class Push : QuickSpec {

// RSH2c / RSH8g
it("should handle GotPushDeviceDetails event when platform’s APIs sends the details for push notifications") {
let stateMachine = rest.push.internal.activationMachine()
let stateMachine = rest.push.internal.activationMachine!
let testDeviceToken = "xxxx-xxxx-xxxx-xxxx-xxxx"
stateMachine.rest.device.setAndPersistDeviceToken(testDeviceToken)
let stateMachineDelegate = StateMachineDelegate()
Expand All @@ -82,7 +82,7 @@ class Push : QuickSpec {

// RSH2d / RSH8h
it("sends GettingPushDeviceDetailsFailed when push registration fails") {
let stateMachine = rest.push.internal.activationMachine()
let stateMachine = rest.push.internal.activationMachine!
defer { stateMachine.transitions = nil }
waitUntil(timeout: testTimeout) { done in
stateMachine.transitions = { event, _, _ in
Expand Down Expand Up @@ -121,7 +121,14 @@ class Push : QuickSpec {

rest.internal.resetDeviceSingleton()

let stateMachine = rest.push.internal.activationMachine()
var stateMachine: ARTPushActivationStateMachine!
waitUntil(timeout: testTimeout) { done in
rest.push.internal.getActivationMachine { machine in
stateMachine = machine
done()
}
}

let testDeviceToken = "xxxx-xxxx-xxxx-xxxx-xxxx"
stateMachine.rest.device.setAndPersistDeviceToken(testDeviceToken)
let stateMachineDelegate = StateMachineDelegate()
Expand Down Expand Up @@ -172,9 +179,9 @@ class Push : QuickSpec {
let deviceTokenBase64 = "HYRXxPSQdt1pnxqtDAvc6PTTLH7N6okiBhYyLClJdmQ="
let deviceTokenData = Data(base64Encoded: deviceTokenBase64, options: [])!
let expectedDeviceToken = "1d8457c4f49076dd699f1aad0c0bdce8f4d32c7ecdea89220616322c29497664"
defer { rest.push.internal.activationMachine().transitions = nil }
defer { rest.push.internal.activationMachine!.transitions = nil }
waitUntil(timeout: testTimeout) { done in
rest.push.internal.activationMachine().onEvent = { event, _ in
rest.push.internal.activationMachine!.onEvent = { event, _ in
if event is ARTPushActivationEventGotPushDeviceDetails {
done()
}
Expand Down Expand Up @@ -293,16 +300,24 @@ class Push : QuickSpec {
}

let realtime = ARTRealtime(options: options)

let storage = MockDeviceStorage(
startWith: ARTPushActivationStateWaitingForNewPushDeviceDetails(
machine: ARTPushActivationStateMachine(rest.internal)
)
)
realtime.internal.rest.storage = storage
let stateMachine = realtime.internal.rest.push.activationMachine()

var stateMachine: ARTPushActivationStateMachine!
waitUntil(timeout: testTimeout) { done in
realtime.internal.rest.push.getActivationMachine { machine in
stateMachine = machine
done()
}
}
let delegate = StateMachineDelegate()
stateMachine.delegate = delegate

storage.simulateOnNextRead(string: testToken, for: ARTDeviceTokenKey)
storage.simulateOnNextRead(data: testIdentity.archive(), for: ARTDeviceIdentityTokenKey)

Expand Down Expand Up @@ -332,7 +347,7 @@ class Push : QuickSpec {
clientId: expectedClientId
)
}
rest.push.internal.activationMachine().delegate = stateMachineDelegate
rest.push.internal.activationMachine!.delegate = stateMachineDelegate

expect(rest.device.clientId).to(beNil())

Expand Down

0 comments on commit 8e80191

Please sign in to comment.