-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix http mocking issues in unit tests
- Loading branch information
Showing
14 changed files
with
489 additions
and
482 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
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 |
---|---|---|
|
@@ -6,15 +6,12 @@ class AsyncAwaitTests: XCTestCase { | |
let testJsonMultiple = #"{ "f": { "key1": { "v": true, "i": "fakeId1", "p": [], "r": [] }, "key2": { "v": false, "i": "fakeId2", "p": [], "r": [{"o":1,"a":"Email","t":2,"c":"@example.com","v":true,"i":"9f21c24c"}] } } }"# | ||
let user = ConfigCatUser(identifier: "id", email: "[email protected]") | ||
|
||
override func setUp() { | ||
super.setUp() | ||
MockHTTP.reset() | ||
MockHTTP.enqueueResponse(response: Response(body: testJsonMultiple, statusCode: 200)) | ||
} | ||
|
||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) | ||
func testGetValue() async { | ||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), session: MockHTTP.session()) | ||
let engine = MockEngine() | ||
engine.enqueueResponse(response: Response(body: testJsonMultiple, statusCode: 200)) | ||
|
||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), httpEngine: engine) | ||
let value = await client.getValue(for: "key1", defaultValue: false) | ||
XCTAssertTrue(value) | ||
let value2 = await client.getValue(for: "key2", defaultValue: false, user: user) | ||
|
@@ -23,7 +20,10 @@ class AsyncAwaitTests: XCTestCase { | |
|
||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) | ||
func testGetVariationId() async { | ||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), session: MockHTTP.session()) | ||
let engine = MockEngine() | ||
engine.enqueueResponse(response: Response(body: testJsonMultiple, statusCode: 200)) | ||
|
||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), httpEngine: engine) | ||
let id = await client.getVariationId(for: "key1", defaultVariationId: "") | ||
XCTAssertEqual("fakeId1", id) | ||
let id2 = await client.getVariationId(for: "key2", defaultVariationId: "", user: user) | ||
|
@@ -32,53 +32,71 @@ class AsyncAwaitTests: XCTestCase { | |
|
||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) | ||
func testGetKeyValue() async { | ||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), session: MockHTTP.session()) | ||
let engine = MockEngine() | ||
engine.enqueueResponse(response: Response(body: testJsonMultiple, statusCode: 200)) | ||
|
||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), httpEngine: engine) | ||
let id = await client.getKeyAndValue(for: "fakeId1") | ||
XCTAssertEqual(true, id?.value as? Bool) | ||
XCTAssertEqual("key1", id?.key) | ||
} | ||
|
||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) | ||
func testGetAllKeys() async { | ||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), session: MockHTTP.session()) | ||
let engine = MockEngine() | ||
engine.enqueueResponse(response: Response(body: testJsonMultiple, statusCode: 200)) | ||
|
||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), httpEngine: engine) | ||
let keys = await client.getAllKeys() | ||
XCTAssertEqual(2, keys.count) | ||
} | ||
|
||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) | ||
func testGetAllValues() async { | ||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), session: MockHTTP.session()) | ||
let engine = MockEngine() | ||
engine.enqueueResponse(response: Response(body: testJsonMultiple, statusCode: 200)) | ||
|
||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), httpEngine: engine) | ||
let values = await client.getAllValues() | ||
XCTAssertEqual(2, values.count) | ||
} | ||
|
||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) | ||
func testRefresh() async { | ||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.manualPoll(), session: MockHTTP.session()) | ||
let engine = MockEngine() | ||
engine.enqueueResponse(response: Response(body: testJsonMultiple, statusCode: 200)) | ||
|
||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), httpEngine: engine) | ||
let result = await client.forceRefresh() | ||
let value = await client.getValue(for: "key2", defaultValue: true) | ||
XCTAssertTrue(result.success) | ||
XCTAssertFalse(value) | ||
XCTAssertEqual(1, MockHTTP.requests.count) | ||
XCTAssertEqual(1, engine.requests.count) | ||
} | ||
|
||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) | ||
func testRefreshWithoutResult() async { | ||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.manualPoll(), session: MockHTTP.session()) | ||
let engine = MockEngine() | ||
engine.enqueueResponse(response: Response(body: testJsonMultiple, statusCode: 200)) | ||
|
||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), httpEngine: engine) | ||
await client.forceRefresh() | ||
let value = await client.getValue(for: "key2", defaultValue: true) | ||
XCTAssertFalse(value) | ||
XCTAssertEqual(1, MockHTTP.requests.count) | ||
XCTAssertEqual(1, engine.requests.count) | ||
} | ||
|
||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) | ||
func testDetails() async { | ||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.manualPoll(), session: MockHTTP.session()) | ||
let engine = MockEngine() | ||
engine.enqueueResponse(response: Response(body: testJsonMultiple, statusCode: 200)) | ||
|
||
let client = ConfigCatClient(sdkKey: "test", pollingMode: PollingModes.autoPoll(), httpEngine: engine) | ||
await client.forceRefresh() | ||
let details = await client.getValueDetails(for: "key2", defaultValue: true) | ||
XCTAssertFalse(details.isDefaultValue) | ||
XCTAssertFalse(details.value) | ||
XCTAssertEqual(1, MockHTTP.requests.count) | ||
XCTAssertEqual(1, engine.requests.count) | ||
} | ||
#endif | ||
} |
Oops, something went wrong.