mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
remove a bunch of convenience initializers that appeared to be giving the compiler some strife
This commit is contained in:
@@ -13,7 +13,7 @@ Please enjoy these examples, but allow me the forced casting and the lack of err
|
||||
// MARK: - Literal Expressibility
|
||||
// The JSONAPITestLib provides literal expressibility for key types to
|
||||
// make creating tests easier
|
||||
let dog = Dog(id: "1234", attributes: Dog.Attributes(name: "Buddy"), relationships: Dog.Relationships(owner: nil))
|
||||
let dog = Dog(id: "1234", attributes: Dog.Attributes(name: "Buddy"), relationships: Dog.Relationships(owner: nil), meta: .none, links: .none)
|
||||
|
||||
// MARK: - JSON API structure checking
|
||||
// The JSONAPITestLib provides a `check` function for each Entity type
|
||||
|
||||
@@ -13,7 +13,7 @@ let dogFromCode = try! Dog(name: "Buddy", owner: nil)
|
||||
|
||||
typealias SingleDogDocument = JSONAPI.Document<SingleResourceBody<Dog>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>
|
||||
|
||||
let singleDogDocument = SingleDogDocument(body: SingleResourceBody(entity: dogFromCode))
|
||||
let singleDogDocument = SingleDogDocument(apiDescription: .none, body: .init(entity: dogFromCode), includes: .none, meta: .none, links: .none)
|
||||
|
||||
let singleDogData = try! JSONEncoder().encode(singleDogDocument)
|
||||
|
||||
@@ -24,13 +24,13 @@ let dogFromData = dogResponse.body.primaryData?.value
|
||||
// MARK: - Create a request or response with multiple people and dogs and houses included
|
||||
let personIds = [Person.Identifier(), Person.Identifier()]
|
||||
let dogs = try! [Dog(name: "Buddy", owner: personIds[0]), Dog(name: "Joy", owner: personIds[0]), Dog(name: "Travis", owner: personIds[1])]
|
||||
let houses = [House(), House()]
|
||||
let houses = [House(attributes: .none, relationships: .none, meta: .none, links: .none), House(attributes: .none, relationships: .none, meta: .none, links: .none)]
|
||||
let people = try! [Person(id: personIds[0], name: ["Gary", "Doe"], favoriteColor: "Orange-Red", friends: [], dogs: [dogs[0], dogs[1]], home: houses[0]), Person(id: personIds[1], name: ["Elise", "Joy"], favoriteColor: "Red", friends: [], dogs: [dogs[2]], home: houses[1])]
|
||||
|
||||
typealias BatchPeopleDocument = JSONAPI.Document<ManyResourceBody<Person>, NoMetadata, NoLinks, Include2<Dog, House>, NoAPIDescription, UnknownJSONAPIError>
|
||||
|
||||
let includes = dogs.map { BatchPeopleDocument.Include($0) } + houses.map { BatchPeopleDocument.Include($0) }
|
||||
let batchPeopleDocument = BatchPeopleDocument(body: .init(entities: people), includes: .init(values: includes))
|
||||
let batchPeopleDocument = BatchPeopleDocument(apiDescription: .none, body: .init(entities: people), includes: .init(values: includes), meta: .none, links: .none)
|
||||
let batchPeopleData = try! JSONEncoder().encode(batchPeopleDocument)
|
||||
|
||||
// MARK: - Parse a request or response body with multiple people in it and dogs and houses included
|
||||
|
||||
@@ -64,7 +64,7 @@ public typealias Person = ExampleEntity<PersonDescription>
|
||||
|
||||
public extension Entity where Description == PersonDescription, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == String {
|
||||
public init(id: Person.Id? = nil,name: [String], favoriteColor: String, friends: [Person], dogs: [Dog], home: House) throws {
|
||||
self = try Person(id: id ?? Person.Id(), attributes: .init(name: .init(rawValue: name), favoriteColor: .init(rawValue: favoriteColor)), relationships: .init(friends: .init(entities: friends), dogs: .init(entities: dogs), home: .init(entity: home)))
|
||||
self = try Person(id: id ?? Person.Id(), attributes: .init(name: .init(rawValue: name), favoriteColor: .init(rawValue: favoriteColor)), relationships: .init(friends: .init(entities: friends), dogs: .init(entities: dogs), home: .init(entity: home)), meta: .none, links: .none)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,11 +93,11 @@ public typealias Dog = ExampleEntity<DogDescription>
|
||||
|
||||
public extension Entity where Description == DogDescription, MetaType == NoMetadata, LinksType == NoLinks, EntityRawIdType == String {
|
||||
public init(name: String, owner: Person?) throws {
|
||||
self = try Dog(attributes: .init(name: .init(rawValue: name)), relationships: DogDescription.Relationships(owner: .init(entity: owner)))
|
||||
self = try Dog(attributes: .init(name: .init(rawValue: name)), relationships: DogDescription.Relationships(owner: .init(entity: owner)), meta: .none, links: .none)
|
||||
}
|
||||
|
||||
public init(name: String, owner: Person.Id) throws {
|
||||
self = try Dog(attributes: .init(name: .init(rawValue: name)), relationships: .init(owner: .init(id: owner)))
|
||||
self = try Dog(attributes: .init(name: .init(rawValue: name)), relationships: .init(owner: .init(id: owner)), meta: .none, links: .none)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ public struct Document<PrimaryResourceBody: JSONAPI.ResourceBody, MetaType: JSON
|
||||
self.apiDescription = apiDescription
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
extension Document where IncludeType == NoIncludes {
|
||||
public init(apiDescription: APIDescription, body: PrimaryResourceBody, meta: MetaType, links: LinksType) {
|
||||
self.init(apiDescription: apiDescription, body: body, includes: .none, meta: meta, links: links)
|
||||
@@ -182,6 +182,7 @@ extension Document where IncludeType == NoIncludes, MetaType == NoMetadata, Link
|
||||
self.init(apiDescription: .none, body: body)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
extension Document {
|
||||
private enum RootCodingKeys: String, CodingKey {
|
||||
|
||||
@@ -143,6 +143,7 @@ extension Entity where EntityRawIdType == Unidentified {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
extension Entity where Description.Attributes == NoAttributes {
|
||||
public init(id: Entity.Id, relationships: Description.Relationships, meta: MetaType, links: LinksType) {
|
||||
self.init(id: id, attributes: NoAttributes(), relationships: relationships, meta: meta, links: links)
|
||||
@@ -370,6 +371,7 @@ extension Entity where MetaType == NoMetadata, LinksType == NoLinks, EntityRawId
|
||||
self.init(attributes: attributes, relationships: relationships, meta: .none, links: .none)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// MARK: Pointer for Relationships use.
|
||||
public extension Entity where EntityRawIdType: JSONAPI.RawIdType {
|
||||
|
||||
@@ -11,7 +11,7 @@ import JSONAPITestLib
|
||||
|
||||
class Attribute_FunctorTests: XCTestCase {
|
||||
func test_mapGuaranteed() {
|
||||
let entity = try? TestType(attributes: .init(name: "Frankie", number: .init(rawValue: 22.0)))
|
||||
let entity = try? TestType(attributes: .init(name: "Frankie", number: .init(rawValue: 22.0)), relationships: .none, meta: .none, links: .none)
|
||||
|
||||
XCTAssertNotNil(entity)
|
||||
|
||||
@@ -19,7 +19,7 @@ class Attribute_FunctorTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_mapOptionalSuccess() {
|
||||
let entity = try? TestType(attributes: .init(name: "Frankie", number: .init(rawValue: 22.0)))
|
||||
let entity = try? TestType(attributes: .init(name: "Frankie", number: .init(rawValue: 22.0)), relationships: .none, meta: .none, links: .none)
|
||||
|
||||
XCTAssertNotNil(entity)
|
||||
|
||||
@@ -27,7 +27,7 @@ class Attribute_FunctorTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_mapOptionalFailure() {
|
||||
let entity = try? TestType(attributes: .init(name: "Frankie", number: .init(rawValue: 22.5)))
|
||||
let entity = try? TestType(attributes: .init(name: "Frankie", number: .init(rawValue: 22.5)), relationships: .none, meta: .none, links: .none)
|
||||
|
||||
XCTAssertNotNil(entity)
|
||||
|
||||
|
||||
@@ -847,7 +847,7 @@ extension DocumentTests {
|
||||
// MARK: Poly PrimaryResource Tests
|
||||
extension DocumentTests {
|
||||
func test_singleDocument_PolyPrimaryResource() {
|
||||
let article = Article(id: Id(rawValue: "1"), relationships: .init(author: ToOneRelationship(id: Id(rawValue: "33"))))
|
||||
let article = Article(id: Id(rawValue: "1"), attributes: .none, relationships: .init(author: ToOneRelationship(id: Id(rawValue: "33"))), meta: .none, links: .none)
|
||||
let document = decoded(type: Document<SingleResourceBody<Poly2<Article, Author>>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self, data: single_document_no_includes)
|
||||
|
||||
XCTAssertEqual(document.body.primaryData?.value[Article.self], article)
|
||||
@@ -859,7 +859,7 @@ extension DocumentTests {
|
||||
}
|
||||
|
||||
func test_singleDocument_PolyPrimaryResourceWithAPIDescription() {
|
||||
let article = Article(id: Id(rawValue: "1"), relationships: .init(author: ToOneRelationship(id: Id(rawValue: "33"))))
|
||||
let article = Article(id: Id(rawValue: "1"), attributes: .none, relationships: .init(author: ToOneRelationship(id: Id(rawValue: "33"))), meta: .none, links: .none)
|
||||
let document = decoded(type: Document<SingleResourceBody<Poly2<Article, Author>>, NoMetadata, NoLinks, NoIncludes, TestAPIDescription, UnknownJSONAPIError>.self, data: single_document_no_includes_with_api_description)
|
||||
|
||||
XCTAssertEqual(document.body.primaryData?.value[Article.self], article)
|
||||
|
||||
@@ -12,15 +12,15 @@ import JSONAPITestLib
|
||||
class EntityTests: XCTestCase {
|
||||
|
||||
func test_relationship_access() {
|
||||
let entity1 = TestEntity1()
|
||||
let entity2 = TestEntity2(relationships: .init(other: entity1.pointer))
|
||||
let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity2 = TestEntity2(attributes: .none, relationships: .init(other: entity1.pointer), meta: .none, links: .none)
|
||||
|
||||
XCTAssertEqual(entity2.relationships.other, entity1.pointer)
|
||||
}
|
||||
|
||||
func test_relationship_operator_access() {
|
||||
let entity1 = TestEntity1()
|
||||
let entity2 = TestEntity2(relationships: .init(other: entity1.pointer))
|
||||
let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity2 = TestEntity2(attributes: .none, relationships: .init(other: entity1.pointer), meta: .none, links: .none)
|
||||
|
||||
XCTAssertEqual(entity2 ~> \.other, entity1.id)
|
||||
}
|
||||
@@ -30,10 +30,10 @@ class EntityTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_toMany_relationship_operator_access() {
|
||||
let entity1 = TestEntity1()
|
||||
let entity2 = TestEntity1()
|
||||
let entity4 = TestEntity1()
|
||||
let entity3 = TestEntity3(relationships: .init(others: .init(pointers: [entity1.pointer, entity2.pointer, entity4.pointer])))
|
||||
let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity2 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity4 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity3 = TestEntity3(attributes: .none, relationships: .init(others: .init(pointers: [entity1.pointer, entity2.pointer, entity4.pointer])), meta: .none, links: .none)
|
||||
|
||||
XCTAssertEqual(entity3 ~> \.others, [entity1.id, entity2.id, entity4.id])
|
||||
}
|
||||
@@ -43,8 +43,8 @@ class EntityTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_relationshipIds() {
|
||||
let entity1 = TestEntity1()
|
||||
let entity2 = TestEntity2(relationships: .init(other: entity1.pointer))
|
||||
let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity2 = TestEntity2(attributes: .none, relationships: .init(other: entity1.pointer), meta: .none, links: .none)
|
||||
|
||||
XCTAssertEqual(entity2.relationships.other.id, entity1.id)
|
||||
}
|
||||
@@ -60,31 +60,31 @@ class EntityTests: XCTestCase {
|
||||
}
|
||||
|
||||
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))
|
||||
let _ = TestEntity5(id: .init(rawValue: "5"), attributes: .init(floater: .init(value: 10.2)))
|
||||
let _ = TestEntity6(id: .init(rawValue: "6"), attributes: .init(here: .init(value: "here"), maybeHere: nil, maybeNull: .init(value: nil)))
|
||||
let _ = TestEntity7(id: .init(rawValue: "7"), attributes: .init(here: .init(value: "hello"), maybeHereMaybeNull: .init(value: "world")))
|
||||
XCTAssertNoThrow(try TestEntity8(id: .init(rawValue: "8"), attributes: .init(string: .init(value: "hello"), int: .init(value: 10), stringFromInt: .init(rawValue: 20), plus: .init(rawValue: 30), doubleFromInt: .init(rawValue: 32), omitted: nil, nullToString: .init(rawValue: nil))))
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: nil, optionalMany: nil))
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), relationships: .init(one: entity1.pointer, nullableOne: .init(entity: nil), optionalOne: nil, optionalNullableOne: nil, optionalMany: nil))
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), relationships: .init(one: entity1.pointer, nullableOne: .init(entity: entity1, meta: .none, links: .none), optionalOne: nil, optionalNullableOne: nil, optionalMany: nil))
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: entity1.pointer, optionalNullableOne: nil, optionalMany: nil))
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: .init(entity: entity1, meta: .none, links: .none), optionalMany: nil))
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: .init(entity: entity1, meta: .none, links: .none), optionalMany: .init(entities: [], meta: .none, links: .none)))
|
||||
let entity1 = TestEntity1(id: .init(rawValue: "wow"), attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity2 = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(entity: entity1)), meta: .none, links: .none)
|
||||
let _ = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(entity: entity1)), meta: .none, links: .none)
|
||||
let _ = TestEntity2(id: .init(rawValue: "cool"), attributes: .none, relationships: .init(other: .init(entity: entity1)), meta: .none, links: .none)
|
||||
let _ = TestEntity3(id: .init(rawValue: "3"), attributes: .none, relationships: .init(others: .init(ids: [.init(rawValue: "10"), .init(rawValue: "20"), entity1.id])), meta: .none, links: .none)
|
||||
let _ = TestEntity3(id: .init(rawValue: "3"), attributes: .none, relationships: .init(others: .none), meta: .none, links: .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), meta: .none, links: .none)
|
||||
let _ = TestEntity5(id: .init(rawValue: "5"), attributes: .init(floater: .init(value: 10.2)), relationships: .none, meta: .none, links: .none)
|
||||
let _ = TestEntity6(id: .init(rawValue: "6"), attributes: .init(here: .init(value: "here"), maybeHere: nil, maybeNull: .init(value: nil)), relationships: .none, meta: .none, links: .none)
|
||||
let _ = TestEntity7(id: .init(rawValue: "7"), attributes: .init(here: .init(value: "hello"), maybeHereMaybeNull: .init(value: "world")), relationships: .none, meta: .none, links: .none)
|
||||
XCTAssertNoThrow(try TestEntity8(id: .init(rawValue: "8"), attributes: .init(string: .init(value: "hello"), int: .init(value: 10), stringFromInt: .init(rawValue: 20), plus: .init(rawValue: 30), doubleFromInt: .init(rawValue: 32), omitted: nil, nullToString: .init(rawValue: nil)), relationships: .none, meta: .none, links: .none))
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none)
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(entity: nil), optionalOne: nil, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none)
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(entity: entity1, meta: .none, links: .none), optionalOne: nil, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none)
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: entity1.pointer, optionalNullableOne: nil, optionalMany: nil), meta: .none, links: .none)
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: .init(entity: entity1, meta: .none, links: .none), optionalMany: nil), meta: .none, links: .none)
|
||||
let _ = TestEntity9(id: .init(rawValue: "9"), attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: nil, optionalOne: nil, optionalNullableOne: .init(entity: entity1, meta: .none, links: .none), optionalMany: .init(entities: [], meta: .none, links: .none)), meta: .none, links: .none)
|
||||
let e10id1 = TestEntity10.Identifier(rawValue: "hello")
|
||||
let e10id2 = TestEntity10.Id(rawValue: "world")
|
||||
let e10id3: TestEntity10.Id = "!"
|
||||
let _ = TestEntity10(id: .init(rawValue: "10"), relationships: .init(selfRef: .init(id: e10id1), selfRefs: .init(ids: [e10id2, e10id3])))
|
||||
XCTAssertNoThrow(try TestEntity11(id: .init(rawValue: "11"), attributes: .init(number: .init(rawValue: 11))))
|
||||
let _ = UnidentifiedTestEntity(attributes: .init(me: .init(value: "hello")))
|
||||
let _ = UnidentifiedTestEntityWithMeta(attributes: .init(me: .init(value: "hello")), meta: .init(x: "world", y: nil))
|
||||
let _ = UnidentifiedTestEntityWithLinks(attributes: .init(me: .init(value: "hello")), links: .init(link1: .init(url: "hmmm")))
|
||||
let _ = TestEntity10(id: .init(rawValue: "10"), attributes: .none, relationships: .init(selfRef: .init(id: e10id1), selfRefs: .init(ids: [e10id2, e10id3])), meta: .none, links: .none)
|
||||
XCTAssertNoThrow(try TestEntity11(id: .init(rawValue: "11"), attributes: .init(number: .init(rawValue: 11)), relationships: .none, meta: .none, links: .none))
|
||||
let _ = UnidentifiedTestEntity(attributes: .init(me: .init(value: "hello")), relationships: .none, meta: .none, links: .none)
|
||||
let _ = UnidentifiedTestEntityWithMeta(attributes: .init(me: .init(value: "hello")), relationships: .none, meta: .init(x: "world", y: nil), links: .none)
|
||||
let _ = UnidentifiedTestEntityWithLinks(attributes: .init(me: .init(value: "hello")), relationships: .none, meta: .none, links: .init(link1: .init(url: "hmmm")))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,27 +13,27 @@ import JSONAPITestLib
|
||||
// in this file.
|
||||
class EntityCheckTests: XCTestCase {
|
||||
func test_failsWithEnumAttributes() {
|
||||
let entity = EnumAttributesEntity(attributes: .hello)
|
||||
let entity = EnumAttributesEntity(attributes: .hello, relationships: .none, meta: .none, links: .none)
|
||||
XCTAssertThrowsError(try EnumAttributesEntity.check(entity))
|
||||
}
|
||||
|
||||
func test_failsWithEnumRelationships() {
|
||||
let entity = EnumRelationshipsEntity(relationships: .hello)
|
||||
let entity = EnumRelationshipsEntity(attributes: .none, relationships: .hello, meta: .none, links: .none)
|
||||
XCTAssertThrowsError(try EnumRelationshipsEntity.check(entity))
|
||||
}
|
||||
|
||||
func test_failsWithBadAttribute() {
|
||||
let entity = BadAttributeEntity(attributes: .init(x: "ok", y: "not ok"))
|
||||
let entity = BadAttributeEntity(attributes: .init(x: "ok", y: "not ok"), relationships: .none, meta: .none, links: .none)
|
||||
XCTAssertThrowsError(try BadAttributeEntity.check(entity))
|
||||
}
|
||||
|
||||
func test_failsWithBadRelationship() {
|
||||
let entity = BadRelationshipEntity(relationships: .init(x: OkEntity().pointer, y: OkEntity().id))
|
||||
let entity = BadRelationshipEntity(attributes: .none, relationships: .init(x: OkEntity(attributes: .none, relationships: .none, meta: .none, links: .none).pointer, y: OkEntity(attributes: .none, relationships: .none, meta: .none, links: .none).id), meta: .none, links: .none)
|
||||
XCTAssertThrowsError(try BadRelationshipEntity.check(entity))
|
||||
}
|
||||
|
||||
func test_failsWithOptionalArrayAttribute() {
|
||||
let entity = OptionalArrayAttributeEntity(attributes: .init(x: ["hello"], y: nil))
|
||||
let entity = OptionalArrayAttributeEntity(attributes: .init(x: ["hello"], y: nil), relationships: .none, meta: .none, links: .none)
|
||||
XCTAssertThrowsError(try OptionalArrayAttributeEntity.check(entity))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class NonJSONAPIRelatableTests: XCTestCase {
|
||||
let e1 = NonJSONAPIEntity(id: .init(rawValue: "hello"))
|
||||
let e2 = NonJSONAPIEntity(id: .init(rawValue: "world"))
|
||||
|
||||
let entity = TestEntity(relationships: .init(one: .init(id: e1.id), many: .init(ids: [e1.id, e2.id])))
|
||||
let entity = TestEntity(attributes: .none, relationships: .init(one: .init(id: e1.id), many: .init(ids: [e1.id, e2.id])), meta: .none, links: .none)
|
||||
|
||||
XCTAssertEqual(entity ~> \.one, e1.id)
|
||||
XCTAssertEqual(entity ~> \.many, [e1.id, e2.id])
|
||||
@@ -25,7 +25,7 @@ class NonJSONAPIRelatableTests: XCTestCase {
|
||||
let e1 = NonJSONAPIEntity(id: .init(rawValue: "hello"))
|
||||
let e2 = NonJSONAPIEntity(id: .init(rawValue: "world"))
|
||||
|
||||
let entity = TestEntity2(relationships: .init(nullableOne: .init(id: e1.id), nullableMaybeOne: .init(id: e2.id), maybeOne: .init(id: e2.id), maybeMany: .init(ids: [e2.id, e1.id])))
|
||||
let entity = TestEntity2(attributes: .none, relationships: .init(nullableOne: .init(id: e1.id), nullableMaybeOne: .init(id: e2.id), maybeOne: .init(id: e2.id), maybeMany: .init(ids: [e2.id, e1.id])), meta: .none, links: .none)
|
||||
|
||||
XCTAssertEqual((entity ~> \.nullableOne)?.rawValue, "hello")
|
||||
XCTAssertEqual((entity ~> \.nullableMaybeOne)?.rawValue, "world")
|
||||
@@ -35,8 +35,8 @@ class NonJSONAPIRelatableTests: XCTestCase {
|
||||
|
||||
func test_initialization2_all_relationships_missing() {
|
||||
|
||||
let entity = TestEntity2(relationships: .init(nullableOne: .init(id: nil), nullableMaybeOne: .init(id: nil), maybeOne: nil, maybeMany: nil))
|
||||
let entity2 = TestEntity2(relationships: .init(nullableOne: .init(id: nil), nullableMaybeOne: nil, maybeOne: nil, maybeMany: nil))
|
||||
let entity = TestEntity2(attributes: .none, relationships: .init(nullableOne: .init(id: nil), nullableMaybeOne: .init(id: nil), maybeOne: nil, maybeMany: nil), meta: .none, links: .none)
|
||||
let entity2 = TestEntity2(attributes: .none, relationships: .init(nullableOne: .init(id: nil), nullableMaybeOne: nil, maybeOne: nil, maybeMany: nil), meta: .none, links: .none)
|
||||
|
||||
XCTAssertNil((entity ~> \.nullableOne))
|
||||
XCTAssertNil((entity ~> \.nullableMaybeOne))
|
||||
|
||||
@@ -15,13 +15,13 @@ class PolyTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_init_Poly1() {
|
||||
let entity = TestEntity5()
|
||||
let entity = TestEntity5(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let poly = Poly1(entity)
|
||||
XCTAssertEqual(poly.a, entity)
|
||||
}
|
||||
|
||||
func test_init_Poly2() {
|
||||
let entity = TestEntity5()
|
||||
let entity = TestEntity5(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let poly = Poly2<TestEntity5, TestEntity>(entity)
|
||||
XCTAssertEqual(poly.a, entity)
|
||||
XCTAssertNil(poly.b)
|
||||
@@ -32,7 +32,7 @@ class PolyTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_init_Poly3() {
|
||||
let entity = TestEntity5()
|
||||
let entity = TestEntity5(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let poly = Poly3<TestEntity5, TestEntity, TestEntity2>(entity)
|
||||
XCTAssertEqual(poly.a, entity)
|
||||
XCTAssertNil(poly.b)
|
||||
@@ -50,7 +50,7 @@ class PolyTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_init_Poly4() {
|
||||
let entity = TestEntity5()
|
||||
let entity = TestEntity5(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let poly = Poly4<TestEntity5, TestEntity, TestEntity2, TestEntity3>(entity)
|
||||
XCTAssertEqual(poly.a, entity)
|
||||
XCTAssertNil(poly.b)
|
||||
@@ -77,7 +77,7 @@ class PolyTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_init_Poly5() {
|
||||
let entity = TestEntity5()
|
||||
let entity = TestEntity5(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let poly = Poly5<TestEntity5, TestEntity, TestEntity2, TestEntity3, TestEntity4>(entity)
|
||||
XCTAssertEqual(poly.a, entity)
|
||||
XCTAssertNil(poly.b)
|
||||
@@ -115,7 +115,7 @@ class PolyTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_init_Poly6() {
|
||||
let entity = TestEntity5()
|
||||
let entity = TestEntity5(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let poly = Poly6<TestEntity5, TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity6>(entity)
|
||||
XCTAssertEqual(poly.a, entity)
|
||||
XCTAssertNil(poly.b)
|
||||
@@ -166,7 +166,7 @@ class PolyTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_init_Poly7() {
|
||||
let entity = TestEntity5()
|
||||
let entity = TestEntity5(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let poly = Poly7<TestEntity5, TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity6, TestEntity7>(entity)
|
||||
XCTAssertEqual(poly.a, entity)
|
||||
XCTAssertNil(poly.b)
|
||||
|
||||
@@ -11,10 +11,10 @@ import JSONAPI
|
||||
class RelationshipTests: XCTestCase {
|
||||
|
||||
func test_initToManyWithEntities() {
|
||||
let entity1 = TestEntity1()
|
||||
let entity2 = TestEntity1()
|
||||
let entity3 = TestEntity1()
|
||||
let entity4 = TestEntity1()
|
||||
let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity2 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity3 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity4 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let relationship = ToManyRelationship<TestEntity1, NoMetadata, NoLinks>(entities: [entity1, entity2, entity3, entity4])
|
||||
|
||||
XCTAssertEqual(relationship.ids.count, 4)
|
||||
@@ -22,10 +22,10 @@ class RelationshipTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_initToManyWithRelationships() {
|
||||
let entity1 = TestEntity1()
|
||||
let entity2 = TestEntity1()
|
||||
let entity3 = TestEntity1()
|
||||
let entity4 = TestEntity1()
|
||||
let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity2 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity3 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity4 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let relationship = ToManyRelationship<TestEntity1, NoMetadata, NoLinks>(pointers: [entity1.pointer, entity2.pointer, entity3.pointer, entity4.pointer])
|
||||
|
||||
XCTAssertEqual(relationship.ids.count, 4)
|
||||
@@ -151,7 +151,7 @@ extension RelationshipTests {
|
||||
}
|
||||
|
||||
func test_ToOneNullableIsEqualToNonNullableIfNotNil() {
|
||||
let entity = TestEntity1()
|
||||
let entity = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let relationship1 = ToOneNonNullable(entity: entity)
|
||||
let relationship2 = ToOneNullable(entity: entity)
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ class ResourceBodyTests: XCTestCase {
|
||||
|
||||
func test_initializers() {
|
||||
let articles = [
|
||||
Article(attributes: .init(title: "hello")),
|
||||
Article(attributes: .init(title: "world"))
|
||||
Article(attributes: .init(title: "hello"), relationships: .none, meta: .none, links: .none),
|
||||
Article(attributes: .init(title: "world"), relationships: .none, meta: .none, links: .none)
|
||||
]
|
||||
let _ = SingleResourceBody(entity: articles[0])
|
||||
let _ = ManyResourceBody(entities: articles)
|
||||
@@ -25,7 +25,7 @@ class ResourceBodyTests: XCTestCase {
|
||||
data: single_resource_body)
|
||||
|
||||
XCTAssertEqual(body.value, Article(id: Id<String, Article>(rawValue: "1"),
|
||||
attributes: ArticleType.Attributes(title: try! .init(rawValue: "JSON:API paints my bikeshed!"))))
|
||||
attributes: ArticleType.Attributes(title: try! .init(rawValue: "JSON:API paints my bikeshed!")), relationships: .none, meta: .none, links: .none))
|
||||
}
|
||||
|
||||
func test_singleResourceBody_encode() {
|
||||
@@ -38,9 +38,9 @@ class ResourceBodyTests: XCTestCase {
|
||||
data: many_resource_body)
|
||||
|
||||
XCTAssertEqual(body.values, [
|
||||
Article(id: .init(rawValue: "1"), attributes: try! .init(title: .init(rawValue: "JSON:API paints my bikeshed!"))),
|
||||
Article(id: .init(rawValue: "2"), attributes: try! .init(title: .init(rawValue: "Sick"))),
|
||||
Article(id: .init(rawValue: "3"), attributes: try! .init(title: .init(rawValue: "Hello World")))
|
||||
Article(id: .init(rawValue: "1"), attributes: try! .init(title: .init(rawValue: "JSON:API paints my bikeshed!")), relationships: .none, meta: .none, links: .none),
|
||||
Article(id: .init(rawValue: "2"), attributes: try! .init(title: .init(rawValue: "Sick")), relationships: .none, meta: .none, links: .none),
|
||||
Article(id: .init(rawValue: "3"), attributes: try! .init(title: .init(rawValue: "Hello World")), relationships: .none, meta: .none, links: .none)
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user