2021-10-07 07:57:07 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2019-07-25 07:55:09 +00:00
|
|
|
|
2020-10-30 09:45:55 +00:00
|
|
|
describe('ticket-request confirm()', () => {
|
2024-06-14 06:39:57 +00:00
|
|
|
const ctx = beforeAll.getCtx();
|
|
|
|
beforeAll.mockLoopBackContext();
|
2019-07-25 07:55:09 +00:00
|
|
|
|
|
|
|
it(`should throw an error if the item doesn't exist`, async() => {
|
2021-10-07 07:57:07 +00:00
|
|
|
const tx = await models.TicketRequest.beginTransaction({});
|
2019-07-25 07:55:09 +00:00
|
|
|
|
2020-01-23 12:31:07 +00:00
|
|
|
let error;
|
2019-07-25 07:55:09 +00:00
|
|
|
try {
|
2021-10-07 07:57:07 +00:00
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
ctx.args = {itemFk: 999};
|
|
|
|
await models.TicketRequest.confirm(ctx, options);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
error = e;
|
2019-07-25 07:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expect(error.message).toEqual(`That item doesn't exists`);
|
|
|
|
});
|
|
|
|
|
2020-02-27 11:31:38 +00:00
|
|
|
it('should throw an error if the item is not available', async() => {
|
2021-10-07 07:57:07 +00:00
|
|
|
const tx = await models.TicketRequest.beginTransaction({});
|
2020-01-23 12:31:07 +00:00
|
|
|
|
2019-07-25 07:55:09 +00:00
|
|
|
let error;
|
|
|
|
try {
|
2021-10-07 07:57:07 +00:00
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
const requestId = 5;
|
|
|
|
const itemId = 4;
|
|
|
|
const quantity = 99999;
|
|
|
|
|
|
|
|
ctx.args = {
|
|
|
|
itemFk: itemId,
|
|
|
|
id: requestId,
|
|
|
|
quantity: quantity
|
|
|
|
};
|
|
|
|
|
|
|
|
await models.TicketRequest.confirm(ctx, options);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
error = e;
|
2019-07-25 07:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expect(error.message).toEqual(`This item is not available`);
|
|
|
|
});
|
|
|
|
|
2020-10-02 07:39:58 +00:00
|
|
|
it(`should throw if there's a sale id`, async() => {
|
2021-10-07 07:57:07 +00:00
|
|
|
const tx = await models.TicketRequest.beginTransaction({});
|
2019-07-25 07:55:09 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
let error;
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
2020-01-23 12:31:07 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
const requestId = 4;
|
|
|
|
const itemId = 1;
|
|
|
|
const quantity = 10;
|
2020-10-06 08:15:27 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
ctx.args = {
|
|
|
|
itemFk: itemId,
|
|
|
|
id: requestId,
|
|
|
|
quantity: quantity
|
|
|
|
};
|
2020-10-06 08:15:27 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
const request = await models.TicketRequest.findById(requestId, null, options);
|
2020-10-06 08:15:27 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
expect(request.saleFk).toBeNull();
|
2024-04-24 08:31:26 +00:00
|
|
|
await request.updateAttributes({saleFk: 2});
|
2021-10-07 07:57:07 +00:00
|
|
|
ctx.args = {
|
|
|
|
itemFk: itemId,
|
|
|
|
id: requestId,
|
|
|
|
quantity: quantity
|
|
|
|
};
|
|
|
|
|
|
|
|
await models.TicketRequest.confirm(ctx, options);
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
error = e;
|
2020-10-02 07:39:58 +00:00
|
|
|
}
|
2019-07-25 07:55:09 +00:00
|
|
|
|
2020-10-02 07:39:58 +00:00
|
|
|
expect(error.message).toEqual(`This request already contains a sale`);
|
2019-07-25 07:55:09 +00:00
|
|
|
});
|
|
|
|
});
|