Debian Codegraph @

__tests__/external/shared/orm/mixed/2-many-to-one/association-create-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Mixed | Many To One | 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 has-many association, for all states
14 */
15 states.forEach((state) => {
16 test(`a ${state} can create an associated parent`, () => {
17 let [post, originalUser] = helper[state]();
18
19 let user = post.createUser({ name: "Zelda" });
20
21 expect(user.id).toBeTruthy();
22 expect(post.user.attrs).toEqual(user.attrs);
23 expect(post.userId).toEqual(user.id);
24
25 // Check the inverse
26 expect(user.posts.includes(post)).toBeTruthy();
27
28 // Ensure old inverse was cleared
29 if (originalUser && originalUser.isSaved()) {
30 originalUser.reload();
31 expect(originalUser.posts.includes(post)).toBeFalsy();
32 }
33 });
34 });
35 });