forked from pointfreeco/swift-url-routing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathURLRoutingClientTests.swift
60 lines (58 loc) · 2.16 KB
/
URLRoutingClientTests.swift
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import Parsing
import URLRouting
import XCTest
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
class URLRoutingClientTests: XCTestCase {
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
func testJSONDecoder_noDecoder() async throws {
struct Response: Equatable, Decodable {
let decodableValue: String
}
enum AppRoute {
case test
}
let sut = URLRoutingClient<AppRoute>(request: { _ in
("{\"decodableValue\":\"result\"}".data(using: .utf8)!, URLResponse())
})
let response = try await sut.decodedResponse(for: .test, as: Response.self)
XCTAssertEqual(response.value, .init(decodableValue: "result"))
}
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
func testJSONDecoder_customDecoder() async throws {
struct Response: Equatable, Decodable {
let decodableValue: String
}
enum AppRoute {
case test
}
let customDecoder = JSONDecoder()
customDecoder.keyDecodingStrategy = .convertFromSnakeCase
let sut = URLRoutingClient<AppRoute>(
request: { _ in
("{\"decodable_value\":\"result\"}".data(using: .utf8)!, URLResponse())
}, decoder: customDecoder)
let response = try await sut.decodedResponse(for: .test, as: Response.self)
XCTAssertEqual(response.value, .init(decodableValue: "result"))
}
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
func testJSONDecoder_customDecoderForRequest() async throws {
struct Response: Equatable, Decodable {
let decodableValue: String
}
enum AppRoute {
case test
}
let customDecoder = JSONDecoder()
customDecoder.keyDecodingStrategy = .convertFromSnakeCase
let sut = URLRoutingClient<AppRoute>(
request: { _ in
("{\"decodableValue\":\"result\"}".data(using: .utf8)!, URLResponse())
}, decoder: customDecoder)
let response = try await sut.decodedResponse(for: .test, as: Response.self, decoder: .init())
XCTAssertEqual(response.value, .init(decodableValue: "result"))
}
#endif
}