mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
Add missing unidentified decoding tests
This commit is contained in:
+1
-1
@@ -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.
|
||||
|
||||
********/
|
||||
|
||||
|
||||
@@ -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)!
|
||||
|
||||
Reference in New Issue
Block a user