More failure test cases. pretty ok test coverage at this point.

This commit is contained in:
Mathew Polzin
2018-11-23 20:44:12 -08:00
parent b97649fab6
commit af1aca9cf4
3 changed files with 40 additions and 1 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ The primary goals of this framework are:
- [x] Support ability to distinguish between `Attributes` fields that are optional (i.e. the key might not be there) and `Attributes` values that are optional (i.e. the key is guaranteed to be there but it might be `null`).
- [x] Fix `ToOneRelationship` so that it is possible to specify an optional relationship where the value is `null` rather than the key being omitted.
- [x] Conform to `CustomStringConvertible`
- [ ] More tests around failing to decode improperly structured JSON (not bad JSON, but JSON that is not to spec)
- [x] More tests around failing to decode improperly structured JSON (not bad JSON, but JSON that is not to spec)
- [ ] Use `KeyPath` to specify `Includes` thus creating type safety around the relationship between a primary resource type and the types of included resources????
- [x] For `NoIncludes`, do not even loop over the "included" JSON API section if it exists.
- [ ] Property-based testing (using `SwiftCheck`)
@@ -61,6 +61,17 @@ extension RelationshipTests {
}
}
// MARK: Failure tests
extension RelationshipTests {
func test_ToManyTypeMismatch() {
XCTAssertThrowsError(try JSONDecoder().decode(ToManyRelationship<TestEntity1>.self, from: to_many_relationship_type_mismatch))
}
func test_ToOneTypeMismatch() {
XCTAssertThrowsError(try JSONDecoder().decode(ToOneRelationship<TestEntity1>.self, from: to_one_relationship_type_mismatch))
}
}
// MARK: - Test types
extension RelationshipTests {
enum TestEntityType1: EntityDescription {
@@ -14,6 +14,15 @@ let to_one_relationship = """
}
""".data(using: .utf8)!
let to_one_relationship_type_mismatch = """
{
"data": {
"type": "not_a_type",
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
}
}
""".data(using: .utf8)!
let to_many_relationship = """
{
"data": [
@@ -32,3 +41,22 @@ let to_many_relationship = """
]
}
""".data(using: .utf8)!
let to_many_relationship_type_mismatch = """
{
"data": [
{
"type": "test_entity1",
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
},
{
"type": "test_entity1",
"id": "90F03B69-4DF1-467F-B52E-B0C9E44FC333"
},
{
"type": "not_a_type",
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
}
]
}
""".data(using: .utf8)!