forked from RocketChat/Rocket.Chat.iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMockAPI.swift
More file actions
32 lines (25 loc) · 802 Bytes
/
Copy pathMockAPI.swift
File metadata and controls
32 lines (25 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// MockAPI.swift
// Rocket.ChatTests
//
// Created by Matheus Cardoso on 11/28/17.
// Copyright © 2017 Rocket.Chat. All rights reserved.
//
import SwiftyJSON
@testable import Rocket_Chat
class MockAPI: APIFetcher {
var nextResult: JSON?
var nextError: APIError?
@discardableResult
func fetch<R: APIRequest>(_ request: R, options: APIRequestOptionSet, sessionDelegate: URLSessionTaskDelegate?, completion: ((_ result: APIResponse<R.APIResourceType>) -> Void)?) -> URLSessionTask? {
if let nextResult = nextResult {
completion?(.resource(R.APIResourceType(raw: nextResult)))
}
if let nextError = nextError {
completion?(.error(nextError))
}
nextResult = nil
nextError = nil
return nil
}
}