Debian Codegraph @

__tests__/external/shared/orm/has-many/7-named-one-way-reflexive/association-set-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Has Many | Named One-Way Reflexive | association #set", () => {
4 let helper;
5 beforeEach(() => {
6 helper = new Helper();
7 });
8 afterEach(() => {
9 helper.shutdown();
10 });
11
12 /*
13 The model can update its association via parent, for all states
14 */
15 states.forEach((state) => {
16 test(`a ${state} can update its association to a list of saved children`, () => {
17 let [tag] = helper[state]();
18 let savedTag = helper.savedChild();
19
20 tag.labels = [savedTag];
21
22 expect(tag.labels.includes(savedTag)).toBeTruthy();
23 expect(tag.labelIds[0]).toEqual(savedTag.id);
24 expect(savedTag.labels.includes(tag)).toBeFalsy();
25
26 tag.save();
27 });
28
29 test(`a ${state} can update its association to a new parent`, () => {
30 let [tag] = helper[state]();
31 let newTag = helper.newChild();
32
33 tag.labels = [newTag];
34
35 expect(tag.labels.includes(newTag)).toBeTruthy();
36 expect(tag.labelIds[0]).toBeUndefined();
37 expect(newTag.labels.includes(tag)).toBeFalsy();
38
39 tag.save();
40 });
41
42 test(`a ${state} can clear its association via an empty list`, () => {
43 let [tag] = helper[state]();
44
45 tag.labels = [];
46
47 expect(tag.labelIds).toBeEmpty();
48 expect(tag.labels.models).toHaveLength(0);
49
50 tag.save();
51 });
52
53 test(`a ${state} can clear its association via an empty list`, () => {
54 let [tag] = helper[state]();
55
56 tag.labels = null;
57
58 expect(tag.labelIds).toBeEmpty();
59 expect(tag.labels.models).toHaveLength(0);
60
61 tag.save();
62 });
63 });
64 });