From 28f664326d328d2c00f4dcdffcaaa6c340c3b071 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Wed, 12 Dec 2018 21:05:07 -0800 Subject: [PATCH] Added a couple of tests --- Tests/JSONAPITests/Entity/EntityTests.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Tests/JSONAPITests/Entity/EntityTests.swift b/Tests/JSONAPITests/Entity/EntityTests.swift index 70a480d..b75b5e1 100644 --- a/Tests/JSONAPITests/Entity/EntityTests.swift +++ b/Tests/JSONAPITests/Entity/EntityTests.swift @@ -26,7 +26,10 @@ class EntityTests: XCTestCase { } func test_optional_relationship_operator_access() { - + let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none) + let entity = TestEntity9(attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(entity: entity1, meta: .none, links: .none), optionalOne: .init(entity: entity1, meta: .none, links: .none), optionalNullableOne: nil, optionalMany: .init(entities: [entity1, entity1], meta: .none, links: .none)), meta: .none, links: .none) + + XCTAssertEqual(entity ~> \.optionalOne, entity1.id) } func test_toMany_relationship_operator_access() { @@ -39,7 +42,10 @@ class EntityTests: XCTestCase { } func test_optionalToMany_relationship_opeartor_access() { + let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none) + let entity = TestEntity9(attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(entity: entity1, meta: .none, links: .none), optionalOne: nil, optionalNullableOne: nil, optionalMany: .init(entities: [entity1, entity1], meta: .none, links: .none)), meta: .none, links: .none) + XCTAssertEqual(entity ~> \.optionalMany, [entity1.id, entity1.id]) } func test_relationshipIds() { @@ -59,6 +65,12 @@ class EntityTests: XCTestCase { XCTAssertEqual(pointer.links.link1.url, "ok") } + func test_unidentifiedEntityAttributeAccess() { + let entity = UnidentifiedTestEntity(attributes: .init(me: "hello"), relationships: .none, meta: .none, links: .none) + + XCTAssertEqual(entity[\.me], "hello") + } + func test_initialization() { 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)