Skip to content

Commit

Permalink
Adds back old mock methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsprint09 committed Oct 31, 2023
1 parent e1f84a3 commit 94af22f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Source/NetworkServices/NetworkServiceMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,40 @@ public final actor NetworkServiceMock: NetworkService {
return .failure(.serverError(response: nil, data: nil))
}
}

public func schedule<T: Encodable>(result: Result<(T, HTTPURLResponse), NetworkError>) {
let scheduled: Result<(Data, HTTPURLResponse), NetworkError>
switch result {
case .failure(let error):
scheduled = .failure(error)
case .success((let object, let httpUrlResponse)):
guard let data = try? encoder.encode(object) else {
fatalError("Not able to encode object")
}
scheduled = .success((data, httpUrlResponse))
}
responses.append(scheduled)
}

public func schedule(success: Void) {
schedule(result: .success(("", HTTPURLResponse())))
}

public func schedule(success: (Void, HTTPURLResponse)) {
schedule(result: .success(("", success.1)))
}

public func schedule<T: Encodable>(success: T) {
schedule(result: .success((success, HTTPURLResponse())))
}

public func schedule<T: Encodable>(success: (T, HTTPURLResponse)) {
schedule(result: .success(success))
}

public func schedule(failure: NetworkError) {
responses.append(.failure(failure))
}
}

fileprivate extension Result {
Expand Down

0 comments on commit 94af22f

Please sign in to comment.