Debian Codegraph @

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

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Has Many | Many-to-many Polymorphic | accessor", () => {
4 let helper;
5 beforeEach(() => {
6 helper = new Helper();
7 });
8 afterEach(() => {
9 helper.shutdown();
10 });
11
12 /*
13 The reference to a belongs-to association is correct, for all states
14 */
15 states.forEach((state) => {
16 test(`the references of a ${state} are correct`, () => {
17 let [user, posts] = helper[state]();
18
19 expect(user.commentables.models).toHaveLength(posts.length);
20 expect(user.commentableIds).toHaveLength(posts.length);
21
22 posts.forEach((post, i) => {
23 expect(user.commentables.includes(post)).toBeTruthy();
24
25 if (post.isSaved()) {
26 expect(user.commentableIds[i]).toEqual({ type: "post", id: post.id });
27 }
28
29 // Check the inverse
30 expect(post.users.includes(user)).toBeTruthy();
31 });
32 });
33 });
34 });