mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
Adding Document Decoding Errors for some common problems
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user