Debian Codegraph @

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

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