8032-devToTest_2440 #3009

Merged
alexm merged 262 commits from 8032-devToTest_2440 into test 2024-09-24 09:34:49 +00:00
1 changed files with 20 additions and 32 deletions
Showing only changes of commit 998d3865a3 - Show all commits

View File

@ -1,21 +1,23 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
fdescribe('ticket setWeight()', () => { describe('ticket setWeight()', () => {
const ctx = beforeAll.getCtx(); const ctx = beforeAll.getCtx();
beforeAll.mockLoopBackContext(); beforeAll.mockLoopBackContext();
let opts; let opts;
let tx; let tx;
const employeeId = 1;
const administrativeId = 5; const administrativeId = 5;
beforeEach(async() => { beforeEach(async() => {
opts = {transaction: tx}; opts = {transaction: tx};
tx = await models.Ticket.beginTransaction({}); tx = await models.Ticket.beginTransaction({});
opts.transaction = tx; opts.transaction = tx;
ctx.req.accessToken.userId = administrativeId;
}); });
afterEach(async() => await tx.rollback()); 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 { try {
const ticketId = 1; const ticketId = 1;
const weight = 10; 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 ticketId = 31;
const weight = 15; const weight = 15;
@ -38,45 +40,31 @@ fdescribe('ticket setWeight()', () => {
}); });
it('should throw an error if the user does not have enough privileges', async() => { 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 { try {
const ticketId = 10; const ticketId = 10;
const weight = 20; const weight = 20;
await models.Ticket.setWeight(ctx, ticketId, weight, opts); await models.Ticket.setWeight(ctx, ticketId, weight, opts);
} catch (e) { } 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() => { it('should call invoiceTicketsAndPdf if the ticket is invoiceable', async() => {
// const tx = await models.Ticket.beginTransaction({}); const ticketId = 10;
const weight = 25;
// try { spyOn(models.Client, 'findById').and.returnValue({
// const opts = {transaction: tx}; hasDailyInvoice: true,
salesPersonUser: () => ({id: 1})
// const ticketId = 4; });
// const weight = 25; spyOn(models.TicketState, 'findOne').and.returnValue({alertLevel: 3});
spyOn(models.Ticket, 'rawSql').and.returnValue([{taxArea: 'WORLD'}]);
// // Mock the necessary methods and data spyOn(models.Ticket, 'invoiceTicketsAndPdf').and.returnValue([10]);
// jest.spyOn(models.ACL, 'checkAccessAcl').mockResolvedValue(true);
// jest.spyOn(models.Client, 'findById').mockResolvedValue({ const invoiceIds = await models.Ticket.setWeight(ctx, ticketId, weight, opts);
// hasDailyInvoice: true,
// salesPersonUser: () => ({id: 1}) expect(invoiceIds.length).toBeGreaterThan(0);
// }); });
// 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;
// }
// });
}); });