diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index c667834a0..9c6adf8a3 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -16,6 +16,7 @@ jobs: - name: Build and test env: api_key: ${{secrets.E2E_API_KEY}} + server_api_key: ${{secrets.E2E_SERVER_API_KEY}} push_campaign_id: ${{secrets.E2E_PUSH_CAMPAIGN_ID}} push_template_id: ${{secrets.E2E_PUSH_TEMPLATE_ID}} in_app_campaign_id: ${{secrets.E2E_IN_APP_CAMPAIGN_ID}} diff --git a/tests/endpoint-tests/CI.swift.template b/tests/endpoint-tests/CI.swift.template index ab09c540a..575bfaab6 100644 --- a/tests/endpoint-tests/CI.swift.template +++ b/tests/endpoint-tests/CI.swift.template @@ -8,6 +8,7 @@ import Foundation /// Actual values will be injected by build step struct CI { static let apiKey = "{api_key}" + static let serverApiKey = "{server_api_key}" static let pushCampaignId = NSNumber(0) static let pushTemplateId = NSNumber(0) static let inAppCampaignId = NSNumber(0) diff --git a/tests/endpoint-tests/EndpointTests.swift b/tests/endpoint-tests/EndpointTests.swift index 5a8aa60f6..ffcf6fd9b 100644 --- a/tests/endpoint-tests/EndpointTests.swift +++ b/tests/endpoint-tests/EndpointTests.swift @@ -215,10 +215,13 @@ class EndpointTests: XCTestCase { ensureInAppMessages(api: api, email: email) api.inAppManager.scheduleSync().wait() - let count = api.inAppManager.getMessages().count - XCTAssert(count > 0) - - let message = api.inAppManager.getMessages()[0] + let messages = api.inAppManager.getMessages() + XCTAssert(messages.count > 0) + + guard let message = messages.first else { + XCTFail("No messages available") + return + } let startTime = Date() let endTime = startTime.addingTimeInterval(10.0) @@ -274,6 +277,7 @@ class EndpointTests: XCTestCase { } private static let apiKey = Environment.apiKey! + private static let serverApiKey = Environment.serverApiKey! private static let pushCampaignId = Environment.pushCampaignId! private static let pushTemplateId = Environment.pushTemplateId! private static let inAppCampaignId = Environment.inAppCampaignId! @@ -288,7 +292,7 @@ class EndpointTests: XCTestCase { } let expectation1 = expectation(for: predicate, evaluatedWith: nil, handler: nil) - wait(for: [expectation1], timeout: 60) + wait(for: [expectation1], timeout: 120) } private func clearAllInAppMessages(api: InternalIterableAPI) { diff --git a/tests/endpoint-tests/Environment.swift b/tests/endpoint-tests/Environment.swift index 3434aa380..f53a8f04a 100644 --- a/tests/endpoint-tests/Environment.swift +++ b/tests/endpoint-tests/Environment.swift @@ -10,6 +10,7 @@ import Foundation struct Environment { enum Key: String { case apiKey = "api_key" + case serverApiKey = "server_api_key" case pushCampaignId = "push_campaign_id" case pushTemplateId = "push_template_id" case inAppCampaignId = "in_app_campaign_id" @@ -19,6 +20,10 @@ struct Environment { static var apiKey: String? { getFromEnv(key: .apiKey) ?? CI.apiKey } + + static var serverApiKey: String? { + getFromEnv(key: .serverApiKey) ?? CI.serverApiKey + } static var pushCampaignId: NSNumber? { getNSNumberFromEnv(key: .pushCampaignId) ?? CI.pushCampaignId diff --git a/tests/endpoint-tests/IterableAPISupport.swift b/tests/endpoint-tests/IterableAPISupport.swift index 7630c59dd..2d52b44fb 100644 --- a/tests/endpoint-tests/IterableAPISupport.swift +++ b/tests/endpoint-tests/IterableAPISupport.swift @@ -12,7 +12,7 @@ struct IterableAPISupport { } var urlRequest = URLRequest(url: url) - urlRequest.setValue(apiKey, forHTTPHeaderField: JsonKey.Header.apiKey) + urlRequest.setValue(serverApiKey, forHTTPHeaderField: JsonKey.Header.apiKey) return RequestSender.sendRequest(urlRequest, usingSession: urlSession) } @@ -44,6 +44,7 @@ struct IterableAPISupport { } private static let apiKey = Environment.apiKey! + private static let serverApiKey = Environment.serverApiKey! private static func createPostRequest(iterablePostRequest: PostRequest) -> URLRequest? { IterableRequestUtil.createPostRequest(forApiEndPoint: Path.apiEndpoint, @@ -57,7 +58,7 @@ struct IterableAPISupport { [JsonKey.contentType: JsonValue.applicationJson, JsonKey.Header.sdkPlatform: JsonValue.iOS, JsonKey.Header.sdkVersion: IterableAPI.sdkVersion, - JsonKey.Header.apiKey: apiKey] + JsonKey.Header.apiKey: serverApiKey] } private static var urlSession: URLSession = { diff --git a/tests/endpoint-tests/scripts/env_vars.sh.sample b/tests/endpoint-tests/scripts/env_vars.sh.sample index 4bb20b8de..aa6cd0455 100755 --- a/tests/endpoint-tests/scripts/env_vars.sh.sample +++ b/tests/endpoint-tests/scripts/env_vars.sh.sample @@ -1,6 +1,7 @@ #!/bin/bash export api_key=the_api_key +export server_api_key=the_server_api_key export push_campaign_id=0 export push_template_id=0 export in_app_campaign_id=0 diff --git a/tests/endpoint-tests/scripts/run_test.sh b/tests/endpoint-tests/scripts/run_test.sh index 0b7a6ce79..5556f767d 100755 --- a/tests/endpoint-tests/scripts/run_test.sh +++ b/tests/endpoint-tests/scripts/run_test.sh @@ -14,6 +14,7 @@ fi echo Generating CI.swift sed -e "s/\(apiKey = \).*$/\1\"$api_key\"/" \ +-e "s/\(serverApiKey = \).*$/\1\"$server_api_key\"/" \ -e "s/\(pushCampaignId = \).*$/\1\NSNumber($push_campaign_id)/" \ -e "s/\(pushTemplateId = \).*$/\1\NSNumber($push_template_id)/" \ -e "s/\(inAppCampaignId = \).*$/\1\NSNumber($in_app_campaign_id)/" \