Add missing unidentified decoding tests

This commit is contained in:
Mathew Polzin
2018-11-16 08:23:36 -08:00
parent 69faa1b33f
commit 7bb5c9ac9f
3 changed files with 47 additions and 4 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ import JSONAPI
/*******
Please enjoy these examples, but allow me the lack of error checking and forced casting for the sake of brevity.
Please enjoy these examples, but allow me the forced casting and the lack of error checking for the sake of brevity.
********/
+30 -3
View File
@@ -58,7 +58,11 @@ class EntityTests: XCTestCase {
XCTAssertEqual(e[\.floater], 123.321)
}
}
// MARK: - Encode/Decode
extension EntityTests {
func test_EntitySomeRelationshipsNoAttributes() {
let entity = try? JSONDecoder().decode(TestEntity3.self, from: entity_some_relationships_no_attributes)
@@ -224,10 +228,30 @@ extension EntityTests {
// MARK: Unidentified
extension EntityTests {
func test_UnidentifiedEntity() {
let entity = try? JSONDecoder().decode(UnidentifiedTestEntity.self, from: entity_unidentified)
XCTAssertNotNil(entity)
guard let e = entity else { return }
XCTAssertNil(e[\.me])
XCTAssertEqual(e.id, Unidentified())
}
func test_UnidentifiedEntityWithAttributes() {
let entity = try? JSONDecoder().decode(UnidentifiedTestEntity.self, from: entity_unidentified_with_attributes)
XCTAssertNotNil(entity)
guard let e = entity else { return }
XCTAssertEqual(e[\.me], "unknown")
XCTAssertEqual(e.id, Unidentified())
}
}
// MARK: Test Types
// MARK: - Test Types
extension EntityTests {
enum TestEntityType1: EntityDescription {
@@ -374,7 +398,10 @@ extension EntityTests {
enum UnidentifiedTestEntityType: EntityDescription {
public static var type: String { return "unidentified_test_entities" }
typealias Attributes = NoAttributes
struct Attributes: JSONAPI.Attributes {
let me: Attribute<String>?
}
typealias Relationships = NoRelatives
}
@@ -205,3 +205,19 @@ let entity_self_ref_relationship = """
}
}
""".data(using: .utf8)!
let entity_unidentified = """
{
"type": "unidentified_test_entities",
"attributes": {}
}
""".data(using: .utf8)!
let entity_unidentified_with_attributes = """
{
"type": "unidentified_test_entities",
"attributes": {
"me": "unknown"
}
}
""".data(using: .utf8)!