Debian Codegraph @

__tests__/external/shared/orm/belongs-to/8-one-to-one/association-set-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Belongs To | One To One | 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 a saved parent`, () => {
17 let [user] = helper[state]();
18 let profile = helper.savedParent();
19
20 user.profile = profile;
21
22 expect(user.profileId).toEqual(profile.id);
23 expect(user.profile.attrs).toEqual(profile.attrs);
24 expect(profile.userId).toEqual(user.id);
25 expect(profile.user.attrs).toEqual(user.attrs);
26 });
27
28 test(`a ${state} can update its association to a new parent`, () => {
29 let [user] = helper[state]();
30 let profile = helper.newParent();
31
32 user.profile = profile;
33
34 expect(user.profileId).toBeNil();
35 expect(user.profile.attrs).toEqual(profile.attrs);
36
37 expect(profile.userId).toEqual(user.id);
38 expect(profile.user.attrs).toEqual(user.attrs);
39 });
40
41 test(`a ${state} can update its association to a null parent`, () => {
42 let [user] = helper[state]();
43
44 user.profile = null;
45
46 expect(user.profileId).toBeNil();
47 expect(user.profile).toBeNil();
48 });
49 });
50 });