Skip to content

Commit

Permalink
Merge branch 'master' into notification_status
Browse files Browse the repository at this point in the history
  • Loading branch information
evantk91 authored Dec 17, 2024
2 parents 7fe2e44 + e5de2b7 commit 855d049
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 100 deletions.
6 changes: 3 additions & 3 deletions Iterable-iOS-AppExtensions.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Pod::Spec.new do |s|
App extensions for rich push notifications with Iterable's iOS SDK
DESC

s.homepage = "https://github.com/Iterable/swift-sdk.git"
s.homepage = "https://github.com/Iterable/iterable-swift-sdk.git"
s.license = "MIT"
s.author = { "Jay Kim" => "[email protected]" }

s.platform = :ios, "10.0"
s.source = { :git => "https://github.com/Iterable/swift-sdk.git", :tag => s.version }
s.platform = :ios, "12.0"
s.source = { :git => "https://github.com/Iterable/iterable-swift-sdk.git", :tag => s.version }
s.source_files = "notification-extension/*.{h,m,swift}"

s.pod_target_xcconfig = {
Expand Down
4 changes: 2 additions & 2 deletions Iterable-iOS-SDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Pod::Spec.new do |s|
Iterable's iOS SDK integrating utility and the Iterable API
DESC

s.homepage = "https://github.com/Iterable/swift-sdk.git"
s.homepage = "https://github.com/Iterable/iterable-swift-sdk.git"
s.license = "MIT"
s.author = { "Jay Kim" => "[email protected]" }

s.platform = :ios, "12.0"
s.source = { :git => "https://github.com/Iterable/swift-sdk.git", :tag => s.version }
s.source = { :git => "https://github.com/Iterable/iterable-swift-sdk.git", :tag => s.version }
s.source_files = "swift-sdk/**/*.{h,m,swift}"
s.exclude_files = "swift-sdk/swiftui/**"

Expand Down
4 changes: 2 additions & 2 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ platform :ios do
)

github_release = set_github_release(
repository_name: "Iterable/swift-sdk",
repository_name: "Iterable/iterable-swift-sdk",
api_token: github_token,
name: "#{version}",
tag_name: "#{version}",
Expand Down Expand Up @@ -135,4 +135,4 @@ platform :ios do
slack_url: slack_webhook,
)
end
end
end
5 changes: 5 additions & 0 deletions swift-sdk/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ enum Const {
static let location = "Location"
static let setCookie = "Set-Cookie"
}

enum RemoteNotification {
static let aps = "aps"
static let contentAvailable = "content-available"
}
}

