From d6e82fab557bb515442320b893f574632e5a2dac Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Fri, 21 Dec 2018 08:53:55 -0800 Subject: [PATCH] get id and type tests into the encoded entity test function --- .../Test Helpers/EncodedAttributeTest.swift | 2 +- .../Test Helpers/EncodedEntityPropertyTest.swift | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Tests/JSONAPITests/Test Helpers/EncodedAttributeTest.swift b/Tests/JSONAPITests/Test Helpers/EncodedAttributeTest.swift index de0a502..6bb3777 100644 --- a/Tests/JSONAPITests/Test Helpers/EncodedAttributeTest.swift +++ b/Tests/JSONAPITests/Test Helpers/EncodedAttributeTest.swift @@ -19,7 +19,7 @@ private struct Wrapper: Coda } /// This function attempts to just cast to the type, so it only works -/// for Attributes of primitive types. +/// for Attributes of primitive types (primitive to JSON). func testEncodedPrimitive(attribute: TransformedAttribute) { let encodedAttributeData = encoded(value: Wrapper(x: attribute)) let wrapperObject = try! JSONSerialization.jsonObject(with: encodedAttributeData, options: []) as! [String: Any] diff --git a/Tests/JSONAPITests/Test Helpers/EncodedEntityPropertyTest.swift b/Tests/JSONAPITests/Test Helpers/EncodedEntityPropertyTest.swift index b623ca8..c15c43f 100644 --- a/Tests/JSONAPITests/Test Helpers/EncodedEntityPropertyTest.swift +++ b/Tests/JSONAPITests/Test Helpers/EncodedEntityPropertyTest.swift @@ -17,6 +17,18 @@ func testEncoded(entity: E) { XCTAssertNotNil(jsonDict) + let jsonId = jsonDict?["id"] + + if E.EntityRawIdType.self == Unidentified.self { + XCTAssertNil(jsonId) + } else { + XCTAssertNotNil(jsonId) + } + + let jsonType = jsonDict?["type"] as? String + + XCTAssertEqual(jsonType, E.type) + let jsonAttributes = jsonDict?["attributes"] as? [String: Any] if E.Attributes.self == NoAttributes.self {