2018-11-27 11:45:15 -08:00
|
|
|
//: [Previous](@previous)
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
import JSONAPI
|
2019-01-13 18:35:20 -08:00
|
|
|
import JSONAPITesting
|
2018-11-27 11:45:15 -08:00
|
|
|
|
|
|
|
|
/*******
|
|
|
|
|
|
|
|
|
|
Please enjoy these examples, but allow me the forced casting and the lack of error checking for the sake of brevity.
|
|
|
|
|
|
|
|
|
|
********/
|
|
|
|
|
|
|
|
|
|
// MARK: - Literal Expressibility
|
2019-01-13 18:35:20 -08:00
|
|
|
// The JSONAPITesting framework provides literal expressibility for key types to
|
2018-11-27 11:45:15 -08:00
|
|
|
// make creating tests easier
|
2018-12-10 22:45:28 -08:00
|
|
|
let dog = Dog(id: "1234", attributes: Dog.Attributes(name: "Buddy"), relationships: Dog.Relationships(owner: nil), meta: .none, links: .none)
|
2018-11-27 13:33:55 -08:00
|
|
|
|
|
|
|
|
// MARK: - JSON API structure checking
|
2019-01-13 18:35:20 -08:00
|
|
|
// The JSONAPITesting framework provides a `check` function for each Entity type
|
2018-11-27 13:33:55 -08:00
|
|
|
// that uses reflection to catch mistakes that are not forbidden by
|
|
|
|
|
// Swift's type system but will result in unexpected results when
|
|
|
|
|
// encoding/decoding. It is a good idea to add a `check` to each of
|
|
|
|
|
// your unit tests that create Entities.
|
|
|
|
|
try Dog.check(dog)
|