Debian Codegraph @

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

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