#7832 - ticketServiceModifyConcept #3332

Merged
jgallego merged 3 commits from 7832-ticketServiceModifyConcept into dev 2025-01-07 07:45:42 +00:00
2 changed files with 74 additions and 1 deletions

View File

@ -0,0 +1,64 @@
const {models} = require('vn-loopback/server/server');
describe('ticketService model ', () => {
const originalTicketFk = 1;
const refundTicketFk = 11;
let tx;
let opts;
let ticketService;
beforeEach(async() => {
tx = await models.Sale.beginTransaction({});
opts = {transaction: tx};
ticketService = await models.TicketService.create({
ticketFk: refundTicketFk,
description: 'test',
quantity: 1,
price: 100,
taxClassFk: 1,
ticketServiceTypeFk: 1
}, opts);
});
afterEach(async() => {
await tx.rollback();
});
describe('TicketService', () => {
it('should allow updating description and quantity for non-refund tickets', async() => {
await ticketService.updateAttributes({
ticketServiceTypeFk: 2,
quantity: 5
}, opts);
const updated = await models.TicketService.findById(ticketService.id, null, opts);
expect(updated.description).not.toBe('test');
expect(updated.quantity).toBe(5);
});
it('should only allow updating description for refund tickets', async() => {
await models.TicketRefund.create({
refundTicketFk,
originalTicketFk
}, opts);
await ticketService.updateAttributes({
ticketServiceTypeFk: 2
}, opts);
try {
await ticketService.updateAttributes({
ticketServiceTypeFk: 3,
quantity: 5
}, opts);
fail('Should have thrown error');
Review

El texto del fail no me cueadra con la descripcion del caso.
Es correcto que queremos un fail para "dejar actualizar(allow updating)"??

El texto del fail no me cueadra con la descripcion del caso. Es correcto que queremos un fail para "dejar actualizar(allow updating)"??
Review

He quitado esta linea y me siguen pasando

He quitado esta linea y me siguen pasando
Review

la cuestion es que esa linea nunca deberia ejecutarse, para que el test vaya bien, el try deberia dar fallo y pasar al catch, esa linea es un salvavidas por si alguien hace que el updatAttributes no falle, se ejecuta el fail.

la cuestion es que esa linea nunca deberia ejecutarse, para que el test vaya bien, el try deberia dar fallo y pasar al catch, esa linea es un salvavidas por si alguien hace que el updatAttributes no falle, se ejecuta el fail.
Review

Si, lo sé, lo hemos comentado alguna vez
Te he puesto una captura diciéndote que con o sin esa linea, el test pasa igualmente.
Entiendo que lo haces de cara a futuro.

Si, lo sé, lo hemos comentado alguna vez Te he puesto una captura diciéndote que con o sin esa linea, el test pasa igualmente. Entiendo que lo haces de cara a futuro.
} catch (e) {
expect(e.message).toBe('Only description can be modified in refund tickets');
}
});
});
});

View File

@ -10,9 +10,18 @@ module.exports = Self => {
const isLocked = await models.Ticket.isLocked(ticketId);
if (isLocked)
throw new UserError(`The current ticket can't be modified`);
const isRefund = await models.TicketRefund.findOne({
where: {refundTicketFk: ticketId}
}, {
transaction: ctx.options.transaction
});
if (isRefund && ctx.data && Object.keys(ctx.data).some(field => field !== 'ticketServiceTypeFk'))
throw new UserError('Only description can be modified in refund tickets');
}
if (changes && changes.ticketServiceTypeFk) {
if (changes?.ticketServiceTypeFk) {
const ticketServiceType = await models.TicketServiceType.findById(changes.ticketServiceTypeFk);
changes.description = ticketServiceType.name;
}