Debian Codegraph @

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

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Has Many | Basic | 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 list of saved children`, () => {
17 let [user] = helper[state]();
18 let savedPost = helper.savedChild();
19
20 user.posts = [savedPost];
21
22 expect(user.posts.models.indexOf(savedPost) > -1).toBeTruthy();
23 expect(user.postIds.indexOf(savedPost.id) > -1).toBeTruthy();
24 });
25
26 test(`a ${state} can update its association to a new parent`, () => {
27 let [user] = helper[state]();
28 let newPost = helper.newChild();
29
30 user.posts = [newPost];
31
32 expect(user.postIds).toEqual([undefined]);
33 expect(user.posts.models[0]).toEqual(newPost);
34 });
35
36 test(`a ${state} can clear its association via an empty list`, () => {
37 let [user] = helper[state]();
38
39 user.posts = [];
40
41 expect(user.postIds).toBeEmpty();
42 expect(user.posts.models).toHaveLength(0);
43 });
44
45 test(`a ${state} can clear its association via an empty list`, () => {
46 let [user] = helper[state]();
47
48 user.posts = null;
49
50 expect(user.postIds).toBeEmpty();
51 expect(user.posts.models).toHaveLength(0);
52 });
53 });
54 });