Debian Codegraph @

__tests__/external/shared/orm/belongs-to/3-reflexive/association-new-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Belongs To | Reflexive | association #new", () => {
4 let helper;
5 beforeEach(() => {
6 helper = new Helper();
7 });
8 afterEach(() => {
9 helper.shutdown();
10 });
11
12 /*
13 The model can make a new unsaved belongs-to association, for all states
14 */
15
16 states.forEach((state) => {
17 test(`a ${state} can build a new associated parent`, () => {
18 let [user, originalUser] = helper[state]();
19
20 let ganon = user.newUser({ name: "Ganon" });
21
22 expect(!ganon.id).toBeTruthy();
23 expect(user.user).toEqual(ganon);
24 expect(user.userId).toBeNil();
25 expect(ganon.user).toEqual(user);
26
27 user.save();
28
29 expect(ganon.id).toBeTruthy();
30 expect(user.userId).toEqual(ganon.id);
31
32 if (originalUser) {
33 originalUser.reload();
34 expect(originalUser.userId).toBeNil();
35 }
36 });
37 });
38 });