Skip to content

Commit

Permalink
WIP work on not calling default local device fetcher in tests
Browse files Browse the repository at this point in the history
TODO are there tests that rely on using the same fetcher in both cases?

TODO run the whole test suite with breakpoints
  • Loading branch information
lawrence-forooghian committed Apr 18, 2023
1 parent 8e03712 commit 7b97b31
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions Test/Test Utilities/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class AblyTests {
}
options.dispatchQueue = DispatchQueue.main
options.internalDispatchQueue = queue
options.testOptions.localDeviceFetcher = MockLocalDeviceFetcher()
return options
}

Expand Down
24 changes: 14 additions & 10 deletions Test/Tests/PushActivationStateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,17 @@ class PushActivationStateMachineTests: XCTestCase {
override func setUp() {
super.setUp()

rest = ARTRest(key: "xxxx:xxxx")
let options = ARTClientOptions(key: "xxxx:xxxx")
options.testOptions.localDeviceFetcher = MockLocalDeviceFetcher()

rest = ARTRest(options: options)
httpExecutor = MockHTTPExecutor()
rest.internal.httpExecutor = httpExecutor
storage = MockDeviceStorage()
rest.internal.storage = storage
initialStateMachine = ARTPushActivationStateMachine(rest: rest.internal, delegate: StateMachineDelegate(), logger: .init(core: MockInternalLogCore()))
}

override func tearDown() {
DefaultLocalDeviceFetcher.sharedInstance.resetDevice()

super.tearDown()
}

func test__002__Activation_state_machine__should_set_NotActivated_state_as_current_state_when_disk_is_empty() {
expect(initialStateMachine.current).to(beAKindOf(ARTPushActivationStateNotActivated.self))
}
Expand Down Expand Up @@ -119,7 +116,8 @@ class PushActivationStateMachineTests: XCTestCase {
func test__014__Activation_state_machine__State_NotActivated__on_Event_CalledActivate__local_device__should_have_a_generated_id() {
beforeEach__Activation_state_machine__State_NotActivated()

DefaultLocalDeviceFetcher.sharedInstance.resetDevice()
// TODO was the reset here in a special place?

XCTAssertEqual(rest.device.id.count, 36)
}

Expand All @@ -138,6 +136,7 @@ class PushActivationStateMachineTests: XCTestCase {

let options = ARTClientOptions(key: "xxxx:xxxx")
options.clientId = "deviceClient"
options.testOptions.localDeviceFetcher = MockLocalDeviceFetcher()
let rest = ARTRest(options: options)
rest.internal.storage = storage
XCTAssertEqual(rest.device.clientId, "deviceClient")
Expand Down Expand Up @@ -473,7 +472,7 @@ class PushActivationStateMachineTests: XCTestCase {
func test__028__Activation_state_machine__State_WaitingForDeviceRegistration__on_Event_GotDeviceRegistration() {
beforeEach__Activation_state_machine__State_WaitingForDeviceRegistration()

DefaultLocalDeviceFetcher.sharedInstance.resetDevice()
// TODO was the reset here in a special place?

var activatedCallbackCalled = false
let hook = stateMachine.testSuite_injectIntoMethod(after: NSSelectorFromString("callActivatedCallback:")) {
Expand Down Expand Up @@ -907,11 +906,12 @@ class PushActivationStateMachineTests: XCTestCase {
expect(stateMachine.current).to(beAKindOf(ARTPushActivationStateWaitingForPushDeviceDetails.self))
}

// TODO what is this a test of?
func test__001__should_remove_identityTokenDetails_from_cache_and_storage() {
let storage = MockDeviceStorage()
rest.internal.storage = storage
rest.device.setAndPersistIdentityTokenDetails(nil)
DefaultLocalDeviceFetcher.sharedInstance.resetDevice()
// DefaultLocalDeviceFetcher.sharedInstance.resetDevice()
XCTAssertNil(rest.device.identityTokenDetails)
XCTAssertEqual(rest.device.isRegistered(), false)
XCTAssertNil(storage.object(forKey: ARTDeviceIdentityTokenKey))
Expand All @@ -930,14 +930,18 @@ class PushActivationStateMachineTests: XCTestCase {
func test__the_local_device_has_id_and_deviceIdentityToken__emits_a_SyncRegistrationFailed_event_with_code_61002_if_client_IDs_don_t_match() {
contextBeforeEach?()

let localDeviceFetcher = MockLocalDeviceFetcher()

let options = ARTClientOptions(key: "xxxx:xxxx")
options.clientId = "deviceClient"
options.testOptions.localDeviceFetcher = localDeviceFetcher
let rest = ARTRest(options: options)
rest.internal.storage = storage
XCTAssertEqual(rest.device.clientId, "deviceClient")

let newOptions = ARTClientOptions(key: "xxxx:xxxx")
newOptions.clientId = "instanceClient"
newOptions.testOptions.localDeviceFetcher = localDeviceFetcher
let newRest = ARTRest(options: newOptions)
newRest.internal.storage = storage
let stateMachine = ARTPushActivationStateMachine(rest: newRest.internal, delegate: StateMachineDelegate(), logger: .init(core: MockInternalLogCore()))
Expand Down
2 changes: 1 addition & 1 deletion Test/Tests/PushChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class PushChannelTests: XCTestCase {
userQueue = AblyTests.createUserQueue()
options.dispatchQueue = userQueue
options.internalDispatchQueue = AblyTests.queue
options.testOptions.localDeviceFetcher = MockLocalDeviceFetcher()
rest = ARTRest(options: options)
rest.internal.options.clientId = "tester"
rest.internal.httpExecutor = mockHttpExecutor
DefaultLocalDeviceFetcher.sharedInstance.resetDevice()
}

// RSH7
Expand Down
23 changes: 16 additions & 7 deletions Test/Tests/PushTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class PushTests: XCTestCase {
override func setUp() {
super.setUp()

rest = ARTRest(key: "xxxx:xxxx")
DefaultLocalDeviceFetcher.sharedInstance.resetDevice()
let options = ARTClientOptions(key: "xxxx:xxxx")
options.testOptions.localDeviceFetcher = MockLocalDeviceFetcher()

rest = ARTRest(options: options)
mockHttpExecutor = MockHTTPExecutor()
rest.internal.httpExecutor = mockHttpExecutor
storage = MockDeviceStorage()
Expand Down Expand Up @@ -126,8 +128,6 @@ class PushTests: XCTestCase {
let storage = MockDeviceStorage()
rest.internal.storage = storage

DefaultLocalDeviceFetcher.sharedInstance.resetDevice()

var stateMachine: ARTPushActivationStateMachine!
waitUntil(timeout: testTimeout) { done in
rest.push.internal.getActivationMachine { machine in
Expand Down Expand Up @@ -203,8 +203,11 @@ class PushTests: XCTestCase {

// RSH8
func test__008__LocalDevice__has_a_device_method_that_returns_a_LocalDevice() {
let _: ARTLocalDevice = ARTRest(key: "fake:key").device
let _: ARTLocalDevice = ARTRealtime(key: "fake:key").device
let options = ARTClientOptions(key: "fake:key")
options.testOptions.localDeviceFetcher = MockLocalDeviceFetcher()

let _: ARTLocalDevice = ARTRest(options: options).device
let _: ARTLocalDevice = ARTRealtime(options: options).device
}

// RSH8a
Expand All @@ -218,7 +221,10 @@ class PushTests: XCTestCase {
clientId: ""
)

let rest = ARTRest(key: "fake:key")
let options = ARTClientOptions(key: "fake:key")
options.testOptions.localDeviceFetcher = MockLocalDeviceFetcher()

let rest = ARTRest(options: options)
rest.internal.storage = storage
storage.simulateOnNextRead(string: testToken, for: ARTAPNSDeviceTokenKey)
storage.simulateOnNextRead(data: testIdentity.archive(withLogger: nil), for: ARTDeviceIdentityTokenKey)
Expand All @@ -239,6 +245,7 @@ class PushTests: XCTestCase {
callback(ARTTokenDetails(token: "fake:token", expires: nil, issued: nil, capability: nil, clientId: "testClient"), nil)
}
}
options.testOptions.localDeviceFetcher = MockLocalDeviceFetcher()

let realtime = ARTRealtime(options: options)
XCTAssertNil(realtime.device.clientId)
Expand All @@ -258,6 +265,7 @@ class PushTests: XCTestCase {
let options = ARTClientOptions(key: "fake:key")
options.autoConnect = false
options.testOptions.transportFactory = TestProxyTransportFactory()
options.testOptions.localDeviceFetcher = MockLocalDeviceFetcher()

let realtime = ARTRealtime(options: options)
XCTAssertNil(realtime.device.clientId)
Expand Down Expand Up @@ -295,6 +303,7 @@ class PushTests: XCTestCase {
callback(ARTTokenDetails(token: "fake:token", expires: nil, issued: nil, capability: nil, clientId: expectedClient), nil)
}
}
options.testOptions.localDeviceFetcher = MockLocalDeviceFetcher()

let realtime = ARTRealtime(options: options)
let mockHttpExecutor = MockHTTPExecutor()
Expand Down

0 comments on commit 7b97b31

Please sign in to comment.