Newer
Older
import CustomDump
import XCTest
@testable import XXClient
final class NotificationReportTests: XCTestCase {
func testCoding() throws {
let forMe = true
let type = NotificationReport.ReportType.default
let sourceB64 = "dGVzdGVyMTIzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
let jsonString = """
{
"ForMe": true,
"Type": "\(type.rawValue)",
"Source": "\(sourceB64)"
}
"""
let jsonData = jsonString.data(using: .utf8)!
let model = try NotificationReport.decode(jsonData)
XCTAssertNoDifference(model, NotificationReport(
forMe: forMe,
type: type,
source: Data(base64Encoded: sourceB64)!
))
let encodedModel = try model.encode()
let decodedModel = try NotificationReport.decode(encodedModel)
XCTAssertNoDifference(decodedModel, model)
}
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
func testCodingArray() throws {
let source1B64 = "dGVzdGVyMTIzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
let source2B64 = "ciI1cpyUUY/UPaVeMy1zBFWbZRgiZSXhY+cVoM+fCxwD"
let jsonString = """
[
{
"ForMe": true,
"Type": "\(NotificationReport.ReportType.default.rawValue)",
"Source": "\(source1B64)"
},
{
"ForMe": false,
"Type": "\(NotificationReport.ReportType.request.rawValue)",
"Source": "\(source2B64)"
},
]
"""
let jsonData = jsonString.data(using: .utf8)!
let models = try [NotificationReport].decode(jsonData)
XCTAssertNoDifference(models, [
NotificationReport(
forMe: true,
type: .default,
source: Data(base64Encoded: source1B64)!
),
NotificationReport(
forMe: false,
type: .request,
source: Data(base64Encoded: source2B64)!
)
])
let encodedModels = try models.encode()
let decodedModels = try [NotificationReport].decode(encodedModels)
XCTAssertNoDifference(decodedModels, models)
}