refs #6335 test(ticketAdvance): add test to keep price
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-10-30 15:00:05 +01:00
parent a80715583c
commit 37dce99447
4 changed files with 115 additions and 12 deletions

View File

@ -326,10 +326,5 @@
"Booking completed": "Reserva completada",
"The ticket is in preparation": "El ticket [{{ticketId}}]({{{ticketUrl}}}) del comercial {{salesPersonId}} está en preparación",
"The amount cannot be less than the minimum": "La cantidad no puede ser menor que la cantidad mímina",
"quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mímina",
"__cachedRelations": "__cachedRelations",
"__data": "__data",
"__strict": "__strict",
"__persisted": "__persisted",
"client": "client"
}
"quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mímina"
}

View File

@ -1,8 +1,8 @@
module.exports = () => {
Date.vnUTC = () => {
const env = process.env.NODE_ENV;
// if (!env || env === 'development')
// return new Date(Date.UTC(2001, 0, 1, 11));
if (!env || env === 'development')
return new Date(Date.UTC(2001, 0, 1, 11));
return new Date();
};

View File

@ -223,7 +223,7 @@ module.exports = Self => {
);
}
if (args.isWithoutNegatives === false) delete args.isWithoutNegatives;
const updatedTicket = Object.assign({}, args, JSON.parse(JSON.stringify(ticketToChange)));
const updatedTicket = Object.assign({}, args);
delete updatedTicket.ctx;
delete updatedTicket.option;
@ -249,8 +249,8 @@ module.exports = Self => {
await models.TicketObservation.create(clonedObservations, myOptions);
}
}
const changes = loggable.getChanges(originalTicket, updatedTicket);
const changes = loggable.getChanges(originalTicket, updatedTicket);
const hasChanges = Object.keys(changes.old).length > 0 || Object.keys(changes.new).length > 0;
if (hasChanges) {

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
fdescribe('ticket componentUpdate()', () => {
describe('ticket componentUpdate()', () => {
const userID = 1101;
const ticketID = 11;
const today = Date.vnNew();
@ -209,4 +209,112 @@ fdescribe('ticket componentUpdate()', () => {
throw e;
}
});
describe('ticket componentUpdate()', () => {
it('should change shipped and keep price', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const saleId = 27;
const originDate = today;
const newDate = tomorrow;
const ticketID = 14;
newDate.setHours(0, 0, 0, 0, 0);
originDate.setHours(0, 0, 0, 0, 0);
const args = {
id: ticketID,
clientFk: 1104,
agencyModeFk: 2,
addressFk: 4,
zoneFk: 9,
warehouseFk: 1,
companyFk: 442,
shipped: newDate,
landed: tomorrow,
isDeleted: false,
option: 1,
isWithoutNegatives: false,
keepPrice: true
};
const ctx = {
args: args,
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'},
__: value => {
return value;
}
}
};
const beforeSale = await models.Sale.findById(saleId, null, options);
await models.Ticket.componentUpdate(ctx, options);
const afterSale = await models.Sale.findById(saleId, null, options);
expect(beforeSale.price).toEqual(afterSale.price);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should change shipped and not keep price', async() => {
const tx = await models.Ticket.beginTransaction({});
try {
const options = {transaction: tx};
const saleId = 27;
const originDate = today;
const newDate = tomorrow;
const ticketID = 14;
newDate.setHours(0, 0, 0, 0, 0);
originDate.setHours(0, 0, 0, 0, 0);
const args = {
id: ticketID,
clientFk: 1104,
agencyModeFk: 2,
addressFk: 4,
zoneFk: 9,
warehouseFk: 1,
companyFk: 442,
shipped: newDate,
landed: tomorrow,
isDeleted: false,
option: 1,
isWithoutNegatives: false,
keepPrice: false
};
const ctx = {
args: args,
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'},
__: value => {
return value;
}
}
};
const beforeSale = await models.Sale.findById(saleId, null, options);
await models.Ticket.componentUpdate(ctx, options);
const afterSale = await models.Sale.findById(saleId, null, options);
expect(beforeSale.price).not.toEqual(afterSale.price);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});
});