-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent registering device with empty identifier existing BQ tas…
…ks (#392)
- Loading branch information
1 parent
b0f309f
commit 867619f
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,8 @@ extension Result { | |
default: return nil | ||
} | ||
} | ||
|
||
var isSuccess: Bool { | ||
success != nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@testable import CioInternalCommon | ||
import Foundation | ||
import SharedTests | ||
import XCTest | ||
|
||
class QueueRunnerTest: UnitTest { | ||
private var runner: CioQueueRunner! | ||
|
||
private let httpClientMock = HttpClientMock() | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
runner = CioQueueRunner(jsonAdapter: jsonAdapter, logger: log, httpClient: httpClientMock, hooksManager: diGraph.hooksManager, sdkConfig: sdkConfig) | ||
} | ||
|
||
// MARK: registerPushToken | ||
|
||
func test_registerPushToken_givenIdentifierEmpty_expectHttpRequestNotMade_expectBQDeletesTask() { | ||
let givenRegisterTokenTask = RegisterPushNotificationQueueTaskData(profileIdentifier: " ", attributesJsonString: nil) | ||
|
||
let givenQueueTask = QueueTask(storageId: .random, type: QueueTaskType.registerPushToken.rawValue, data: jsonAdapter.toJson(givenRegisterTokenTask)!, runResults: QueueTaskRunResults(totalRuns: 0)) | ||
|
||
let expectToCompleteRunning = expectation(description: "expect to complete running") | ||
var actualResult: Result<Void, HttpRequestError>! | ||
runner.runTask(givenQueueTask) { result in | ||
actualResult = result | ||
expectToCompleteRunning.fulfill() | ||
} | ||
|
||
waitForExpectations() | ||
|
||
XCTAssertTrue(actualResult.isSuccess) // the BQ will delete the task if http was successful | ||
XCTAssertFalse(httpClientMock.mockCalled) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@testable import CioInternalCommon | ||
import Foundation | ||
import SharedTests | ||
import XCTest | ||
|
||
class ResultExtensionsTest: UnitTest { | ||
// MARK: isSuccess | ||
|
||
func test_givenSuccess_expectIsSuccessTrue() { | ||
let result: Result<String, Error> = .success("hello") | ||
|
||
XCTAssertTrue(result.isSuccess) | ||
} | ||
|
||
func test_givenFailure_expectIsSuccessFalse() { | ||
let result: Result<String, Error> = .failure(HttpRequestError.cancelled) | ||
|
||
XCTAssertFalse(result.isSuccess) | ||
} | ||
} |