Debian Codegraph @

__tests__/external/shared/orm/belongs-to/10-one-to-one-polymorphic/accessor-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Belongs To | One-to-one 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 [comment, post] = helper[state]();
18
19 // We use .attrs here because otherwise deepEqual goes on infinite recursive comparison
20 if (post) {
21 expect(comment.commentable.attrs).toEqual(post.attrs);
22 expect(comment.commentableId).toEqual({ type: "post", id: post.id });
23 } else {
24 expect(comment.commentable).toBeNil();
25 expect(comment.commentableId).toBeNil();
26 }
27
28 // If there's a post in this state, make sure the inverse association is correct
29 if (post) {
30 expect(post.comment.attrs).toEqual(comment.attrs);
31 expect(post.commentId).toEqual(comment.id);
32 }
33 });
34 });
35 });