enum JsonKey {
Expand Down
9 changes: 9 additions & 0 deletions swift-sdk/Internal/InternalIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,16 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
guard let launchOptions = launchOptions else {
return
}

if let remoteNotificationPayload = launchOptions[UIApplication.LaunchOptionsKey.remoteNotification] as? [AnyHashable: Any] {

if let aps = remoteNotificationPayload[Const.RemoteNotification.aps] as? [String: Any],
let contentAvailable = aps[Const.RemoteNotification.contentAvailable] as? Int,
contentAvailable == 1 {
ITBInfo("Received push notification with wakey content-available flag")
return
}

if let _ = IterableUtil.rootViewController {
// we are ready
IterableAppIntegration.implementation?.performDefaultNotificationAction(remoteNotificationPayload)
Expand Down
48 changes: 24 additions & 24 deletions tests/unit-tests/AuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -562,30 +562,30 @@ class AuthTests: XCTestCase {
func testAuthTokenRefreshRetryOnlyOnce() throws {
throw XCTSkip("skipping this test - auth token retries should occur more than once")

let condition1 = expectation(description: "\(#function) - callback not called correctly in some form")
condition1.expectedFulfillmentCount = 2

let authDelegate = createAuthDelegate({
condition1.fulfill()
return AuthTests.authToken
})

let config = IterableConfig()
config.authDelegate = authDelegate

let mockNetworkSession = MockNetworkSession(statusCode: 401,
json: [JsonKey.Response.iterableCode: JsonValue.Code.invalidJwtPayload])

let internalAPI = InternalIterableAPI.initializeForTesting(config: config,
networkSession: mockNetworkSession)

internalAPI.email = AuthTests.email

// two calls here to trigger the retry more than once
internalAPI.track("event")
internalAPI.track("event")

wait(for: [condition1], timeout: testExpectationTimeout)
// let condition1 = expectation(description: "\(#function) - callback not called correctly in some form")
// condition1.expectedFulfillmentCount = 2
//
// let authDelegate = createAuthDelegate({
// condition1.fulfill()
// return AuthTests.authToken
// })
//
// let config = IterableConfig()
// config.authDelegate = authDelegate
//
// let mockNetworkSession = MockNetworkSession(statusCode: 401,
// json: [JsonKey.Response.iterableCode: JsonValue.Code.invalidJwtPayload])
//
// let internalAPI = InternalIterableAPI.initializeForTesting(config: config,
// networkSession: mockNetworkSession)
//
// internalAPI.email = AuthTests.email
//
// // two calls here to trigger the retry more than once
// internalAPI.track("event")
// internalAPI.track("event")
//
// wait(for: [condition1], timeout: testExpectationTimeout)
}

func testPriorAuthFailedRetryPrevention() {
Expand Down
48 changes: 24 additions & 24 deletions tests/unit-tests/EmbeddedManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ final class EmbeddedManagerTests: XCTestCase {
func testManagerSingleDelegateUpdated() throws {
throw XCTSkip("skipping this test - manager logic updated, needs to be revisited")

let condition1 = expectation(description: #function)

let mockApiClient = MockApiClient()

let manager = IterableEmbeddedManager(apiClient: mockApiClient,
urlDelegate: nil,
customActionDelegate: nil,
urlOpener: MockUrlOpener(),
allowedProtocols: [],
enableEmbeddedMessaging: true)

let view1 = ViewWithUpdateDelegate(
onMessagesUpdatedCallback: {
condition1.fulfill()
},
onEmbeddedMessagingDisabledCallback: nil
)

manager.addUpdateListener(view1)

mockApiClient.haveNewEmbeddedMessages()
manager.syncMessages {}

wait(for: [condition1], timeout: 2)
// let condition1 = expectation(description: #function)
//
// let mockApiClient = MockApiClient()
//
// let manager = IterableEmbeddedManager(apiClient: mockApiClient,
// urlDelegate: nil,
// customActionDelegate: nil,
// urlOpener: MockUrlOpener(),
// allowedProtocols: [],
// enableEmbeddedMessaging: true)
//
// let view1 = ViewWithUpdateDelegate(
// onMessagesUpdatedCallback: {
// condition1.fulfill()
// },
// onEmbeddedMessagingDisabledCallback: nil
// )
//
// manager.addUpdateListener(view1)
//
// mockApiClient.haveNewEmbeddedMessages()
// manager.syncMessages {}
//
// wait(for: [condition1], timeout: 2)
}

// getMessages
Expand Down
90 changes: 45 additions & 45 deletions tests/unit-tests/IterableAPIResponseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,51 +102,51 @@ class IterableAPIResponseTests: XCTestCase {

func testRetryOnInvalidJwtPayload() throws {
throw XCTSkip("skipping this test - retry logic updated, needs to be revisited")
let xpectation = expectation(description: "retry on 401 with invalidJWTPayload")

// Mock the dependencies and requestProvider for your test
let authManager = MockAuthManager()

let networkErrorSession = MockNetworkSession() { _ in
MockNetworkSession.MockResponse(statusCode: 401,
data: ["code":"InvalidJwtPayload"].toJsonData(),
delay: 1)
}

let networkSuccessSession = MockNetworkSession() { _ in
MockNetworkSession.MockResponse(statusCode: 200,
data: ["msg": "success"].toJsonData(),
delay: 1)
}

let urlErrorRequest = createApiClient(networkSession: networkErrorSession).convertToURLRequest(iterableRequest: IterableRequest.post(PostRequest(path: "", args: nil, body: [:])))!


let urlSuccessRequest = createApiClient(networkSession: networkSuccessSession).convertToURLRequest(iterableRequest: IterableRequest.post(PostRequest(path: "", args: nil, body: [:])))!

let requestProvider: () -> Pending<SendRequestValue, SendRequestError> = {
if authManager.retryWasRequested {
return RequestSender.sendRequest(urlSuccessRequest, usingSession: networkSuccessSession)
}
return RequestSender.sendRequest(urlErrorRequest, usingSession: networkErrorSession)
}

let result = RequestProcessorUtil.sendRequest(
requestProvider: requestProvider,
authManager: authManager,
requestIdentifier: "TestIdentifier"
)

result.onSuccess { value in
xpectation.fulfill()
XCTAssert(true)
}.onError { error in
if authManager.retryWasRequested {
xpectation.fulfill()
}
}

waitForExpectations(timeout: testExpectationTimeout)
// let xpectation = expectation(description: "retry on 401 with invalidJWTPayload")
//
// // Mock the dependencies and requestProvider for your test
// let authManager = MockAuthManager()
//
// let networkErrorSession = MockNetworkSession() { _ in
// MockNetworkSession.MockResponse(statusCode: 401,
// data: ["code":"InvalidJwtPayload"].toJsonData(),
// delay: 1)
// }
//
// let networkSuccessSession = MockNetworkSession() { _ in
// MockNetworkSession.MockResponse(statusCode: 200,
// data: ["msg": "success"].toJsonData(),
// delay: 1)
// }
//
// let urlErrorRequest = createApiClient(networkSession: networkErrorSession).convertToURLRequest(iterableRequest: IterableRequest.post(PostRequest(path: "", args: nil, body: [:])))!
//
//
// let urlSuccessRequest = createApiClient(networkSession: networkSuccessSession).convertToURLRequest(iterableRequest: IterableRequest.post(PostRequest(path: "", args: nil, body: [:])))!
//
// let requestProvider: () -> Pending<SendRequestValue, SendRequestError> = {
// if authManager.retryWasRequested {
// return RequestSender.sendRequest(urlSuccessRequest, usingSession: networkSuccessSession)
// }
// return RequestSender.sendRequest(urlErrorRequest, usingSession: networkErrorSession)
// }
//
// let result = RequestProcessorUtil.sendRequest(
// requestProvider: requestProvider,
// authManager: authManager,
// requestIdentifier: "TestIdentifier"
// )
//
// result.onSuccess { value in
// xpectation.fulfill()
// XCTAssert(true)
// }.onError { error in
// if authManager.retryWasRequested {
// xpectation.fulfill()
// }
// }
//
// waitForExpectations(timeout: testExpectationTimeout)
}

func testResponseCode401() { // 401 = unauthorized
Expand Down

0 comments on commit 855d049

Please sign in to comment.