Debian Codegraph @

__tests__/external/shared/orm/destroy-test.js

raw
1 import { Server, Model } from "miragejs";
2
3 describe("External | Shared | ORM | destroy", () => {
4 let server;
5
6 beforeEach(() => {
7 server = new Server({
8 environment: "test",
9 models: {
10 user: Model,
11 },
12 });
13
14 server.db.loadData({
15 users: [
16 { id: 1, name: "Link", evil: false },
17 { id: 2, name: "Link", location: "Hyrule", evil: false },
18 { id: 3, name: "Zelda", location: "Hyrule", evil: false },
19 ],
20 });
21 });
22
23 afterEach(() => {
24 server.shutdown();
25 });
26
27 test("destroying a model removes the associated record from the db", () => {
28 expect(server.db.users).toHaveLength(3);
29
30 let link = server.schema.users.find(1);
31 link.destroy();
32
33 expect(server.db.users.find(1)).toBeNull();
34 expect(server.db.users).toHaveLength(2);
35 });
36
37 test("destroying a collection removes the associated records from the db", () => {
38 expect(server.db.users).toHaveLength(3);
39
40 let users = server.schema.users.all();
41 users.destroy();
42
43 expect(server.db.users).toBeEmpty();
44 });
45 });