Skip to content

Commit b303aff

Browse files
committed
Fix tests to check correct 1-to-many relationships serialization according to JSON API v1.0 specification
1 parent 75c1ea6 commit b303aff

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Project/JSONAPITests/JSONAPITests.m

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,21 @@ - (void)testSerializeComplex {
151151
newAuthor.firstName = @"Karl";
152152
newAuthor.lastName = @"Armstrong";
153153

154-
CommentResource *newComment = [[CommentResource alloc] init];
155-
newComment.ID = [NSUUID UUID];
156-
newComment.author = newAuthor;
157-
newComment.text = @"First!";
154+
CommentResource *firstComment = [[CommentResource alloc] init];
155+
firstComment.ID = [NSUUID UUID];
156+
firstComment.author = newAuthor;
157+
firstComment.text = @"First!";
158+
159+
CommentResource *secondComment = [[CommentResource alloc] init];
160+
secondComment.ID = [NSUUID UUID];
161+
secondComment.author = newAuthor;
162+
secondComment.text = @"Second!";
158163

159164
ArticleResource *newArticle = [[ArticleResource alloc] init];
160165
newArticle.title = @"Title";
161166
newArticle.author = newAuthor;
162167
newArticle.date = [NSDate date];
163-
newArticle.comments = [[NSArray alloc] initWithObjects:newComment, nil];
168+
newArticle.comments = [[NSArray alloc] initWithObjects:firstComment, secondComment, nil];
164169

165170
NSDictionary *json = [JSONAPIResourceParser dictionaryFor:newArticle];
166171
XCTAssertEqualObjects(json[@"type"], @"articles", @"Did not create Article!");
@@ -171,8 +176,8 @@ - (void)testSerializeComplex {
171176
XCTAssertNil(json[@"relationships"][@"author"][@"first-name"], @"Bad link!");
172177

173178
XCTAssertNotNil(json[@"relationships"][@"comments"], @"Did not create links!");
174-
XCTAssertTrue([json[@"relationships"][@"comments"] isKindOfClass:[NSArray class]], @"Comments should be array!.");
175-
XCTAssertEqual([json[@"relationships"][@"comments"] count], 1, @"Comments should have 1 element!.");
179+
XCTAssertTrue([json[@"relationships"][@"comments"][@"data"] isKindOfClass:[NSArray class]], @"Comments should be array!.");
180+
XCTAssertEqual([json[@"relationships"][@"comments"][@"data"] count], 2, @"Comments should have 1 element!.");
176181
}
177182

178183
- (void)testCreate {
@@ -226,11 +231,11 @@ - (void)testGenericSerialization {
226231
NSDictionary *serializedFirstPost = [JSONAPIResourceParser dictionaryFor:posts.firstObject];
227232
NSDictionary *serializedSecondPost = [JSONAPIResourceParser dictionaryFor:posts.lastObject];
228233

229-
XCTAssertNotNil(serializedFirstPost[@"relationships"][@"attachments"][0], @"Media attachment should not be nil");
230-
XCTAssertNotNil(serializedFirstPost[@"relationships"][@"attachments"][1], @"Web page url attachment should not be nil");
234+
XCTAssertNotNil(serializedFirstPost[@"relationships"][@"attachments"][@"data"][0], @"Media attachment should not be nil");
235+
XCTAssertNotNil(serializedFirstPost[@"relationships"][@"attachments"][@"data"][1], @"Web page url attachment should not be nil");
231236

232-
XCTAssertEqualObjects(serializedFirstPost[@"relationships"][@"attachments"][0][@"data"][@"id"], @15, @"Media id should be '15'");
233-
XCTAssertEqualObjects(serializedFirstPost[@"relationships"][@"attachments"][0][@"data"][@"type"], @"Media", @"Media type should be 'Media'");
237+
XCTAssertEqualObjects(serializedFirstPost[@"relationships"][@"attachments"][@"data"][0][@"id"], @15, @"Media id should be '15'");
238+
XCTAssertEqualObjects(serializedFirstPost[@"relationships"][@"attachments"][@"data"][0][@"type"], @"Media", @"Media type should be 'Media'");
234239

235240
XCTAssertEqualObjects(serializedFirstPost[@"relationships"][@"publisher"][@"data"][@"id"], @45, @"User id should be '45'");
236241
XCTAssertEqualObjects(serializedFirstPost[@"relationships"][@"publisher"][@"data"][@"type"], @"User", @"User type should be 'User'");

0 commit comments

Comments
 (0)