Adding a few tests here and there

This commit is contained in:
Mathew Polzin
2018-12-05 18:31:53 -08:00
parent 6e6973c170
commit 1f83216b03
4 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -358,7 +358,7 @@ public extension Entity where EntityRawIdType: JSONAPI.RawIdType {
return ToOneRelationship(entity: self, meta: .none, links: .none)
}
public func pointer<MType: JSONAPI.Meta, LType: JSONAPI.Links>(withMeta meta: MType, andLinks links: LType) -> ToOneRelationship<Entity, MType, LType> {
public func pointer<MType: JSONAPI.Meta, LType: JSONAPI.Links>(withMeta meta: MType, links: LType) -> ToOneRelationship<Entity, MType, LType> {
return ToOneRelationship(entity: self, meta: meta, links: links)
}
}
@@ -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<NoMetadata>.self, data: api_description_empty)
@@ -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))
@@ -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<Article>.self,
data: single_resource_body)