get id and type tests into the encoded entity test function

This commit is contained in:
Mathew Polzin
2018-12-21 08:53:55 -08:00
parent 5fa9848f02
commit d6e82fab55
2 changed files with 13 additions and 1 deletions
@@ -19,7 +19,7 @@ private struct Wrapper<Value: Equatable & Codable, Transform: Transformer>: 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<Value: Equatable & Codable, Transform: Transformer>(attribute: TransformedAttribute<Value, Transform>) {
let encodedAttributeData = encoded(value: Wrapper<Value, Transform>(x: attribute))
let wrapperObject = try! JSONSerialization.jsonObject(with: encodedAttributeData, options: []) as! [String: Any]
@@ -17,6 +17,18 @@ func testEncoded<E: EntityType>(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 {