Debian Codegraph @

__tests__/external/shared/orm/has-many/10-many-to-many-polymorphic/association-create-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Has Many | Many-to-many Polymorphic | 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.commentables.models.length;
19
20 let post = user.createCommentable("post", { title: "Lorem ipsum" });
21
22 expect(post.id).toBeTruthy();
23 expect(user.commentables.models).toHaveLength(initialCount + 1);
24 expect(user.commentables.includes(post)).toBeTruthy();
25 expect(
26 user.commentableIds.find((obj) => {
27 return obj.id === post.id && obj.type === "post";
28 })
29 ).toBeTruthy();
30 expect(
31 user.attrs.commentableIds.find((obj) => {
32 return obj.id === post.id && obj.type === "post";
33 })
34 ).toBeTruthy();
35 expect(post.users.includes(user)).toBeTruthy();
36 });
37 });
38 });