Debian Codegraph @

__tests__/external/shared/orm/belongs-to/11-named-one-way-reflexive-self-referential/association-set-id-test.js

raw
1 import Helper from "./_helper";
2
3 describe("External | Shared | ORM | Belongs To | Named one-way reflexive self referential | association #setId", () => {
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 parentId, for all states
14 */
15
16 ["savedChildNoParent", "savedChildSavedParent"].forEach((state) => {
17 test(`a ${state} can update its association to itself via parentId`, () => {
18 let [user] = helper[state]();
19
20 user.representativeId = user.id;
21
22 expect(user.representativeId).toEqual(user.id);
23 expect(user.representative.attrs).toEqual(user.attrs);
24
25 user.save();
26
27 expect(user.representativeId).toEqual(user.id);
28 expect(user.representative.attrs).toEqual(user.attrs);
29 });
30 });
31
32 ["savedChildSavedParent", "newChildNewParent"].forEach((state) => {
33 test(`a ${state} can clear its association via a null parentId`, () => {
34 let [user] = helper[state]();
35
36 user.representativeId = null;
37
38 expect(user.representativeId).toBeNil();
39 expect(user.representative).toBeNil();
40
41 user.save();
42
43 expect(user.representativeId).toBeNil();
44 expect(user.representative).toBeNil();
45 });
46 });
47 });