| 1 |
import { Server, Model, Factory } from "miragejs"; |
| 2 |
|
| 3 |
describe("External | Shared | Fixtures and factories", () => { |
| 4 |
let server; |
| 5 |
|
| 6 |
beforeEach(() => { |
| 7 |
server = new Server({ |
| 8 |
environment: "development", |
| 9 |
models: { |
| 10 |
author: Model, |
| 11 |
}, |
| 12 |
factories: { |
| 13 |
author: Factory, |
| 14 |
}, |
| 15 |
seeds() {}, |
| 16 |
fixtures: { |
| 17 |
authors: [{ id: 1, name: "Zelda" }], |
| 18 |
}, |
| 19 |
}); |
| 20 |
}); |
| 21 |
|
| 22 |
afterEach(function () { |
| 23 |
server.shutdown(); |
| 24 |
}); |
| 25 |
|
| 26 |
test(`[regression] When loaded, fixture files correctly update the database's autoincrement id`, () => { |
| 27 |
server.loadFixtures(); |
| 28 |
|
| 29 |
server.schema.authors.create({}); |
| 30 |
|
| 31 |
let authors = server.db.authors; |
| 32 |
|
| 33 |
expect(authors).toHaveLength(2); |
| 34 |
expect(authors.map((a) => a.id)).toEqual(["1", "2"]); |
| 35 |
}); |
| 36 |
}); |