| 1 |
import { Server, Model, Collection } from "miragejs"; |
| 2 |
|
| 3 |
describe("External | Shared | ORM | #all", function () { |
| 4 |
let User; |
| 5 |
let server; |
| 6 |
|
| 7 |
beforeEach(() => { |
| 8 |
User = Model.extend(); |
| 9 |
server = new Server({ |
| 10 |
environment: "test", |
| 11 |
models: { |
| 12 |
user: User, |
| 13 |
}, |
| 14 |
}); |
| 15 |
}); |
| 16 |
|
| 17 |
afterEach(() => { |
| 18 |
server.shutdown(); |
| 19 |
}); |
| 20 |
|
| 21 |
test("it can return all models", () => { |
| 22 |
server.db.loadData({ |
| 23 |
users: [ |
| 24 |
{ id: 1, name: "Link" }, |
| 25 |
{ id: 2, name: "Zelda" }, |
| 26 |
], |
| 27 |
}); |
| 28 |
|
| 29 |
let users = server.schema.users.all(); |
| 30 |
|
| 31 |
expect(users instanceof Collection).toBeTruthy(); |
| 32 |
expect(users.models[0] instanceof User).toBeTruthy(); |
| 33 |
expect(users.models).toHaveLength(2); |
| 34 |
expect(users.models[1].attrs).toEqual({ id: "2", name: "Zelda" }); |
| 35 |
}); |
| 36 |
|
| 37 |
test("it returns an empty array when no models exist", () => { |
| 38 |
let users = server.schema.users.all(); |
| 39 |
|
| 40 |
expect(users instanceof Collection).toBeTruthy(); |
| 41 |
expect(users.modelName).toEqual("user"); |
| 42 |
expect(users.models).toHaveLength(0); |
| 43 |
}); |
| 44 |
}); |