How to use the @loopback/testlab.toJSON function in @loopback/testlab

To help you get started, we’ve selected a few @loopback/testlab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback-next / packages / repository-tests / src / crud / relations / acceptance / has-many.relation.acceptance.ts View on Github external
it('can create an instance of the related model', async () => {
      const order = await customerRepo.orders(existingCustomerId).create({
        description: 'order 1',
      });

      expect(toJSON(order)).containDeep(
        toJSON({
          customerId: existingCustomerId,
          description: 'order 1',
        }),
      );

      const persisted = await orderRepo.findById(order.id);
      expect(toJSON(persisted)).to.deepEqual(
        toJSON({
          ...order,
          isShipped: features.emptyValue,
          // eslint-disable-next-line @typescript-eslint/camelcase
          shipment_id: features.emptyValue,
        }),
      );
    });
github strongloop / loopback-next / packages / repository-tests / src / crud / relations / acceptance / multi-relations-inclusion-resolver.relation.acceptance.ts View on Github external
});
      const expected = [
        {
          ...customer,
          parentId: features.emptyValue,
          orders: [
            {
              ...o2,
              isShipped: features.emptyValue,
              // eslint-disable-next-line @typescript-eslint/camelcase
              shipment_id: features.emptyValue,
            },
          ],
        },
      ];
      expect(toJSON(result)).to.deepEqual(toJSON(expected));
    });
github strongloop / loopback-next / packages / repository-tests / src / crud / relations / acceptance / has-many-inclusion-resolver.relation.acceptance.ts View on Github external
parentId: features.emptyValue,
          },
          {
            ...odin,
            parentId: features.emptyValue,
            orders: [
              {
                ...odinPizza,
                isShipped: features.emptyValue,
                // eslint-disable-next-line @typescript-eslint/camelcase
                shipment_id: features.emptyValue,
              },
            ],
          },
        ];
        expect(toJSON(result)).to.deepEqual(toJSON(expected));
      },
    );
github strongloop / loopback-next / packages / repository-tests / src / crud / relations / acceptance / has-one.relation.acceptance.ts View on Github external
it('can create an instance of the related model', async () => {
      const address = await createCustomerAddress(existingCustomerId, {
        street: '123 test avenue',
      });
      expect(toJSON(address)).to.containDeep(
        toJSON({
          customerId: existingCustomerId,
          street: '123 test avenue',
        }),
      );

      const persisted = await addressRepo.findById(address.id);
      expect(toJSON(persisted)).to.deepEqual(
        toJSON({
          ...address,
          zipcode: features.emptyValue,
          city: features.emptyValue,
          province: features.emptyValue,
        }),
      );
    });
github strongloop / loopback-next / examples / todo-list / src / __tests__ / integration / todo.repository.integration.ts View on Github external
it('includes TodoList in findById result', async () => {
    const list = await givenTodoListInstance(todoListRepo, {});
    const todo = await givenTodoInstance(todoRepo, {todoListId: list.id});

    const response = await todoRepo.findById(todo.id, {
      include: [{relation: 'todoList'}],
    });

    expect(toJSON(response)).to.deepEqual({
      ...toJSON(todo),
      todoList: toJSON(list),
    });
  });
github strongloop / loopback-next / packages / repository-tests / src / crud / relations / acceptance / has-one.relation.acceptance.ts View on Github external
it('can create an instance of the related model', async () => {
      const address = await createCustomerAddress(existingCustomerId, {
        street: '123 test avenue',
      });
      expect(toJSON(address)).to.containDeep(
        toJSON({
          customerId: existingCustomerId,
          street: '123 test avenue',
        }),
      );

      const persisted = await addressRepo.findById(address.id);
      expect(toJSON(persisted)).to.deepEqual(
        toJSON({
          ...address,
          zipcode: features.emptyValue,
          city: features.emptyValue,
          province: features.emptyValue,
        }),
      );
    });
github strongloop / loopback-next / examples / todo-list / src / __tests__ / integration / todo-list.repository.integration.ts View on Github external
it('includes both Todos and TodoListImage in find method result', async () => {
    const list = await givenTodoListInstance(todoListRepo);
    const todo = await givenTodoInstance(todoRepo, {todoListId: list.id});
    const image = await givenTodoListImageInstance(todoListImageRepo, {
      todoListId: list.id,
    });

    const response = await todoListRepo.find({
      include: [{relation: 'image'}, {relation: 'todos'}],
    });

    expect(toJSON(response)).to.deepEqual([
      {
        ...toJSON(list),
        image: toJSON(image),
        todos: [toJSON(todo)],
      },
    ]);
  });
});
github strongloop / loopback-next / examples / todo / src / __tests__ / acceptance / todo.acceptance.ts View on Github external
it('queries todos with a filter', async () => {
    await givenTodoInstance({title: 'wake up', isComplete: true});

    const todoInProgress = await givenTodoInstance({
      title: 'go to sleep',
      isComplete: false,
    });

    await client
      .get('/todos')
      .query({filter: {where: {isComplete: false}}})
      .expect(200, [toJSON(todoInProgress)]);
  });
github strongloop / loopback-next / packages / repository-tests / src / crud / relations / acceptance / has-many-inclusion-resolver.relation.acceptance.ts View on Github external
it('returns inclusions after running updateById() operation', async () => {
      const thor = await customerRepo.create({name: 'Thor'});
      const odin = await customerRepo.create({name: 'Odin'});

      const thorOrder = await orderRepo.create({
        customerId: thor.id,
        description: 'Pizza',
      });

      const pizza = await orderRepo.findById(thorOrder.id.toString());
      pizza.customerId = odin.id;
      const reheatedPizza = toJSON(pizza);

      await orderRepo.updateById(pizza.id, reheatedPizza);
      const odinPizza = await orderRepo.findById(thorOrder.id);

      const result = await customerRepo.find({
        include: [{relation: 'orders'}],
      });
      const expected = [
        {
          ...thor,
          parentId: features.emptyValue,
        },
        {
          ...odin,
          parentId: features.emptyValue,
          orders: [
github strongloop / loopback-next / packages / repository / src / __tests__ / unit / repositories / relations-helpers / include-related-models.unit.ts View on Github external
});

    const productThree = await productRepo.create({
      name: 'product 3',
      categoryId: categoryTwo.id,
    });

    productRepo.inclusionResolvers.set('category', belongsToResolver);

    const productWithCategories = await includeRelatedModels(
      productRepo,
      [productOne, productTwo, productThree],
      [{relation: 'category'}],
    );

    expect(toJSON(productWithCategories)).to.deepEqual([
      {...productOne.toJSON(), category: categoryOne.toJSON()},
      {...productTwo.toJSON(), category: categoryTwo.toJSON()},
      {...productThree.toJSON(), category: categoryTwo.toJSON()},
    ]);
  });