-
Notifications
You must be signed in to change notification settings - Fork 27
/
ReadingListClientRecordTestCase.swift
126 lines (107 loc) · 4.75 KB
/
ReadingListClientRecordTestCase.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
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
122
123
124
125
126
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@testable import ReadingList
import Foundation
import XCTest
class ReadingListClientRecordTestCase: XCTestCase {
func testInitWithRow() {
let now = ReadingListNow()
let row: [String:AnyObject] = [
"client_id": 1234,
"client_last_modified": NSNumber(longLong: now),
"id": "5DB5597A-8E60-454D-B1F5-51810C2A5FFE",
"last_modified": NSNumber(longLong: now),
"url": "http://localhost/article/1",
"title": "Article 1",
"added_by": "Stefan's iPhone",
"unread": true,
"archived": false,
"favorite": true
]
let record = ReadingListClientRecord(row: row)
XCTAssert(record != nil)
if let record = record {
XCTAssertEqual(record.url, "http://localhost/article/1")
XCTAssertEqual(record.title, "Article 1")
XCTAssertEqual(record.addedBy, "Stefan's iPhone")
XCTAssertEqual(record.unread, true)
XCTAssertEqual(record.archived, false)
XCTAssertEqual(record.favorite, true)
XCTAssert(record.clientMetadata.id == 1234)
XCTAssert(record.clientMetadata.lastModified == now)
XCTAssert(record.serverMetadata != nil)
XCTAssertEqual(record.serverMetadata!.guid, "5DB5597A-8E60-454D-B1F5-51810C2A5FFE")
XCTAssertEqual(record.serverMetadata!.lastModified, now)
}
}
func testInitWithRowWithoutServerMeta() {
let now = ReadingListNow()
let row: [String:AnyObject] = [
"client_id": 1234,
"client_last_modified": NSNumber(longLong: now),
"url": "http://localhost/article/1",
"title": "Article 1",
"added_by": "Stefan's iPhone",
"unread": true,
"archived": false,
"favorite": true
]
let record = ReadingListClientRecord(row: row)
XCTAssert(record != nil)
if let record = record {
XCTAssertEqual(record.url, "http://localhost/article/1")
XCTAssertEqual(record.title, "Article 1")
XCTAssertEqual(record.addedBy, "Stefan's iPhone")
XCTAssertEqual(record.unread, true)
XCTAssertEqual(record.archived, false)
XCTAssertEqual(record.favorite, true)
XCTAssert(record.clientMetadata.id == 1234)
XCTAssert(record.clientMetadata.lastModified == now)
XCTAssert(record.serverMetadata == nil)
}
}
func testInitWithEmptyRow() {
let row = NSDictionary()
let record = ReadingListClientRecord(row: row)
XCTAssert(record == nil)
}
// func testInit() {
// let record = ReadingListClientRecord(url: "http://localhost/some/article", title: "Some Article", addedBy: "Stefan's iPad Mini")
// XCTAssertNil(record.clientMetadata.id)
// XCTAssert(record.clientMetadata.lastModified != 0)
// XCTAssert(record.serverMetadata == nil)
// XCTAssertEqual(record.url, "http://localhost/some/article")
// XCTAssertEqual(record.title, "Some Article")
// XCTAssertEqual(record.addedBy, "Stefan's iPad Mini")
// XCTAssertEqual(record.unread, ReadingListDefaultUnread)
// XCTAssertEqual(record.favorite, ReadingListDefaultFavorite)
// XCTAssertEqual(record.archived, ReadingListDefaultArchived)
// }
func testJSON() {
let now = ReadingListNow()
let row: [String:AnyObject] = [
"client_id": 1234,
"client_last_modified": NSNumber(longLong: now),
"id": "5DB5597A-8E60-454D-B1F5-51810C2A5FFE",
"last_modified": NSNumber(longLong: now),
"url": "http://localhost/article/1",
"title": "Article 1",
"added_by": "Stefan's iPhone 3GS",
"unread": true,
"archived": false,
"favorite": true
]
let record = ReadingListClientRecord(row: row)
XCTAssert(record != nil)
if let record = record {
let json: AnyObject = record.json
XCTAssertEqual(json.valueForKeyPath("url") as? String, "http://localhost/article/1")
XCTAssertEqual(json.valueForKeyPath("title") as? String, "Article 1")
XCTAssertEqual(json.valueForKeyPath("added_by") as? String, "Stefan's iPhone 3GS")
XCTAssertEqual(json.valueForKeyPath("unread") as? Bool, true)
XCTAssertEqual(json.valueForKeyPath("archived") as? Bool, false)
XCTAssertEqual(json.valueForKeyPath("favorite") as? Bool, true)
}
}
}