-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodingDecodingTests.swift
More file actions
63 lines (50 loc) · 1.72 KB
/
EncodingDecodingTests.swift
File metadata and controls
63 lines (50 loc) · 1.72 KB
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
61
62
63
@testable import DataTransferObjects
import XCTest
final class EncodingDecodingTests: XCTestCase {
func testAppSettingsEncoding() throws {
let input = DTOv2.AppSettings(displayMode: .app)
let output = try JSONEncoder.telemetryEncoder.encode(input)
let expectedOutput = """
{
"displayMode": "app",
"showExampleData": false,
"startOfWeek": "sunday"
}
"""
.filter { !$0.isWhitespace }
XCTAssertEqual(expectedOutput, String(data: output, encoding: .utf8)!)
}
func testAppSettingsDecoding() throws {
let input = """
{
"displayMode": "website"
}
"""
.filter { !$0.isWhitespace }
let output = try JSONDecoder.telemetryDecoder.decode(DTOv2.AppSettings.self, from: input.data(using: .utf8)!)
XCTAssertEqual(output.displayMode, .website)
}
func testAppSettingsDecodingMore() throws {
let input = """
{
"displayMode": "website",
"showExampleData": false
}
"""
.filter { !$0.isWhitespace }
let output = try JSONDecoder.telemetryDecoder.decode(DTOv2.AppSettings.self, from: input.data(using: .utf8)!)
XCTAssertEqual(output.displayMode, .website)
}
func testAppSettingsDecodingMoreMore() throws {
let input = """
{
"displayMode": "website",
"showExampleData": false,
"colorScheme": "#f00 #0f0 #00f"
}
"""
.filter { !$0.isWhitespace }
let output = try JSONDecoder.telemetryDecoder.decode(DTOv2.AppSettings.self, from: input.data(using: .utf8)!)
XCTAssertEqual(output.displayMode, .website)
}
}