Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
}),
);
});
});
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));
});
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));
},
);
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,
}),
);
});
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),
});
});
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,
}),
);
});
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)],
},
]);
});
});
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)]);
});
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: [
});
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()},
]);
});