Debian Codegraph @

__tests__/external/shared/orm/has-many/1-basic/association-set-ids-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Has Many | Basic | association #setIds", () => {
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 [user] = helper[state]();
18 let savedPost = helper.savedChild();
19
20 user.postIds = [savedPost.id];
21
22 expect(user.posts.models[0].attrs).toEqual(savedPost.attrs);
23 expect(user.postIds).toEqual([savedPost.id]);
24 });
25
26 test(`a ${state} can clear its association via a null parentId`, () => {
27 let [user] = helper[state]();
28
29 user.postIds = null;
30
31 expect(user.posts.models).toBeEmpty();
32 expect(user.postIds).toBeEmpty();
33 });
34 });
35 });