Debian Codegraph @

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

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Has Many | Named One-Way Reflexive | association #setIds", () => {
4 let helper;
5 beforeEach(() => {
6 helper = new Helper();
7 });
8 afterEach(() => {
9 helper.shutdown();
10 });
11
12 states.forEach((state) => {
13 test(`a ${state} can update its association to include a saved child via childIds`, () => {
14 let [tag] = helper[state]();
15 let savedTag = helper.savedChild();
16
17 tag.labelIds = [savedTag.id];
18
19 expect(tag.labels.models[0].attrs).toEqual(savedTag.attrs);
20 expect(tag.labelIds).toEqual([savedTag.id]);
21
22 tag.save();
23 savedTag.reload();
24
25 expect(savedTag.labels.models).toHaveLength(0);
26 });
27
28 test(`a ${state} can clear its association via a null childIds`, () => {
29 let [tag] = helper[state]();
30
31 tag.labelIds = null;
32
33 expect(tag.labels.models).toBeEmpty();
34 expect(tag.labelIds).toBeEmpty();
35
36 tag.save();
37 });
38 });
39 });