diff --git a/Sources/JSONAPI/Resource/Entity.swift b/Sources/JSONAPI/Resource/Entity.swift index 763a784..4adf193 100644 --- a/Sources/JSONAPI/Resource/Entity.swift +++ b/Sources/JSONAPI/Resource/Entity.swift @@ -358,7 +358,7 @@ public extension Entity where EntityRawIdType: JSONAPI.RawIdType { return ToOneRelationship(entity: self, meta: .none, links: .none) } - public func pointer(withMeta meta: MType, andLinks links: LType) -> ToOneRelationship { + public func pointer(withMeta meta: MType, links: LType) -> ToOneRelationship { return ToOneRelationship(entity: self, meta: meta, links: links) } } diff --git a/Tests/JSONAPITests/APIDescription/APIDescriptionTests.swift b/Tests/JSONAPITests/APIDescription/APIDescriptionTests.swift index e70d53e..d5706b6 100644 --- a/Tests/JSONAPITests/APIDescription/APIDescriptionTests.swift +++ b/Tests/JSONAPITests/APIDescription/APIDescriptionTests.swift @@ -10,6 +10,10 @@ import JSONAPI class APIDescriptionTests: XCTestCase { + func test_NoDescriptionString() { + XCTAssertEqual(String(describing: NoAPIDescription()), "No JSON:API Object") + } + func test_empty() { let description = decoded(type: APIDescription.self, data: api_description_empty) diff --git a/Tests/JSONAPITests/Entity/EntityTests.swift b/Tests/JSONAPITests/Entity/EntityTests.swift index e08111d..c6df47e 100644 --- a/Tests/JSONAPITests/Entity/EntityTests.swift +++ b/Tests/JSONAPITests/Entity/EntityTests.swift @@ -41,9 +41,21 @@ class EntityTests: XCTestCase { XCTAssertEqual(entity2.relationships.other.id, entity1.id) } + func test_pointerWithMetaAndLinks() { + let entity = TestEntity4WithMetaAndLinks(attributes: .init(word: "hello", number: 10, array: []), relationships: .init(other: .init(id: "2")), meta: .init(x: "world", y: nil), links: .init(link1: .init(url: "ok"))) + + let pointer = entity.pointer(withMeta: TestEntityMeta(x: "world", y: nil), links: TestEntityLinks(link1: .init(url: "ok"))) + + XCTAssertEqual(pointer.id, entity.id) + XCTAssertEqual(pointer.meta.x, "world") + XCTAssertEqual(pointer.links.link1.url, "ok") + } + func test_initialization() { let entity1 = TestEntity1(id: .init(rawValue: "wow")) let entity2 = TestEntity2(id: .init(rawValue: "cool"), relationships: .init(other: .init(entity: entity1))) + let _ = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(entity: entity1))) + let _ = TestEntity2(id: .init(rawValue: "cool"), relationships: .init(other: .init(entity: entity1)), meta: .none) let _ = TestEntity3(id: .init(rawValue: "3"), relationships: .init(others: .init(ids: [.init(rawValue: "10"), .init(rawValue: "20"), entity1.id]))) let _ = TestEntity3(id: .init(rawValue: "3"), relationships: .init(others: .none)) let _ = TestEntity4(id: .init(rawValue: "4"), attributes: .init(word: .init(value: "hello"), number: .init(value: 10), array: .init(value: [10.2, 10.3])), relationships: .init(other: entity2.pointer)) diff --git a/Tests/JSONAPITests/ResourceBody/ResourceBodyTests.swift b/Tests/JSONAPITests/ResourceBody/ResourceBodyTests.swift index 7566b03..2af4bed 100644 --- a/Tests/JSONAPITests/ResourceBody/ResourceBodyTests.swift +++ b/Tests/JSONAPITests/ResourceBody/ResourceBodyTests.swift @@ -10,6 +10,16 @@ import JSONAPI class ResourceBodyTests: XCTestCase { + func test_initializers() { + let articles = [ + Article(attributes: .init(title: "hello")), + Article(attributes: .init(title: "world")) + ] + let _ = SingleResourceBody(entity: articles[0]) + let _ = ManyResourceBody(entities: articles) + let _: NoResourceBody = .none + } + func test_singleResourceBody() { let body = decoded(type: SingleResourceBody
.self, data: single_resource_body)