Debian Codegraph @

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

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Belongs To | One-to-one Polymorphic | association #setId", () => {
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 parentId, for all states
14 */
15 states.forEach((state) => {
16 test(`a ${state} can update its association to a saved parent via parentId`, () => {
17 let [comment] = helper[state]();
18 let post = helper.savedParent();
19
20 comment.commentableId = { type: "post", id: post.id };
21
22 expect(comment.commentableId).toEqual({ type: "post", id: post.id });
23 expect(comment.commentable.attrs).toEqual(post.attrs);
24
25 comment.save();
26 post.reload();
27
28 expect(post.commentId).toEqual(comment.id);
29 expect(post.comment.attrs).toEqual(comment.attrs);
30 });
31 });
32
33 ["savedChildSavedParent", "newChildSavedParent"].forEach((state) => {
34 test(`a ${state} can clear its association via a null parentId`, () => {
35 let [comment] = helper[state]();
36
37 comment.commentableId = null;
38
39 expect(comment.commentableId).toBeNil();
40 expect(comment.commentable).toBeNil();
41 });
42 });
43 });