Debian Codegraph @

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

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Belongs To | One-way 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 savedPost = helper.savedParent();
19
20 comment.commentable = savedPost;
21
22 expect(comment.commentableId).toEqual({ id: savedPost.id, type: "post" });
23 expect(comment.commentable).toEqual(savedPost);
24 });
25
26 test(`a ${state} can update its association to a new parent`, () => {
27 let [comment] = helper[state]();
28 let newPost = helper.newParent();
29
30 comment.commentable = newPost;
31
32 expect(comment.commentableId).toEqual({ id: undefined, type: "post" });
33 expect(comment.commentable).toEqual(newPost);
34 });
35
36 test(`a ${state} can update its association to a null parent`, () => {
37 let [comment] = helper[state]();
38
39 comment.commentable = null;
40
41 expect(comment.commentableId).toBeNil();
42 expect(comment.commentable).toBeNil();
43 });
44 });
45 });