@@ -714,6 +714,99 @@ class RequestHandlerTests: XCTestCase {
714
714
wait ( for: [ expectation1] , timeout: testExpectationTimeout)
715
715
}
716
716
717
+ func testNoRemoteConfigurationUsesOnline( ) throws {
718
+ let expectation1 = expectation ( description: " getRemoteConfiguration is called " )
719
+ var mapper = [ String: Data? ] ( )
720
+ mapper [ " getRemoteConfiguration " ] = nil
721
+ let networkSession = MockNetworkSession ( statusCode: 200 , urlPatternDataMapping: mapper)
722
+ networkSession. requestCallback = { request in
723
+ if request. url!. absoluteString. contains ( Const . Path. getRemoteConfiguration) {
724
+ expectation1. fulfill ( )
725
+ }
726
+ }
727
+ let localStorage = MockLocalStorage ( )
728
+ localStorage
. email
= " [email protected] "
729
+ let internalAPI = InternalIterableAPI . initializeForTesting ( networkSession: networkSession, localStorage: localStorage)
730
+ wait ( for: [ expectation1] , timeout: testExpectationTimeout)
731
+
732
+ let expectation2 = expectation ( description: #function)
733
+ networkSession. requestCallback = { request in
734
+ if request. url!. absoluteString. contains ( " track " ) {
735
+ let processor = request. allHTTPHeaderFields ? [ JsonKey . Header. requestProcessor] !
736
+ XCTAssertEqual ( processor, Const . ProcessorTypeName. online)
737
+ expectation2. fulfill ( )
738
+ }
739
+ }
740
+ internalAPI. track ( " myEvent " )
741
+ wait ( for: [ expectation2] , timeout: testExpectationTimeout)
742
+ }
743
+
744
+ func testDefaultUsesOnlineMode( ) throws {
745
+ let expectation1 = expectation ( description: " getRemoteConfiguration is called " )
746
+ let remoteConfigurationData = """
747
+ {
748
+ " offlineMode " : false,
749
+ " offlineModeBeta " : false
750
+ }
751
+ """ . data ( using: . utf8) !
752
+ var mapper = [ String: Data? ] ( )
753
+ mapper [ " getRemoteConfiguration " ] = remoteConfigurationData
754
+ let networkSession = MockNetworkSession ( statusCode: 200 , urlPatternDataMapping: mapper)
755
+ networkSession. requestCallback = { request in
756
+ if request. url!. absoluteString. contains ( Const . Path. getRemoteConfiguration) {
757
+ expectation1. fulfill ( )
758
+ }
759
+ }
760
+ let localStorage = MockLocalStorage ( )
761
+ localStorage
. email
= " [email protected] "
762
+ let internalAPI = InternalIterableAPI . initializeForTesting ( networkSession: networkSession, localStorage: localStorage)
763
+ wait ( for: [ expectation1] , timeout: testExpectationTimeout)
764
+
765
+ let expectation2 = expectation ( description: #function)
766
+ networkSession. requestCallback = { request in
767
+ if request. url!. absoluteString. contains ( " track " ) {
768
+ let processor = request. allHTTPHeaderFields ? [ JsonKey . Header. requestProcessor] !
769
+ XCTAssertEqual ( processor, Const . ProcessorTypeName. online)
770
+ expectation2. fulfill ( )
771
+ }
772
+ }
773
+ internalAPI. track ( " myEvent " )
774
+ wait ( for: [ expectation2] , timeout: testExpectationTimeout)
775
+ }
776
+
777
+ func testFeatureFlagTurnOnOfflineMode( ) throws {
778
+ let expectation1 = expectation ( description: " getRemoteConfiguration is called " )
779
+ let remoteConfigurationData = """
780
+ {
781
+ " offlineMode " : false,
782
+ " offlineModeBeta " : true
783
+ }
784
+ """ . data ( using: . utf8) !
785
+ var mapper = [ String: Data? ] ( )
786
+ mapper [ " getRemoteConfiguration " ] = remoteConfigurationData
787
+ let networkSession = MockNetworkSession ( statusCode: 200 , urlPatternDataMapping: mapper)
788
+ networkSession. requestCallback = { request in
789
+ if request. url!. absoluteString. contains ( Const . Path. getRemoteConfiguration) {
790
+ expectation1. fulfill ( )
791
+ }
792
+ }
793
+ let localStorage = MockLocalStorage ( )
794
+ localStorage
. email
= " [email protected] "
795
+ let internalAPI = InternalIterableAPI . initializeForTesting ( networkSession: networkSession, localStorage: localStorage)
796
+ wait ( for: [ expectation1] , timeout: testExpectationTimeout)
797
+
798
+ let expectation2 = expectation ( description: #function)
799
+ networkSession. requestCallback = { request in
800
+ if request. url!. absoluteString. contains ( " track " ) {
801
+ let processor = request. allHTTPHeaderFields ? [ JsonKey . Header. requestProcessor] !
802
+ XCTAssertEqual ( processor, Const . ProcessorTypeName. offline)
803
+ expectation2. fulfill ( )
804
+ }
805
+ }
806
+ internalAPI. track ( " myEvent " )
807
+ wait ( for: [ expectation2] , timeout: testExpectationTimeout)
808
+ }
809
+
717
810
private func handleRequestWithSuccessAndFailure( requestGenerator: ( RequestHandlerProtocol ) -> Future < SendRequestValue , SendRequestError > ,
718
811
path: String ,
719
812
bodyDict: [ AnyHashable : Any ] ) throws {
0 commit comments