From ead8341e75eb880b44b621e7c77fb7ff347afef2 Mon Sep 17 00:00:00 2001 From: Nicky Bondarenko Date: Wed, 10 Jan 2024 16:25:47 +0100 Subject: [PATCH] rename client to offline for clarity --- .../RemoteConfidenceClient.swift | 8 ++++---- .../ConfidenceIntegrationTest.swift | 2 +- .../FlagApplierWithRetriesTest.swift | 16 ++++++++-------- .../Helpers/HttpClientMock.swift | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Sources/ConfidenceProvider/ConfidenceClient/RemoteConfidenceClient.swift b/Sources/ConfidenceProvider/ConfidenceClient/RemoteConfidenceClient.swift index 05441db8..3ff9f361 100644 --- a/Sources/ConfidenceProvider/ConfidenceClient/RemoteConfidenceClient.swift +++ b/Sources/ConfidenceProvider/ConfidenceClient/RemoteConfidenceClient.swift @@ -186,10 +186,10 @@ public enum ConfidenceClientCredentials { } } -public enum ConfidenceRegion: String { - case global = "global" - case europe = "eu" - case usa = "us" +public enum ConfidenceRegion { + case global + case europe + case usa } struct Sdk: Codable { diff --git a/Tests/ConfidenceProviderTests/ConfidenceIntegrationTest.swift b/Tests/ConfidenceProviderTests/ConfidenceIntegrationTest.swift index 9530afd7..812f2810 100644 --- a/Tests/ConfidenceProviderTests/ConfidenceIntegrationTest.swift +++ b/Tests/ConfidenceProviderTests/ConfidenceIntegrationTest.swift @@ -5,7 +5,7 @@ import XCTest @testable import ConfidenceProvider class ConfidenceIntegrationTests: XCTestCase { - let clientToken: String? = "5GdaBq79NMVrMGXRVhN9g1pBKtG9cNK8" + let clientToken: String? = ProcessInfo.processInfo.environment["CLIENT_TOKEN"] let resolveFlag = setResolveFlag() let storage: Storage = StorageMock() diff --git a/Tests/ConfidenceProviderTests/FlagApplierWithRetriesTest.swift b/Tests/ConfidenceProviderTests/FlagApplierWithRetriesTest.swift index 820da2da..3274a6ab 100644 --- a/Tests/ConfidenceProviderTests/FlagApplierWithRetriesTest.swift +++ b/Tests/ConfidenceProviderTests/FlagApplierWithRetriesTest.swift @@ -197,7 +197,7 @@ class FlagApplierWithRetriesTest: XCTestCase { func testApply_multipleApplyCalls_batchTriggered() async throws { // Given flag applier with http client that is offline - let httpClient = HttpClientMock(testMode: .error) + let httpClient = HttpClientMock(testMode: .offline) let networkExpectation = self.expectation(description: "Waiting for batch trigger") networkExpectation.expectedFulfillmentCount = 2 httpClient.expectation = networkExpectation @@ -237,7 +237,7 @@ class FlagApplierWithRetriesTest: XCTestCase { func testApply_multipleApplyCalls_sentSet() async throws { // Given flag applier with http client that is offline let cacheDataInteractor = CacheDataInteractor(cacheData: .empty()) - let offlineClient = HttpClientMock(testMode: .error) + let offlineClient = HttpClientMock(testMode: .offline) let networkExpectation = self.expectation(description: "Waiting for network call to complete") networkExpectation.expectedFulfillmentCount = 2 offlineClient.expectation = networkExpectation @@ -336,7 +336,7 @@ class FlagApplierWithRetriesTest: XCTestCase { func testApply_previoslyStoredData_doesNotCleanAfterSendingFailure() throws { // Given offline http client // And storage that has previosly stored data (100 records, same token) - let offlineClient = HttpClientMock(testMode: .error) + let offlineClient = HttpClientMock(testMode: .offline) let prefilledStorage = StorageMock() let prefilledCache = try CacheDataUtility.prefilledCacheData(applyEventCount: 100) try prefilledStorage.save(data: prefilledCache) @@ -359,7 +359,7 @@ class FlagApplierWithRetriesTest: XCTestCase { func testApplyOffline_storesOnDisk() async throws { // Given offline http client and flag applier - let offlineClient = HttpClientMock(testMode: .error) + let offlineClient = HttpClientMock(testMode: .offline) let applier = FlagApplierWithRetries( httpClient: offlineClient, storage: storage, options: options, metadata: metadata, triggerBatch: false ) @@ -388,7 +388,7 @@ class FlagApplierWithRetriesTest: XCTestCase { func testApplyOffline_storesOnDisk_multipleTokens() async throws { // Given offline http client and flag applier - let offlineClient = HttpClientMock(testMode: .error) + let offlineClient = HttpClientMock(testMode: .offline) let applier = FlagApplierWithRetries( httpClient: offlineClient, storage: storage, options: options, metadata: metadata, triggerBatch: false ) @@ -416,7 +416,7 @@ class FlagApplierWithRetriesTest: XCTestCase { func testApplyOffline_previoslyStoredData_storesOnDisk() async throws { // Given flag applier set up with offline http client // And storage that has previously stored 1 record - let offlineClient = HttpClientMock(testMode: .error) + let offlineClient = HttpClientMock(testMode: .offline) let data = CacheData(resolveToken: "token0", flagName: "flag1", applyTime: Date(timeIntervalSince1970: 1000)) let prefilledStorage = try StorageMock(data: data) @@ -453,7 +453,7 @@ class FlagApplierWithRetriesTest: XCTestCase { func testApplyOffline_previoslyStoredData_100records() async throws { // Given flag applier set up with offline http client // And storage that has previously stored 100 records with different tokens - let offlineClient = HttpClientMock(testMode: .error) + let offlineClient = HttpClientMock(testMode: .offline) let prefilledStorage = StorageMock() let prefilledCache = try CacheDataUtility.prefilledCacheData(resolveEventCount: 100) try prefilledStorage.save(data: prefilledCache) @@ -477,7 +477,7 @@ class FlagApplierWithRetriesTest: XCTestCase { func testApplyOffline_100applyCalls_sameToken() async throws { // Given flag applier set up with offline http client // And storage that has previously stored 100 records with same token - let offlineClient = HttpClientMock(testMode: .error) + let offlineClient = HttpClientMock(testMode: .offline) let networkExpectation = self.expectation(description: "Waiting for networkRequest to be completed") // Since we don't fail other requests when one request is failing diff --git a/Tests/ConfidenceProviderTests/Helpers/HttpClientMock.swift b/Tests/ConfidenceProviderTests/Helpers/HttpClientMock.swift index a9ccb5c8..6d325e6c 100644 --- a/Tests/ConfidenceProviderTests/Helpers/HttpClientMock.swift +++ b/Tests/ConfidenceProviderTests/Helpers/HttpClientMock.swift @@ -12,7 +12,7 @@ final class HttpClientMock: HttpClient { enum TestMode { case success case failFirstChunk - case error + case offline } init(testMode: TestMode = .success) { @@ -63,7 +63,7 @@ final class HttpClientMock: HttpClient { } else { return HttpClientResponse(response: HTTPURLResponse()) } - case .error: + case .offline: throw HttpClientError.invalidResponse } }