Skip to content

Commit 1f83216

Browse files
committed
Adding a few tests here and there
1 parent 6e6973c commit 1f83216

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

Sources/JSONAPI/Resource/Entity.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public extension Entity where EntityRawIdType: JSONAPI.RawIdType {
358358
return ToOneRelationship(entity: self, meta: .none, links: .none)
359359
}
360360

361-
public func pointer<MType: JSONAPI.Meta, LType: JSONAPI.Links>(withMeta meta: MType, andLinks links: LType) -> ToOneRelationship<Entity, MType, LType> {
361+
public func pointer<MType: JSONAPI.Meta, LType: JSONAPI.Links>(withMeta meta: MType, links: LType) -> ToOneRelationship<Entity, MType, LType> {
362362
return ToOneRelationship(entity: self, meta: meta, links: links)
363363
}
364364
}

Tests/JSONAPITests/APIDescription/APIDescriptionTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import JSONAPI
1010

1111
class APIDescriptionTests: XCTestCase {
1212

13+
func test_NoDescriptionString() {
14+
XCTAssertEqual(String(describing: NoAPIDescription()), "No JSON:API Object")
15+
}
16+
1317
func test_empty() {
1418
let description = decoded(type: APIDescription<NoMetadata>.self, data: api_description_empty)
1519

Tests/JSONAPITests/Entity/EntityTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,21 @@ class EntityTests: XCTestCase {
4141
XCTAssertEqual(entity2.relationships.other.id, entity1.id)
4242
}
4343

44+
func test_pointerWithMetaAndLinks() {
45+
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")))
46+
47+
let pointer = entity.pointer(withMeta: TestEntityMeta(x: "world", y: nil), links: TestEntityLinks(link1: .init(url: "ok")))
48+
49+
XCTAssertEqual(pointer.id, entity.id)
50+
XCTAssertEqual(pointer.meta.x, "world")
51+
XCTAssertEqual(pointer.links.link1.url, "ok")
52+
}
53+
4454
func test_initialization() {
4555
let entity1 = TestEntity1(id: .init(rawValue: "wow"))
4656
let entity2 = TestEntity2(id: .init(rawValue: "cool"), relationships: .init(other: .init(entity: entity1)))
57+
let _ = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(entity: entity1)))
58+
let _ = TestEntity2(id: .init(rawValue: "cool"), relationships: .init(other: .init(entity: entity1)), meta: .none)
4759
let _ = TestEntity3(id: .init(rawValue: "3"), relationships: .init(others: .init(ids: [.init(rawValue: "10"), .init(rawValue: "20"), entity1.id])))
4860
let _ = TestEntity3(id: .init(rawValue: "3"), relationships: .init(others: .none))
4961
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))

Tests/JSONAPITests/ResourceBody/ResourceBodyTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import JSONAPI
1010

1111
class ResourceBodyTests: XCTestCase {
1212

13+
func test_initializers() {
14+
let articles = [
15+
Article(attributes: .init(title: "hello")),
16+
Article(attributes: .init(title: "world"))
17+
]
18+
let _ = SingleResourceBody(entity: articles[0])
19+
let _ = ManyResourceBody(entities: articles)
20+
let _: NoResourceBody = .none
21+
}
22+
1323
func test_singleResourceBody() {
1424
let body = decoded(type: SingleResourceBody<Article>.self,
1525
data: single_resource_body)

0 commit comments

Comments
 (0)