Debian Codegraph @

__tests__/external/shared/orm/belongs-to/5-named-reflexive-explicit-inverse/association-set-id-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Belongs To | Named Reflexive Explicit Inverse | 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 states.forEach((state) => {
16 test(`a ${state} can update its association to a saved parent via parentId`, () => {
17 let [user] = helper[state]();
18 let friend = helper.savedParent();
19
20 user.bestFriendId = friend.id;
21
22 expect(user.bestFriendId).toEqual(friend.id);
23 expect(user.bestFriend.attrs).toEqual(friend.attrs);
24 });
25 });
26
27 ["savedChildSavedParent", "newChildSavedParent"].forEach((state) => {
28 test(`a ${state} can clear its association via a null parentId`, () => {
29 let [user] = helper[state]();
30
31 user.bestFriendId = null;
32
33 expect(user.bestFriendId).toBeNil();
34 expect(user.bestFriend).toBeNil();
35 });
36 });
37 });