Adding Document Decoding Errors for some common problems

This commit is contained in:
Mathew Polzin
2019-11-10 23:02:26 -08:00
parent 4dc30ddc1c
commit 2eecf95995
12 changed files with 483 additions and 15 deletions
@@ -287,6 +287,30 @@ extension ResourceObjectDecodingErrorTests {
}
}
// MARK: - JSON:API Type
extension ResourceObjectDecodingErrorTests {
func test_wrongType() {
XCTAssertThrowsError(try testDecoder.decode(
TestEntity2.self,
from: entity_is_wrong_type
)) { error in
XCTAssertEqual(
error as? ResourceObjectDecodingError,
ResourceObjectDecodingError(
subjectName: "self",
cause: .jsonTypeMismatch(expectedType: "fourteenth_test_entities", foundType: "not_correct_type"),
location: .type
)
)
XCTAssertEqual(
(error as? ResourceObjectDecodingError)?.description,
#"found JSON:API type "not_correct_type" but expected "fourteenth_test_entities""#
)
}
}
}
// MARK: - Test Types
extension ResourceObjectDecodingErrorTests {
enum TestEntityType: ResourceObjectDescription {
@@ -533,6 +533,17 @@ let entity_attribute_is_wrong_type3 = """
}
""".data(using: .utf8)!
let entity_is_wrong_type = """
{
"id": "1",
"type": "not_correct_type",
"attributes": {
"required": "hello",
"yetAnother": 101
}
}
""".data(using: .utf8)!
let entity_attributes_entirely_missing = """
{
"id": "1",