Debian Codegraph @

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

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Belongs To | One-to-one Polymorphic | association #new", () => {
4 let helper;
5 beforeEach(() => {
6 helper = new Helper();
7 });
8 afterEach(() => {
9 helper.shutdown();
10 });
11
12 /*
13 The model can make a new unsaved belongs-to association, for all states
14 */
15
16 states.forEach((state) => {
17 test(`a ${state} can build a new associated parent`, () => {
18 let [comment] = helper[state]();
19
20 let post = comment.newCommentable("post", { age: 300 });
21
22 expect(!post.id).toBeTruthy();
23 expect(comment.commentable).toEqual(post);
24 expect(comment.commentableId).toEqual({ type: "post", id: undefined });
25 expect(post.comment).toEqual(comment);
26 expect(post.commentId).toEqual(comment.id);
27
28 comment.save();
29
30 expect(post.id).toBeTruthy();
31 expect(comment.commentableId).toEqual({ type: "post", id: post.id });
32 });
33 });
34 });