mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
get id and type tests into the encoded entity test function
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user