|
|
|
@@ -11,7 +11,7 @@ import JSONAPI
|
|
|
|
|
class DocumentTests: XCTestCase {
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNull() {
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article?>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article?>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_null)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -20,15 +20,36 @@ class DocumentTests: XCTestCase {
|
|
|
|
|
XCTAssertEqual(document.body.meta, NoMetadata())
|
|
|
|
|
XCTAssertNil(document.body.primaryData?.value)
|
|
|
|
|
XCTAssertEqual(document.body.includes?.count, 0)
|
|
|
|
|
XCTAssertEqual(document.body.links, NoLinks())
|
|
|
|
|
XCTAssertEqual(document.apiDescription, .none)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNull_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article?>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article?>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_null)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNullWithAPIDescription() {
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article?>, NoMetadata, NoLinks, NoIncludes, TestAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_null_with_api_description)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
|
XCTAssertNil(document.body.errors)
|
|
|
|
|
XCTAssertNotNil(document.body.primaryData)
|
|
|
|
|
XCTAssertEqual(document.body.meta, NoMetadata())
|
|
|
|
|
XCTAssertNil(document.body.primaryData?.value)
|
|
|
|
|
XCTAssertEqual(document.body.includes?.count, 0)
|
|
|
|
|
XCTAssertEqual(document.body.links, NoLinks())
|
|
|
|
|
XCTAssertEqual(document.apiDescription.version, "1.0")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNullWithAPIDescription_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article?>, NoMetadata, NoLinks, NoIncludes, TestAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_null_with_api_description)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNonOptionalFailsOnNull() {
|
|
|
|
|
XCTAssertThrowsError(try JSONDecoder().decode(Document<SingleResourceBody<Article>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
XCTAssertThrowsError(try JSONDecoder().decode(Document<SingleResourceBody<Article>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
from: single_document_null))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -36,7 +57,7 @@ class DocumentTests: XCTestCase {
|
|
|
|
|
// MARK: - Error Document Tests
|
|
|
|
|
extension DocumentTests {
|
|
|
|
|
func test_unknownErrorDocumentNoMeta() {
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: error_document_no_metadata)
|
|
|
|
|
|
|
|
|
|
XCTAssertTrue(document.body.isError)
|
|
|
|
@@ -56,12 +77,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentNoMeta_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: error_document_no_metadata)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentMissingMeta() {
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self, data: error_document_no_metadata)
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self, data: error_document_no_metadata)
|
|
|
|
|
|
|
|
|
|
XCTAssertTrue(document.body.isError)
|
|
|
|
|
XCTAssertNil(document.body.meta)
|
|
|
|
@@ -80,11 +101,11 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentMissingMeta_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self, data: error_document_no_metadata)
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self, data: error_document_no_metadata)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_errorDocumentNoMeta() {
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, NoMetadata, NoLinks, NoIncludes, TestError>.self,
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, TestError>.self,
|
|
|
|
|
data: error_document_no_metadata)
|
|
|
|
|
|
|
|
|
|
XCTAssertTrue(document.body.isError)
|
|
|
|
@@ -104,12 +125,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_errorDocumentNoMeta_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, NoMetadata, NoLinks, NoIncludes, TestError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, TestError>.self,
|
|
|
|
|
data: error_document_no_metadata)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentWithMeta() {
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: error_document_with_metadata)
|
|
|
|
|
|
|
|
|
|
XCTAssertTrue(document.body.isError)
|
|
|
|
@@ -128,12 +149,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentWithMeta_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: error_document_with_metadata)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentWithMetaWithLinks() {
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: error_document_with_metadata_with_links)
|
|
|
|
|
|
|
|
|
|
XCTAssertTrue(document.body.isError)
|
|
|
|
@@ -156,12 +177,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentWithMetaWithLinks_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: error_document_with_metadata_with_links)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentWithLinks() {
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: error_document_with_links)
|
|
|
|
|
|
|
|
|
|
XCTAssertTrue(document.body.isError)
|
|
|
|
@@ -182,12 +203,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentWithLinks_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: error_document_with_links)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentMissingLinks() {
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: error_document_no_metadata)
|
|
|
|
|
|
|
|
|
|
XCTAssertTrue(document.body.isError)
|
|
|
|
@@ -205,7 +226,7 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_unknownErrorDocumentMissingLinks_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: error_document_no_metadata)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -213,7 +234,7 @@ extension DocumentTests {
|
|
|
|
|
// MARK: - Meta Document Tests
|
|
|
|
|
extension DocumentTests {
|
|
|
|
|
func test_metaDataDocument() {
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: metadata_document)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -224,12 +245,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_metaDataDocument_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: metadata_document)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_metaDataDocumentWithLinks() {
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: metadata_document_with_links)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -244,14 +265,14 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_metaDataDocumentWithLinks_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<NoResourceBody, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: metadata_document_with_links)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_metaDocumentMissingMeta() {
|
|
|
|
|
XCTAssertThrowsError(try JSONDecoder().decode(Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self, from: metadata_document_missing_metadata))
|
|
|
|
|
XCTAssertThrowsError(try JSONDecoder().decode(Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self, from: metadata_document_missing_metadata))
|
|
|
|
|
|
|
|
|
|
XCTAssertThrowsError(try JSONDecoder().decode(Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self, from: metadata_document_missing_metadata2))
|
|
|
|
|
XCTAssertThrowsError(try JSONDecoder().decode(Document<NoResourceBody, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self, from: metadata_document_missing_metadata2))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -259,7 +280,7 @@ extension DocumentTests {
|
|
|
|
|
// MARK: Single Document Tests
|
|
|
|
|
extension DocumentTests {
|
|
|
|
|
func test_singleDocumentNoIncludes() {
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_no_includes)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -271,12 +292,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludes_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_no_includes)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesOptionalNotNull() {
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article?>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article?>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_no_includes)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -288,12 +309,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesOptionalNotNull_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article?>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article?>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_no_includes)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesWithMetadata() {
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_no_includes_with_metadata)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -305,12 +326,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesWithMetadata_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_no_includes_with_metadata)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesWithLinks() {
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, NoMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, NoMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_no_includes_with_links)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -327,12 +348,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesWithLinks_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, NoMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, NoMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_no_includes_with_links)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesWithMetadataWithLinks() {
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_no_includes_with_metadata_with_links)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -349,20 +370,20 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesWithMetadataWithLinks_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_no_includes_with_metadata_with_links)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesWithMetadataMissingLinks() {
|
|
|
|
|
XCTAssertThrowsError(try JSONDecoder().decode(Document<SingleResourceBody<Article>, TestPageMetadata, TestLinks, NoIncludes, UnknownJSONAPIError>.self, from: single_document_no_includes_with_metadata))
|
|
|
|
|
XCTAssertThrowsError(try JSONDecoder().decode(Document<SingleResourceBody<Article>, TestPageMetadata, TestLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self, from: single_document_no_includes_with_metadata))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesMissingMetadata() {
|
|
|
|
|
XCTAssertThrowsError(try JSONDecoder().decode(Document<SingleResourceBody<Article>, TestPageMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self, from: single_document_no_includes))
|
|
|
|
|
XCTAssertThrowsError(try JSONDecoder().decode(Document<SingleResourceBody<Article>, TestPageMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self, from: single_document_no_includes))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentSomeIncludes() {
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, NoMetadata, NoLinks, Include1<Author>, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, NoMetadata, NoLinks, Include1<Author>, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_some_includes)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -375,12 +396,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentSomeIncludes_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, NoMetadata, NoLinks, Include1<Author>, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, NoMetadata, NoLinks, Include1<Author>, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_some_includes)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentSomeIncludesWithMetadata() {
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, TestPageMetadata, NoLinks, Include1<Author>, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, TestPageMetadata, NoLinks, Include1<Author>, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_some_includes_with_metadata)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -394,12 +415,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentSomeIncludesWithMetadata_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, TestPageMetadata, NoLinks, Include1<Author>, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, TestPageMetadata, NoLinks, Include1<Author>, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_some_includes_with_metadata)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesWithSomeIncludesWithMetadataWithLinks() {
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, TestPageMetadata, TestLinks, Include1<Author>, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Article>, TestPageMetadata, TestLinks, Include1<Author>, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_some_includes_with_metadata_with_links)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -417,7 +438,7 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocumentNoIncludesWithSomeIncludesMetadataWithLinks_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, TestPageMetadata, TestLinks, Include1<Author>, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Article>, TestPageMetadata, TestLinks, Include1<Author>, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: single_document_some_includes_with_metadata_with_links)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -426,21 +447,21 @@ extension DocumentTests {
|
|
|
|
|
extension DocumentTests {
|
|
|
|
|
func test_singleDocument_PolyPrimaryResource() {
|
|
|
|
|
let article = Article(id: Id(rawValue: "1"), relationships: .init(author: ToOneRelationship(id: Id(rawValue: "33"))))
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Poly2<Article, Author>>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self, data: single_document_no_includes)
|
|
|
|
|
let document = decoded(type: Document<SingleResourceBody<Poly2<Article, Author>>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self, data: single_document_no_includes)
|
|
|
|
|
|
|
|
|
|
XCTAssertEqual(document.body.primaryData?.value[Article.self], article)
|
|
|
|
|
XCTAssertNil(document.body.primaryData?.value[Author.self])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_singleDocument_PolyPrimaryResource_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Poly2<Article, Author>>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self, data: single_document_no_includes)
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<SingleResourceBody<Poly2<Article, Author>>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self, data: single_document_no_includes)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: - ManyResourceBody Tests
|
|
|
|
|
extension DocumentTests {
|
|
|
|
|
func test_manyDocumentNoIncludes() {
|
|
|
|
|
let document = decoded(type: Document<ManyResourceBody<Article>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<ManyResourceBody<Article>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: many_document_no_includes)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -454,12 +475,12 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_manyDocumentNoIncludes_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<ManyResourceBody<Article>, NoMetadata, NoLinks, NoIncludes, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<ManyResourceBody<Article>, NoMetadata, NoLinks, NoIncludes, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: many_document_no_includes)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_manyDocumentSomeIncludes() {
|
|
|
|
|
let document = decoded(type: Document<ManyResourceBody<Article>, NoMetadata, NoLinks, Include1<Author>, UnknownJSONAPIError>.self,
|
|
|
|
|
let document = decoded(type: Document<ManyResourceBody<Article>, NoMetadata, NoLinks, Include1<Author>, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: many_document_some_includes)
|
|
|
|
|
|
|
|
|
|
XCTAssertFalse(document.body.isError)
|
|
|
|
@@ -477,7 +498,7 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test_manyDocumentSomeIncludes_encode() {
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<ManyResourceBody<Article>, NoMetadata, NoLinks, Include1<Author>, UnknownJSONAPIError>.self,
|
|
|
|
|
test_DecodeEncodeEquality(type: Document<ManyResourceBody<Article>, NoMetadata, NoLinks, Include1<Author>, NoAPIDescription, UnknownJSONAPIError>.self,
|
|
|
|
|
data: many_document_some_includes)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -520,6 +541,8 @@ extension DocumentTests {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typealias TestAPIDescription = APIDescription<NoMetadata>
|
|
|
|
|
|
|
|
|
|
enum TestError: JSONAPIError {
|
|
|
|
|
case unknownError
|
|
|
|
|
case basic(BasicError)
|
|
|
|
|