Skip to content

Commit

Permalink
Merge pull request #847 from Iterable/chore/comment-outdated-tests-logic
Browse files Browse the repository at this point in the history
🤫 Commenting out these tests logic to silence warnings.
  • Loading branch information
joaodordio authored Oct 22, 2024
2 parents 4e08441 + a844c78 commit 885d255
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 93 deletions.
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 885d255

Please sign in to comment.