Debian Codegraph @

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

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