Debian Codegraph @

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

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Has Many | Many to Many | association #create", () => {
4 let helper;
5 beforeEach(() => {
6 helper = new Helper();
7 });
8 afterEach(() => {
9 helper.shutdown();
10 });
11
12 /*
13 The model can create a has-many association, for all states
14 */
15 states.forEach((state) => {
16 test(`a ${state} can create an associated child`, () => {
17 let [order] = helper[state]();
18 let initialCount = order.products.models.length;
19
20 let orangeProduct = order.createProduct({ name: "Orange" });
21
22 expect(orangeProduct.id).toBeTruthy();
23 expect(order.products.models).toHaveLength(initialCount + 1);
24 expect(order.products.includes(orangeProduct)).toBeTruthy();
25 expect(order.productIds.indexOf(orangeProduct.id) > -1).toBeTruthy();
26 expect(
27 order.attrs.productIds.indexOf(orangeProduct.id) > -1
28 ).toBeTruthy();
29 expect(orangeProduct.orders.includes(order)).toBeTruthy();
30 });
31 });
32 });