Skip to content

Commit

Permalink
Merge pull request #32 from allaboutapps/bug/stub-encoding
Browse files Browse the repository at this point in the history
Remove dependency from shared APIClient in StubResponse.
  • Loading branch information
wieweb authored Feb 28, 2023
2 parents 02299c6 + b906e48 commit dd60740
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/Fetch/Stub/Stub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct StubResponse: Stub {
/// - encodable: The object which will be encoded
/// - encoder: The `JSONEncoder` used to encode the `Encodable`
/// - delay: Simulated network delay
public init(statusCode: StatusCode, encodable: Encodable, encoder: ResourceEncoderProtocol = APIClient.shared.config.encoder, headers: HTTPHeaders = HTTPHeaders(), delay: TimeInterval) {
public init(statusCode: StatusCode, encodable: Encodable, encoder: ResourceEncoderProtocol = JSONEncoder(), headers: HTTPHeaders = HTTPHeaders(), delay: TimeInterval) {
self.init(statusCode: statusCode, data: try! encoder.encode(AnyEncodable(encodable)), headers: headers, delay: delay)
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/FetchTests/StubProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class StubProviderTests: XCTestCase {
}

// update stub
waitForExpectations(timeout: 5, handler: nil)
wait(for: [expectationA], timeout: 5)
let expectationB = self.expectation(description: "Fetch model b")
let stubB = StubResponse(statusCode: 200, encodable: ModelA(a: "b"), delay: 0.1)
APIClient.shared.stubProvider.register(stub: stubB, for: resource)
Expand All @@ -54,13 +54,13 @@ class StubProviderTests: XCTestCase {
}
}

waitForExpectations(timeout: 5, handler: nil)
wait(for: [expectationB], timeout: 5)
}

func testRemoveStub() {
let expectation = self.expectation(description: "Fetch model")

let resource = Resource<ModelA>(method: .get, path: "/test")
let resource = Resource<ModelA>(method: .get, path: "/testRemove")

let stub = StubResponse(statusCode: 200, encodable: ModelA(a: "a"), delay: 0.1)
APIClient.shared.stubProvider.register(stub: stub, for: resource)
Expand Down

0 comments on commit dd60740

Please sign in to comment.