From 94af22f9818e379f9c3e012c44cde4fbc9d5929e Mon Sep 17 00:00:00 2001 From: Lukas Schmidt Date: Tue, 31 Oct 2023 14:20:53 +0100 Subject: [PATCH] Adds back old mock methods --- .../NetworkServices/NetworkServiceMock.swift | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Source/NetworkServices/NetworkServiceMock.swift b/Source/NetworkServices/NetworkServiceMock.swift index 46f57e2..ada0660 100644 --- a/Source/NetworkServices/NetworkServiceMock.swift +++ b/Source/NetworkServices/NetworkServiceMock.swift @@ -166,6 +166,40 @@ public final actor NetworkServiceMock: NetworkService { return .failure(.serverError(response: nil, data: nil)) } } + + public func schedule(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(success: T) { + schedule(result: .success((success, HTTPURLResponse()))) + } + + public func schedule(success: (T, HTTPURLResponse)) { + schedule(result: .success(success)) + } + + public func schedule(failure: NetworkError) { + responses.append(.failure(failure)) + } } fileprivate extension Result {