Debian Codegraph @

__tests__/external/shared/orm/mixed/3-one-to-many-polymorphic/association-create-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Mixed | One To Many Polymorphic | association #create", () => {
4 let helper;
5 beforeEach(() => {
6 helper = new Helper();
7 });
8 afterEach(() => {
9 helper.shutdown();
10 });
11
12 /*
13 The model can create a has-many association, for all states
14 */
15 states.forEach((state) => {
16 test(`a ${state} can create an associated parent`, () => {
17 let [user] = helper[state]();
18 let initialCount = user.things.models.length;
19
20 let post = user.createThing("post", { title: "Lorem ipsum" });
21
22 expect(post.id).toBeTruthy();
23 expect(user.things.models).toHaveLength(initialCount + 1);
24 expect(user.things.includes(post)).toBeTruthy();
25 expect(
26 user.thingIds.find((obj) => {
27 return obj.id === post.id && obj.type === "post";
28 })
29 ).toBeTruthy();
30 expect(
31 user.attrs.thingIds.find((obj) => {
32 return obj.id === post.id && obj.type === "post";
33 })
34 ).toBeTruthy();
35
36 // Check the inverse
37 expect(post.user.attrs).toEqual(user.attrs);
38 expect(post.userId).toEqual(user.id);
39 });
40 });
41 });