This commit is contained in:
parent
df5961a2a2
commit
998d3865a3
|
@ -1,21 +1,23 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
fdescribe('ticket setWeight()', () => {
|
||||
describe('ticket setWeight()', () => {
|
||||
const ctx = beforeAll.getCtx();
|
||||
beforeAll.mockLoopBackContext();
|
||||
let opts;
|
||||
let tx;
|
||||
const employeeId = 1;
|
||||
const administrativeId = 5;
|
||||
|
||||
beforeEach(async() => {
|
||||
opts = {transaction: tx};
|
||||
tx = await models.Ticket.beginTransaction({});
|
||||
opts.transaction = tx;
|
||||
ctx.req.accessToken.userId = administrativeId;
|
||||
});
|
||||
|
||||
afterEach(async() => await tx.rollback());
|
||||
|
||||
xit('should throw an error if the weight is already set', async() => {
|
||||
it('should throw an error if the weight is already set', async() => {
|
||||
try {
|
||||
const ticketId = 1;
|
||||
const weight = 10;
|
||||
|
@ -26,7 +28,7 @@ fdescribe('ticket setWeight()', () => {
|
|||
}
|
||||
});
|
||||
|
||||
xit('should set the weight of a ticket', async() => {
|
||||
it('should set the weight of a ticket', async() => {
|
||||
const ticketId = 31;
|
||||
const weight = 15;
|
||||
|
||||
|
@ -38,45 +40,31 @@ fdescribe('ticket setWeight()', () => {
|
|||
});
|
||||
|
||||
it('should throw an error if the user does not have enough privileges', async() => {
|
||||
ctx.req.accessToken.userId = administrativeId;
|
||||
ctx.req.accessToken.userId = employeeId;
|
||||
try {
|
||||
const ticketId = 10;
|
||||
const weight = 20;
|
||||
|
||||
await models.Ticket.setWeight(ctx, ticketId, weight, opts);
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual('You don\'t have enough privilegs');
|
||||
expect(e.message).toEqual('You don\'t have enough privileges');
|
||||
}
|
||||
});
|
||||
|
||||
// it('should commit the transaction and return invoice ids if the ticket is invoiceable', async() => {
|
||||
// const tx = await models.Ticket.beginTransaction({});
|
||||
it('should call invoiceTicketsAndPdf if the ticket is invoiceable', async() => {
|
||||
const ticketId = 10;
|
||||
const weight = 25;
|
||||
|
||||
// try {
|
||||
// const opts = {transaction: tx};
|
||||
spyOn(models.Client, 'findById').and.returnValue({
|
||||
hasDailyInvoice: true,
|
||||
salesPersonUser: () => ({id: 1})
|
||||
});
|
||||
spyOn(models.TicketState, 'findOne').and.returnValue({alertLevel: 3});
|
||||
spyOn(models.Ticket, 'rawSql').and.returnValue([{taxArea: 'WORLD'}]);
|
||||
spyOn(models.Ticket, 'invoiceTicketsAndPdf').and.returnValue([10]);
|
||||
|
||||
// const ticketId = 4;
|
||||
// const weight = 25;
|
||||
const invoiceIds = await models.Ticket.setWeight(ctx, ticketId, weight, opts);
|
||||
|
||||
// // Mock the necessary methods and data
|
||||
// jest.spyOn(models.ACL, 'checkAccessAcl').mockResolvedValue(true);
|
||||
// jest.spyOn(models.Client, 'findById').mockResolvedValue({
|
||||
// hasDailyInvoice: true,
|
||||
// salesPersonUser: () => ({id: 1})
|
||||
// });
|
||||
// jest.spyOn(models.State, 'findOne').mockResolvedValue({alertLevel: 2});
|
||||
// jest.spyOn(models.TicketState, 'findOne').mockResolvedValue({alertLevel: 3});
|
||||
// jest.spyOn(models.Ticket, 'rawSql').mockResolvedValue([{taxArea: 'WORLD'}]);
|
||||
// jest.spyOn(models.Ticket, 'invoiceTicketsAndPdf').mockResolvedValue([1001]);
|
||||
|
||||
// const invoiceIds = await models.Ticket.setWeight(ctx, ticketId, weight, opts);
|
||||
|
||||
// expect(invoiceIds).toEqual([1001]);
|
||||
|
||||
// await tx.rollback();
|
||||
// } catch (e) {
|
||||
// await tx.rollback();
|
||||
// throw e;
|
||||
// }
|
||||
// });
|
||||
expect(invoiceIds.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue