salix/modules/client/back/methods/client/specs/consumption.spec.js

94 lines
2.7 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
describe('client consumption() filter', () => {
it('should return a list of buyed items by ticket', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 9}}, args: {}};
const filter = {
where: {
clientFk: 1101
},
order: 'itemTypeFk, itemName, itemSize'
};
const result = await models.Client.consumption(ctx, filter, options);
expect(result.length).toEqual(11);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return a list of tickets grouped by item', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 9}},
args: {
grouped: true
}
};
const filter = {
where: {
clientFk: 1101
},
order: 'itemFk'
};
const result = await models.Client.consumption(ctx, filter, options);
const firstRow = result[0];
const secondRow = result[1];
const thirdRow = result[2];
expect(result.length).toEqual(3);
expect(firstRow.quantity).toEqual(11);
expect(secondRow.quantity).toEqual(15);
expect(thirdRow.quantity).toEqual(20);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return a list of tickets from the item id 4', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 9}},
args: {
itemId: 4
}
};
const filter = {
where: {
clientFk: 1101
},
order: 'itemTypeFk, itemName, itemSize'
};
const result = await models.Client.consumption(ctx, filter, options);
const expectedItemId = 4;
const firstRow = result[0];
expect(firstRow.itemFk).toEqual(expectedItemId);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});