Debian Codegraph @

__tests__/external/shared/orm/has-many/8-many-to-many/association-new-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Has Many | Many to Many | association #new", () => {
4 let helper;
5 beforeEach(() => {
6 helper = new Helper();
7 });
8 afterEach(() => {
9 helper.shutdown();
10 });
11
12 /*
13 The model can make a new unsaved belongs-to association, for all states
14 */
15
16 states.forEach((state) => {
17 test(`a ${state} can build a new associated child`, () => {
18 let [order] = helper[state]();
19 let initialCount = order.products.models.length;
20
21 let blueProduct = order.newProduct({ name: "Blue" });
22
23 expect(!blueProduct.id).toBeTruthy();
24 expect(order.products.models).toHaveLength(initialCount + 1);
25 expect(blueProduct.orders.models).toHaveLength(1);
26
27 blueProduct.save();
28
29 expect(blueProduct.attrs).toEqual({
30 id: blueProduct.id,
31 name: "Blue",
32 orderIds: [order.id],
33 });
34 expect(order.products.models).toHaveLength(initialCount + 1);
35 expect(order.products.includes(blueProduct)).toBeTruthy();
36 expect(order.productIds.indexOf(blueProduct.id) > -1).toBeTruthy();
37 expect(blueProduct.orders.includes(order)).toBeTruthy();
38 });
39 });
40 });