Debian Codegraph @

__tests__/external/shared/orm/has-many/4-named-reflexive/association-new-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Has Many | Named Reflexive | 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 child`, () => {
18 let [tag] = helper[state]();
19 let initialCount = tag.labels.models.length;
20
21 let blueTag = tag.newLabel({ name: "Blue" });
22
23 expect(!blueTag.id).toBeTruthy();
24 expect(tag.labels.models).toHaveLength(initialCount + 1);
25 expect(blueTag.labels.models).toHaveLength(1);
26
27 blueTag.save();
28
29 expect(blueTag.attrs).toEqual({
30 id: blueTag.id,
31 name: "Blue",
32 labelIds: [tag.id],
33 });
34 expect(tag.labels.models).toHaveLength(initialCount + 1);
35 expect(tag.labels.includes(blueTag)).toBeTruthy();
36 expect(tag.labelIds.indexOf(blueTag.id) > -1).toBeTruthy();
37 expect(blueTag.labels.includes(tag)).toBeTruthy();
38 });
39 });
40 });