-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathRoomReactionDTOTests.swift
More file actions
121 lines (102 loc) · 3.72 KB
/
RoomReactionDTOTests.swift
File metadata and controls
121 lines (102 loc) · 3.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@testable import AblyChat
import Testing
enum RoomReactionDTOTests {
struct DataTests {
// MARK: - JSONDecodable
@Test
func initWithJSONValue_failsIfNotObject() {
#expect {
try RoomReactionDTO.Data(jsonValue: "hello")
} throws: { error in
isInternalErrorWithCase(error, .jsonValueDecodingError)
}
}
@Test
func initWithJSONValue_withNoTypeKey() {
#expect {
try RoomReactionDTO.Data(jsonValue: [:])
} throws: { error in
isInternalErrorWithCase(error, .jsonValueDecodingError)
}
}
@Test
func initWithJSONValue_withNoMetadataKey() throws {
#expect(try RoomReactionDTO.Data(jsonValue: ["name": "" /* arbitrary */ ]).metadata == nil)
}
@Test
func initWithJSONValue() throws {
let data = try RoomReactionDTO.Data(
jsonValue: [
"name": "someName",
"metadata": [
"someStringKey": "someStringValue",
"someNumberKey": 123,
],
]
)
#expect(data == .init(name: "someName", metadata: ["someStringKey": "someStringValue", "someNumberKey": 123]))
}
// MARK: - JSONCodable
@Test
func toJSONValue_withNilMetadata() {
// i.e. should create an empty object for metadata
#expect(RoomReactionDTO.Data(name: "" /* arbitrary */, metadata: nil).toJSONValue == .object(["name": "", "metadata": .object([:])]))
}
@Test
func toJSONValue() {
let data = RoomReactionDTO.Data(name: "someName", metadata: ["someStringKey": "someStringValue", "someNumberKey": 123])
#expect(data.toJSONValue == [
"name": "someName",
"metadata": [
"someStringKey": "someStringValue",
"someNumberKey": 123,
],
])
}
}
struct ExtrasTests {
// MARK: - JSONDecodable
@Test
func initWithJSONValue_failsIfNotObject() {
#expect {
try RoomReactionDTO.Extras(jsonValue: "hello")
} throws: { error in
isInternalErrorWithCase(error, .jsonValueDecodingError)
}
}
@Test
func initWithJSONValue_withNoHeadersKey() throws {
#expect(try RoomReactionDTO.Extras(jsonValue: [:]).headers == nil)
}
@Test
func initWithJSONValue() throws {
let data = try RoomReactionDTO.Extras(
jsonValue: [
"headers": [
"someStringKey": "someStringValue",
"someNumberKey": 123,
],
]
)
#expect(data == .init(headers: ["someStringKey": "someStringValue", "someNumberKey": 123]))
}
// MARK: - JSONCodable
@Test
func toJSONValue_withNilHeaders() {
// i.e. should create an empty object for headers
// swiftlint:disable:next empty_collection_literal
#expect(RoomReactionDTO.Extras(headers: nil).toJSONValue.objectValue?["headers"] == [:])
}
@Test
func toJSONValue() {
let data = RoomReactionDTO.Extras(headers: ["someStringKey": "someStringValue", "someNumberKey": 123])
#expect(data.toJSONValue == [
"headers": [
"someStringKey": "someStringValue",
"someNumberKey": 123,
],
"ephemeral": true,
])
}
}
}