Debian Codegraph @

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

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Mixed | One To Many | 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 [user] = helper[state]();
18 let initialCount = user.posts.models.length;
19
20 let post = user.createPost({ title: "Lorem ipsum" });
21
22 expect(post.id).toBeTruthy();
23 expect(user.posts.models).toHaveLength(initialCount + 1);
24 expect(user.posts.includes(post)).toBeTruthy();
25 expect(user.postIds.indexOf(post.id) > -1).toBeTruthy();
26 expect(user.attrs.postIds.indexOf(post.id) > -1).toBeTruthy();
27
28 // Check the inverse
29 expect(post.user.attrs).toEqual(user.attrs);
30 expect(post.userId).toEqual(user.id);
31 });
32 });
33 });