diff --git a/Tests/JSONAPITests/Error/BasicJSONAPIErrorTests.swift b/Tests/JSONAPITests/Error/BasicJSONAPIErrorTests.swift index e726143..05bcf2f 100644 --- a/Tests/JSONAPITests/Error/BasicJSONAPIErrorTests.swift +++ b/Tests/JSONAPITests/Error/BasicJSONAPIErrorTests.swift @@ -8,6 +8,7 @@ import Foundation @testable import JSONAPI import XCTest +import Poly final class BasicJSONAPIErrorTests: XCTestCase { func test_initAndEquality() { @@ -89,4 +90,42 @@ final class BasicJSONAPIErrorTests: XCTestCase { XCTAssertEqual(wellPopulatedError.definedFields["pointer"], "/data/attributes/id") XCTAssertEqual(wellPopulatedError.definedFields["parameter"], "id") } + + func test_decodeAFewExamples() { + let datas = [ +""" +{ + "id": "hello" +} +""", +""" +{ + "id": 1234 +} +""", +""" +{ + "status": "404", + "title": "Missing", + "links": { + "about": "https://google.com" + } +} +""", +""" +{ + "status": 404 +} +""" + ].map { $0.data(using: .utf8)! } + + let errors = datas + .map { decoded(type: BasicJSONAPIError>.self, data: $0) } + + XCTAssertEqual(errors[0].payload?.id, .init("hello")) + XCTAssertEqual(errors[1].payload?.id, .init(1234)) + XCTAssertEqual(errors[2].payload?.status, "404") + XCTAssertEqual(errors[2].payload?.title, "Missing") + XCTAssertEqual(errors[3], .unknown) + } }