Debian Codegraph @

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

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Belongs To | One-to-one 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 belongs-to association, for all states
14 */
15 states.forEach((state) => {
16 test(`a ${state} can create an associated parent`, () => {
17 let [comment] = helper[state]();
18
19 let post = comment.createCommentable("post", { title: "Lorem" });
20
21 expect(post.id).toBeTruthy();
22 expect(comment.commentable.attrs).toEqual(post.attrs);
23 expect(post.comment.attrs).toEqual(comment.attrs);
24 expect(comment.commentableId).toEqual({ type: "post", id: post.id });
25 expect(helper.schema.comments.find(comment.id).commentableId).toEqual({
26 type: "post",
27 id: post.id,
28 });
29 });
30 });
31 });