@@ -741,7 +741,7 @@ class RequestHandlerTests: XCTestCase {
741
741
wait ( for: [ expectation2] , timeout: testExpectationTimeout)
742
742
}
743
743
744
- func testDefaultUsesOnlineMode ( ) throws {
744
+ func testDefaultRemoteConfigurationUsesOnlineMode ( ) throws {
745
745
let expectation1 = expectation ( description: " getRemoteConfiguration is called " )
746
746
let remoteConfigurationData = """
747
747
{
@@ -807,6 +807,63 @@ class RequestHandlerTests: XCTestCase {
807
807
wait ( for: [ expectation2] , timeout: testExpectationTimeout)
808
808
}
809
809
810
+ func testLoadOfflineModeEnabledFromLocalStorage( ) throws {
811
+ let expectation1 = expectation ( description: " getRemoteConfiguration is called " )
812
+ var mapper = [ String: Data? ] ( )
813
+ mapper [ " getRemoteConfiguration " ] = nil
814
+ let networkSession = MockNetworkSession ( statusCode: 200 , urlPatternDataMapping: mapper)
815
+ networkSession. requestCallback = { request in
816
+ if request. url!. absoluteString. contains ( Const . Path. getRemoteConfiguration) {
817
+ expectation1. fulfill ( )
818
+ }
819
+ }
820
+ let localStorage = MockLocalStorage ( )
821
+ localStorage
. email
= " [email protected] "
822
+ localStorage. offlineModeBeta = true
823
+ let internalAPI = InternalIterableAPI . initializeForTesting ( networkSession: networkSession, localStorage: localStorage)
824
+ wait ( for: [ expectation1] , timeout: testExpectationTimeout)
825
+
826
+ let expectation2 = expectation ( description: #function)
827
+ networkSession. requestCallback = { request in
828
+ if request. url!. absoluteString. contains ( " track " ) {
829
+ let processor = request. allHTTPHeaderFields ? [ JsonKey . Header. requestProcessor] !
830
+ XCTAssertEqual ( processor, Const . ProcessorTypeName. offline)
831
+ expectation2. fulfill ( )
832
+ }
833
+ }
834
+ internalAPI. track ( " myEvent " )
835
+ wait ( for: [ expectation2] , timeout: testExpectationTimeout)
836
+ }
837
+
838
+ func testLoadOfflineModeDisabledFromLocalStorage( ) throws {
839
+ let expectation1 = expectation ( description: " getRemoteConfiguration is called " )
840
+ var mapper = [ String: Data? ] ( )
841
+ mapper [ " getRemoteConfiguration " ] = nil
842
+ let networkSession = MockNetworkSession ( statusCode: 200 , urlPatternDataMapping: mapper)
843
+ networkSession. requestCallback = { request in
844
+ if request. url!. absoluteString. contains ( Const . Path. getRemoteConfiguration) {
845
+ expectation1. fulfill ( )
846
+ }
847
+ }
848
+ let localStorage = MockLocalStorage ( )
849
+ localStorage
. email
= " [email protected] "
850
+ localStorage. offlineModeBeta = false
851
+ let internalAPI = InternalIterableAPI . initializeForTesting ( networkSession: networkSession, localStorage: localStorage)
852
+ wait ( for: [ expectation1] , timeout: testExpectationTimeout)
853
+
854
+ let expectation2 = expectation ( description: #function)
855
+ networkSession. requestCallback = { request in
856
+ if request. url!. absoluteString. contains ( " track " ) {
857
+ let processor = request. allHTTPHeaderFields ? [ JsonKey . Header. requestProcessor] !
858
+ XCTAssertEqual ( processor, Const . ProcessorTypeName. online)
859
+ expectation2. fulfill ( )
860
+ }
861
+ }
862
+ internalAPI. track ( " myEvent " )
863
+ wait ( for: [ expectation2] , timeout: testExpectationTimeout)
864
+ }
865
+
866
+
810
867
private func handleRequestWithSuccessAndFailure( requestGenerator: ( RequestHandlerProtocol ) -> Future < SendRequestValue , SendRequestError > ,
811
868
path: String ,
812
869
bodyDict: [ AnyHashable : Any ] ) throws {
0 commit comments