Debian Codegraph @

__tests__/internal/move-after-handle-request/regressions/1318-linkage-data-bug-test.js

raw
1 import { Server, Model, hasMany, belongsTo, JSONAPISerializer } from "miragejs";
2
3 describe("Integration | Server | Regressions | 1318 Linkage bug test", function () {
4 let server;
5
6 beforeEach(function () {
7 server = new Server({
8 environment: "test",
9 models: {
10 happyUser: Model.extend({
11 happyLicenses: hasMany(),
12 }),
13 happyLicense: Model.extend({
14 happyUser: belongsTo(),
15 happySubscription: belongsTo(),
16 }),
17 happySubscription: Model.extend({
18 happyLicenses: hasMany(),
19 }),
20 },
21 serializers: {
22 application: JSONAPISerializer,
23 },
24 routes() {
25 this.resource("happy-users");
26 },
27 });
28 });
29
30 afterEach(function () {
31 server.shutdown();
32 });
33
34 test("it works", async () => {
35 let happySubscription = server.create("happy-subscription");
36
37 let user1 = server.create("happy-user");
38 server.create("happy-license", {
39 happyUser: user1,
40 happySubscription,
41 });
42
43 let user2 = server.create("happy-user");
44 server.create("happy-license", {
45 happyUser: user2,
46 happySubscription,
47 });
48
49 expect.assertions(1);
50
51 let res = await fetch(
52 "/happy-users/1?include=happy-licenses.happy-subscription"
53 );
54 let json = await res.json();
55
56 expect(json.included).toEqual([
57 {
58 id: "1",
59 type: "happy-licenses",
60 attributes: {},
61 relationships: {
62 "happy-subscription": {
63 data: {
64 type: "happy-subscriptions",
65 id: "1",
66 },
67 },
68 },
69 },
70 {
71 id: "1",
72 type: "happy-subscriptions",
73 attributes: {},
74 },
75 ]);
76 });
77 });