@@ -69,6 +69,7 @@ class PaginatedListTests: XCTestCase {
69
69
XCTAssertNotNil ( paginatedList. startedAt)
70
70
XCTAssertNotNil ( paginatedList. nextToken)
71
71
XCTAssertNotNil ( paginatedList. items)
72
+ XCTAssertEqual ( paginatedList. items. count, 2 )
72
73
XCTAssert ( !paginatedList. items. isEmpty)
73
74
XCTAssert ( paginatedList. items [ 0 ] . model. title == " title " )
74
75
XCTAssert ( paginatedList. items [ 0 ] . syncMetadata. version == 10 )
@@ -94,4 +95,53 @@ class PaginatedListTests: XCTestCase {
94
95
}
95
96
}
96
97
98
+ /// - Given: a `Post` Sync query with items, nextToken, and with sync data (startedAt, _version, etc)
99
+ /// - When:
100
+ /// - some of the JSON items are not able to be decoded to Post
101
+ /// - the JSON is decoded into `PaginatedList<Post>`
102
+ /// - Then:
103
+ /// - the result should contain only valid items of type MutationSync<Post>, startedAt, nextToken.
104
+ func testDecodePaginatedListOptimistically( ) {
105
+ let syncQueryJSON = """
106
+ {
107
+ " items " : [
108
+ null,
109
+ {
110
+ " id " : " post-id " ,
111
+ " createdAt " : " 2019-11-27T23:35:39Z " ,
112
+ " _version " : 10,
113
+ " _lastChangedAt " : 1574897753341,
114
+ " _deleted " : null
115
+ },
116
+ {
117
+ " id " : " post-id " ,
118
+ " title " : " title " ,
119
+ " content " : " post content " ,
120
+ " createdAt " : " 2019-11-27T23:35:39Z " ,
121
+ " _version " : 11,
122
+ " _lastChangedAt " : 1574897753341,
123
+ " _deleted " : null
124
+ }
125
+ ],
126
+ " startedAt " : 1575322600038,
127
+ " nextToken " : " token "
128
+ }
129
+ """
130
+ do {
131
+ let decoder = JSONDecoder ( dateDecodingStrategy: ModelDateFormatting . decodingStrategy)
132
+ let data = Data ( syncQueryJSON. utf8)
133
+ let paginatedList = try decoder. decode ( PaginatedList< Post> . self , from: data)
134
+ XCTAssertNotNil ( paginatedList)
135
+ XCTAssertNotNil ( paginatedList. startedAt)
136
+ XCTAssertNotNil ( paginatedList. nextToken)
137
+ XCTAssertNotNil ( paginatedList. items)
138
+ XCTAssertEqual ( paginatedList. items. count, 1 )
139
+ XCTAssert ( paginatedList. items [ 0 ] . model. title == " title " )
140
+ XCTAssert ( paginatedList. items [ 0 ] . syncMetadata. version == 11 )
141
+ XCTAssert ( paginatedList. items [ 0 ] . syncMetadata. lastChangedAt == 1_574_897_753_341 )
142
+ } catch {
143
+ XCTFail ( error. localizedDescription)
144
+ }
145
+ }
146
+
97
147
}
0 commit comments