Debian Codegraph @

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

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Belongs To | One-to-one Polymorphic | association #set", () => {
4 let helper;
5 beforeEach(() => {
6 helper = new Helper();
7 });
8 afterEach(() => {
9 helper.shutdown();
10 });
11
12 /*
13 The model can update its association via parent, for all states
14 */
15 states.forEach((state) => {
16 test(`a ${state} can update its association to a saved parent`, () => {
17 let [comment] = helper[state]();
18 let post = helper.savedParent();
19
20 comment.commentable = post;
21
22 expect(comment.commentableId).toEqual({ type: "post", id: post.id });
23 expect(comment.commentable.attrs).toEqual(post.attrs);
24 expect(post.commentId).toEqual(comment.id);
25 expect(post.comment.attrs).toEqual(comment.attrs);
26 });
27
28 test(`a ${state} can update its association to a new parent`, () => {
29 let [comment] = helper[state]();
30 let post = helper.newParent();
31
32 comment.commentable = post;
33
34 expect(comment.commentableId).toEqual({ type: "post", id: undefined });
35 expect(comment.commentable.attrs).toEqual(post.attrs);
36
37 expect(post.commentId).toEqual(comment.id);
38 expect(post.comment.attrs).toEqual(comment.attrs);
39 });
40
41 test(`a ${state} can update its association to a null parent`, () => {
42 let [comment] = helper[state]();
43
44 comment.commentable = null;
45
46 expect(comment.commentableId).toBeNil();
47 expect(comment.commentable).toBeNil();
48 });
49 });
50 });