@@ -57,6 +57,8 @@ class EntityTests: XCTestCase {
5757 let _ = TestEntity10 ( id: . init( rawValue: " 10 " ) , relationships: . init( selfRef: . init( id: e10id1) , selfRefs: . init( ids: [ e10id2, e10id3] ) ) )
5858 XCTAssertNoThrow ( try TestEntity11 ( id: . init( rawValue: " 11 " ) , attributes: . init( number: . init( rawValue: 11 ) ) ) )
5959 let _ = UnidentifiedTestEntity ( attributes: . init( me: . init( value: " hello " ) ) )
60+ let _ = UnidentifiedTestEntityWithMeta ( attributes: . init( me: . init( value: " hello " ) ) , meta: . init( x: " world " , y: nil ) )
61+ let _ = UnidentifiedTestEntityWithLinks ( attributes: . init( me: . init( value: " hello " ) ) , links: . init( link1: . init( url: " hmmm " ) ) )
6062 }
6163}
6264
@@ -336,6 +338,109 @@ extension EntityTests {
336338 }
337339}
338340
341+ // MARK: With Meta and/or Links
342+
343+ extension EntityTests {
344+ func test_UnidentifiedEntityWithAttributesAndMeta( ) {
345+ let entity = decoded ( type: UnidentifiedTestEntityWithMeta . self,
346+ data: entity_unidentified_with_attributes_and_meta)
347+
348+ XCTAssertEqual ( entity [ \. me] , " unknown " )
349+ XCTAssertEqual ( entity. id, . unidentified)
350+ XCTAssertEqual ( entity. meta. x, " world " )
351+ XCTAssertEqual ( entity. meta. y, 5 )
352+ XCTAssertNoThrow ( try UnidentifiedTestEntityWithMeta . check ( entity) )
353+ }
354+
355+ func test_UnidentifiedEntityWithAttributesAndMeta_encode( ) {
356+ test_DecodeEncodeEquality ( type: UnidentifiedTestEntityWithMeta . self,
357+ data: entity_unidentified_with_attributes_and_meta)
358+ }
359+
360+ func test_UnidentifiedEntityWithAttributesAndLinks( ) {
361+ let entity = decoded ( type: UnidentifiedTestEntityWithLinks . self,
362+ data: entity_unidentified_with_attributes_and_links)
363+
364+ XCTAssertEqual ( entity [ \. me] , " unknown " )
365+ XCTAssertEqual ( entity. id, . unidentified)
366+ XCTAssertEqual ( entity. links. link1, . init( url: " https://image.com/image.png " ) )
367+ XCTAssertNoThrow ( try UnidentifiedTestEntityWithLinks . check ( entity) )
368+ }
369+
370+ func test_UnidentifiedEntityWithAttributesAndLinks_encode( ) {
371+ test_DecodeEncodeEquality ( type: UnidentifiedTestEntityWithLinks . self,
372+ data: entity_unidentified_with_attributes_and_links)
373+ }
374+
375+ func test_UnidentifiedEntityWithAttributesAndMetaAndLinks( ) {
376+ let entity = decoded ( type: UnidentifiedTestEntityWithMetaAndLinks . self,
377+ data: entity_unidentified_with_attributes_and_meta_and_links)
378+
379+ XCTAssertEqual ( entity [ \. me] , " unknown " )
380+ XCTAssertEqual ( entity. id, . unidentified)
381+ XCTAssertEqual ( entity. meta. x, " world " )
382+ XCTAssertEqual ( entity. meta. y, 5 )
383+ XCTAssertEqual ( entity. links. link1, . init( url: " https://image.com/image.png " ) )
384+ XCTAssertNoThrow ( try UnidentifiedTestEntityWithMetaAndLinks . check ( entity) )
385+ }
386+
387+ func test_UnidentifiedEntityWithAttributesAndMetaAndLinks_encode( ) {
388+ test_DecodeEncodeEquality ( type: UnidentifiedTestEntityWithMetaAndLinks . self,
389+ data: entity_unidentified_with_attributes_and_meta_and_links)
390+ }
391+
392+ func test_EntitySomeRelationshipsSomeAttributesWithMeta( ) {
393+ let entity = decoded ( type: TestEntity4WithMeta . self,
394+ data: entity_some_relationships_some_attributes_with_meta)
395+
396+ XCTAssertEqual ( entity [ \. word] , " coolio " )
397+ XCTAssertEqual ( entity [ \. number] , 992299 )
398+ XCTAssertEqual ( ( entity ~> \. other) . rawValue, " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " )
399+ XCTAssertEqual ( entity. meta. x, " world " )
400+ XCTAssertEqual ( entity. meta. y, 5 )
401+ XCTAssertNoThrow ( try TestEntity4WithMeta . check ( entity) )
402+ }
403+
404+ func test_EntitySomeRelationshipsSomeAttributesWithMeta_encode( ) {
405+ test_DecodeEncodeEquality ( type: TestEntity4WithMeta . self,
406+ data: entity_some_relationships_some_attributes_with_meta)
407+ }
408+
409+ func test_EntitySomeRelationshipsSomeAttributesWithLinks( ) {
410+ let entity = decoded ( type: TestEntity4WithLinks . self,
411+ data: entity_some_relationships_some_attributes_with_links)
412+
413+ XCTAssertEqual ( entity [ \. word] , " coolio " )
414+ XCTAssertEqual ( entity [ \. number] , 992299 )
415+ XCTAssertEqual ( ( entity ~> \. other) . rawValue, " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " )
416+ XCTAssertEqual ( entity. links. link1, . init( url: " https://image.com/image.png " ) )
417+ XCTAssertNoThrow ( try TestEntity4WithLinks . check ( entity) )
418+ }
419+
420+ func test_EntitySomeRelationshipsSomeAttributesWithLinks_encode( ) {
421+ test_DecodeEncodeEquality ( type: TestEntity4WithLinks . self,
422+ data: entity_some_relationships_some_attributes_with_links)
423+ }
424+
425+ func test_EntitySomeRelationshipsSomeAttributesWithMetaAndLinks( ) {
426+ let entity = decoded ( type: TestEntity4WithMetaAndLinks . self,
427+ data: entity_some_relationships_some_attributes_with_meta_and_links)
428+
429+ XCTAssertEqual ( entity [ \. word] , " coolio " )
430+ XCTAssertEqual ( entity [ \. number] , 992299 )
431+ XCTAssertEqual ( ( entity ~> \. other) . rawValue, " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " )
432+ XCTAssertEqual ( entity. meta. x, " world " )
433+ XCTAssertEqual ( entity. meta. y, 5 )
434+ XCTAssertEqual ( entity. links. link1, . init( url: " https://image.com/image.png " ) )
435+ XCTAssertNoThrow ( try TestEntity4WithMetaAndLinks . check ( entity) )
436+ }
437+
438+ func test_EntitySomeRelationshipsSomeAttributesWithMetaAndLinks_encode( ) {
439+ test_DecodeEncodeEquality ( type: TestEntity4WithMetaAndLinks . self,
440+ data: entity_some_relationships_some_attributes_with_meta_and_links)
441+ }
442+ }
443+
339444// MARK: - Test Types
340445extension EntityTests {
341446
@@ -388,6 +493,12 @@ extension EntityTests {
388493
389494 typealias TestEntity4 = BasicEntity < TestEntityType4 >
390495
496+ typealias TestEntity4WithMeta = Entity < TestEntityType4 , TestEntityMeta , NoLinks >
497+
498+ typealias TestEntity4WithLinks = Entity < TestEntityType4 , NoMetadata , TestEntityLinks >
499+
500+ typealias TestEntity4WithMetaAndLinks = Entity < TestEntityType4 , TestEntityMeta , TestEntityLinks >
501+
391502 enum TestEntityType5 : EntityDescription {
392503 static var type : String { return " fifth_test_entities " }
393504
@@ -504,6 +615,12 @@ extension EntityTests {
504615
505616 typealias UnidentifiedTestEntity = NewEntity < UnidentifiedTestEntityType , NoMetadata , NoLinks >
506617
618+ typealias UnidentifiedTestEntityWithMeta = NewEntity < UnidentifiedTestEntityType , TestEntityMeta , NoLinks >
619+
620+ typealias UnidentifiedTestEntityWithLinks = NewEntity < UnidentifiedTestEntityType , NoMetadata , TestEntityLinks >
621+
622+ typealias UnidentifiedTestEntityWithMetaAndLinks = NewEntity < UnidentifiedTestEntityType , TestEntityMeta , TestEntityLinks >
623+
507624 enum IntToString : Transformer {
508625 public static func transform( _ from: Int ) -> String {
509626 return String ( from)
@@ -540,4 +657,13 @@ extension EntityTests {
540657 return from
541658 }
542659 }
660+
661+ struct TestEntityMeta : JSONAPI . Meta {
662+ let x : String
663+ let y : Int ?
664+ }
665+
666+ struct TestEntityLinks : JSONAPI . Links {
667+ let link1 : Link < String , NoMetadata >
668+ }
543669}
0 commit comments