|
12 | 12 | #import "JSONAPIResourceDescriptor.h"
|
13 | 13 | #import "JSONAPIErrorResource.h"
|
14 | 14 | #import "JSONAPIResourceParser.h"
|
| 15 | +#import "NSDateFormatter+JSONAPIDateFormatter.h" |
15 | 16 |
|
16 | 17 | #import "CommentResource.h"
|
17 | 18 | #import "PeopleResource.h"
|
@@ -65,10 +66,12 @@ - (void)testDataArticles {
|
65 | 66 | ArticleResource *article = jsonAPI.resource;
|
66 | 67 | XCTAssert([article isKindOfClass:[ArticleResource class]], @"Article should be a ArticleResource");
|
67 | 68 | XCTAssertEqualObjects(article.ID, @"1", @"Article id should be 1");
|
| 69 | + XCTAssertTrue([article.selfLink isEqualToString:@"http://example.com/articles/1"], @"Article selfLink should be 'http://example.com/articles/1'"); |
68 | 70 | XCTAssertEqualObjects(article.title, @"JSON API paints my bikeshed!", @"Article title should be 'JSON API paints my bikeshed!'");
|
69 | 71 |
|
70 |
| - NSArray *dateStrings = @[@"2015-09-01T12:15:00Z",@"2015-08-01T06:15:00Z"]; |
71 |
| - XCTAssertEqualObjects(article.versions, dateStrings, @"Article versions should contain an array of date strings"); |
| 72 | + NSArray *dates = @[[[NSDateFormatter RFC3339DateFormatter] dateFromString:@"2015-09-01T12:15:00.000Z"], |
| 73 | + [[NSDateFormatter RFC3339DateFormatter] dateFromString:@"2015-08-01T06:15:00.000Z"]]; |
| 74 | + XCTAssertEqualObjects(article.versions, dates, @"Article versions should contain an array of date objects"); |
72 | 75 | }
|
73 | 76 |
|
74 | 77 | - (void)testIncludedPeopleAndComments {
|
@@ -181,13 +184,21 @@ - (void)testSerializeComplex {
|
181 | 184 | }
|
182 | 185 |
|
183 | 186 | - (void)testCreate {
|
184 |
| - PeopleResource *newAuthor = [[PeopleResource alloc] init]; |
185 |
| - |
186 |
| - newAuthor.firstName = @"Karl"; |
187 |
| - newAuthor.lastName = @"Armstrong"; |
188 |
| - |
189 |
| - JSONAPI *jsonAPI = [JSONAPI jsonAPIWithResource:newAuthor]; |
190 |
| - XCTAssertEqualObjects([jsonAPI dictionary][@"data"][@"type"], @"people", @"Did not create person!"); |
| 187 | + NSDictionary *json = [self mainExampleJSON]; |
| 188 | + JSONAPI *jsonAPI = [JSONAPI jsonAPIWithDictionary:json]; |
| 189 | + |
| 190 | + ArticleResource *article = jsonAPI.resource; |
| 191 | + |
| 192 | + jsonAPI = [JSONAPI jsonAPIWithResource:article]; |
| 193 | + NSDictionary *dictionary = [jsonAPI dictionary]; |
| 194 | + XCTAssertEqualObjects(dictionary[@"data"][@"type"], @"articles", @"Did not create article!"); |
| 195 | + XCTAssertEqualObjects(dictionary[@"data"][@"attributes"][@"title"], @"JSON API paints my bikeshed!", @"Did not parse title!"); |
| 196 | + XCTAssertEqual([dictionary[@"data"][@"relationships"][@"comments"][@"data"] count], 2, @"Did not parse relationships!"); |
| 197 | + XCTAssertEqual([dictionary[@"included"] count], 3, @"Did not parse included resources!"); |
| 198 | + XCTAssertEqualObjects(dictionary[@"included"][0][@"type"], @"people", @"Did not parse included people object!"); |
| 199 | + XCTAssertEqualObjects(dictionary[@"included"][0][@"id"], @"9", @"Did not parse ID!"); |
| 200 | + XCTAssertEqualObjects(dictionary[@"included"][1][@"type"], @"comments", @"Did not parse included comments object!"); |
| 201 | + XCTAssertEqualObjects(dictionary[@"included"][1][@"relationships"][@"author"][@"data"][@"type"], @"people", @"Did not parse included comments author!"); |
191 | 202 | }
|
192 | 203 |
|
193 | 204 | #pragma mark - Generic relationships tests
|
|
0 commit comments