| 1 |
import { Server, Model, JSONAPISerializer } from "miragejs"; |
| 2 |
import FunctionRouteHandler from "@lib/route-handlers/function"; |
| 3 |
|
| 4 |
describe("Integration | Route handlers | Assertions", () => { |
| 5 |
let server; |
| 6 |
beforeEach(() => { |
| 7 |
server = new Server({ |
| 8 |
environment: "development", |
| 9 |
models: { |
| 10 |
user: Model.extend({}), |
| 11 |
comment: Model.extend({}), |
| 12 |
}, |
| 13 |
serializers: { |
| 14 |
application: JSONAPISerializer, |
| 15 |
}, |
| 16 |
}); |
| 17 |
server.timing = 0; |
| 18 |
server.logging = false; |
| 19 |
|
| 20 |
server.post("/users"); |
| 21 |
}); |
| 22 |
|
| 23 |
afterEach(() => { |
| 24 |
server.shutdown(); |
| 25 |
}); |
| 26 |
|
| 27 |
test("a helpful assert is thrown if a relationship passed in a request is not a defined association on the posted model", async () => { |
| 28 |
expect.assertions(1); |
| 29 |
|
| 30 |
let request = { |
| 31 |
requestHeaders: {}, |
| 32 |
method: "POST", |
| 33 |
url: "/users", |
| 34 |
requestBody: JSON.stringify({ |
| 35 |
data: { |
| 36 |
type: "user", |
| 37 |
attributes: { |
| 38 |
name: "Jacob Dylan", |
| 39 |
}, |
| 40 |
relationships: { |
| 41 |
comments: { |
| 42 |
data: { |
| 43 |
type: "comment", |
| 44 |
name: "Bob Dylan", |
| 45 |
}, |
| 46 |
}, |
| 47 |
}, |
| 48 |
}, |
| 49 |
}), |
| 50 |
}; |
| 51 |
|
| 52 |
let functionHandler = new FunctionRouteHandler( |
| 53 |
server.schema, |
| 54 |
server.serializerOrRegistry |
| 55 |
); |
| 56 |
functionHandler.path = "/users"; |
| 57 |
functionHandler.request = request; |
| 58 |
|
| 59 |
expect(function () { |
| 60 |
functionHandler.normalizedRequestAttrs(); |
| 61 |
}).toThrow(); |
| 62 |
}); |
| 63 |
}); |