Debian Codegraph @

__tests__/external/shared/orm/has-many/3-reflexive/association-create-test.js

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