@@ -47,6 +47,46 @@ extension RelationshipTests {
4747 data: to_one_relationship)
4848 }
4949
50+ func test_ToOneRelationshipWithMeta( ) {
51+ let relationship = decoded ( type: ToOneWithMeta . self,
52+ data: to_one_relationship_with_meta)
53+
54+ XCTAssertEqual ( relationship. id. rawValue, " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " )
55+ XCTAssertEqual ( relationship. meta. a, " hello " )
56+ }
57+
58+ func test_ToOneRelationshipWithMeta_encode( ) {
59+ test_DecodeEncodeEquality ( type: ToOneWithMeta . self,
60+ data: to_one_relationship_with_meta)
61+ }
62+
63+ func test_ToOneRelationshipWithLinks( ) {
64+ let relationship = decoded ( type: ToOneWithLinks . self,
65+ data: to_one_relationship_with_links)
66+
67+ XCTAssertEqual ( relationship. id. rawValue, " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " )
68+ XCTAssertEqual ( relationship. links. b, . init( url: " world " ) )
69+ }
70+
71+ func test_ToOneRelationshipWithLinks_encode( ) {
72+ test_DecodeEncodeEquality ( type: ToOneWithLinks . self,
73+ data: to_one_relationship_with_links)
74+ }
75+
76+ func test_ToOneRelationshipWithMetaAndLinks( ) {
77+ let relationship = decoded ( type: ToOneWithMetaAndLinks . self,
78+ data: to_one_relationship_with_meta_and_links)
79+
80+ XCTAssertEqual ( relationship. id. rawValue, " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " )
81+ XCTAssertEqual ( relationship. meta. a, " hello " )
82+ XCTAssertEqual ( relationship. links. b, . init( url: " world " ) )
83+ }
84+
85+ func test_ToOneRelationshipWithMetaAndLinks_encode( ) {
86+ test_DecodeEncodeEquality ( type: ToOneWithMetaAndLinks . self,
87+ data: to_one_relationship_with_meta_and_links)
88+ }
89+
5090 func test_ToManyRelationship( ) {
5191 let relationship = decoded ( type: ToManyRelationship < TestEntity1 , NoMetadata , NoLinks > . self,
5292 data: to_many_relationship)
@@ -58,6 +98,46 @@ extension RelationshipTests {
5898 test_DecodeEncodeEquality ( type: ToManyRelationship < TestEntity1 , NoMetadata , NoLinks > . self,
5999 data: to_many_relationship)
60100 }
101+
102+ func test_ToManyRelationshipWithMeta( ) {
103+ let relationship = decoded ( type: ToManyWithMeta . self,
104+ data: to_many_relationship_with_meta)
105+
106+ XCTAssertEqual ( relationship. ids. map { $0. rawValue } , [ " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " , " 90F03B69-4DF1-467F-B52E-B0C9E44FC333 " , " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " ] )
107+ XCTAssertEqual ( relationship. meta. a, " hello " )
108+ }
109+
110+ func test_ToManyRelationshipWithMeta_encode( ) {
111+ test_DecodeEncodeEquality ( type: ToManyWithMeta . self,
112+ data: to_many_relationship_with_meta)
113+ }
114+
115+ func test_ToManyRelationshipWithLinks( ) {
116+ let relationship = decoded ( type: ToManyWithLinks . self,
117+ data: to_many_relationship_with_links)
118+
119+ XCTAssertEqual ( relationship. ids. map { $0. rawValue } , [ " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " , " 90F03B69-4DF1-467F-B52E-B0C9E44FC333 " , " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " ] )
120+ XCTAssertEqual ( relationship. links. b, . init( url: " world " ) )
121+ }
122+
123+ func test_ToManyRelationshipWithLinks_encode( ) {
124+ test_DecodeEncodeEquality ( type: ToManyWithLinks . self,
125+ data: to_many_relationship_with_links)
126+ }
127+
128+ func test_ToManyRelationshipWithMetaAndLinks( ) {
129+ let relationship = decoded ( type: ToManyWithMetaAndLinks . self,
130+ data: to_many_relationship_with_meta_and_links)
131+
132+ XCTAssertEqual ( relationship. ids. map { $0. rawValue } , [ " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " , " 90F03B69-4DF1-467F-B52E-B0C9E44FC333 " , " 2DF03B69-4B0A-467F-B52E-B0C9E44FCECF " ] )
133+ XCTAssertEqual ( relationship. meta. a, " hello " )
134+ XCTAssertEqual ( relationship. links. b, . init( url: " world " ) )
135+ }
136+
137+ func test_ToManyRelationshipWithMetaAndLinks_encode( ) {
138+ test_DecodeEncodeEquality ( type: ToManyWithMetaAndLinks . self,
139+ data: to_many_relationship_with_meta_and_links)
140+ }
61141}
62142
63143// MARK: Failure tests
@@ -82,4 +162,23 @@ extension RelationshipTests {
82162 }
83163
84164 typealias TestEntity1 = BasicEntity < TestEntityType1 >
165+
166+ typealias ToOneWithMeta = ToOneRelationship < TestEntity1 , TestMeta , NoLinks >
167+
168+ typealias ToOneWithLinks = ToOneRelationship < TestEntity1 , NoMetadata , TestLinks >
169+ typealias ToOneWithMetaAndLinks = ToOneRelationship < TestEntity1 , TestMeta , TestLinks >
170+
171+ typealias ToManyWithMeta = ToManyRelationship < TestEntity1 , TestMeta , NoLinks >
172+ typealias ToManyWithLinks = ToManyRelationship < TestEntity1 , NoMetadata , TestLinks >
173+ typealias ToManyWithMetaAndLinks = ToManyRelationship < TestEntity1 , TestMeta , TestLinks >
174+
175+ struct TestMeta : JSONAPI . Meta {
176+ let a : String
177+ }
178+
179+ typealias TestLink = JSONAPI . Link < String , NoMetadata >
180+
181+ struct TestLinks : JSONAPI . Links {
182+ let b : TestLink
183+ }
85184}
0 commit comments