refs #6755 fix canRestoreTicket

This commit is contained in:
Carlos Satorres 2024-03-07 11:36:30 +01:00
parent 64d82d92d6
commit d4d3fdceb5
3 changed files with 13 additions and 9 deletions

View File

@ -47,8 +47,6 @@ module.exports = Self => {
}] }]
}, myOptions); }, myOptions);
console.log('id', id);
console.log('ticket', ticket);
const now = Date.vnNew(); const now = Date.vnNew();
const maxDate = new Date(ticket.creationDate); const maxDate = new Date(ticket.creationDate);
maxDate.setHours(maxDate.getHours() + 1); maxDate.setHours(maxDate.getHours() + 1);

View File

@ -68,7 +68,7 @@ describe('ticket filter()', () => {
const filter = {}; const filter = {};
const result = await models.Ticket.filter(ctx, filter, options); const result = await models.Ticket.filter(ctx, filter, options);
expect(result.length).toEqual(6); expect(result.length).toEqual(5);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {

View File

@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
const models = app.models; const models = app.models;
describe('ticket restore()', () => { fdescribe('ticket restore()', () => {
const employeeUser = 1110; const employeeUser = 1110;
const ticketId = 18; const ticketId = 9;
const activeCtx = { const activeCtx = {
accessToken: {userId: employeeUser}, accessToken: {userId: employeeUser},
headers: { headers: {
@ -48,25 +48,31 @@ describe('ticket restore()', () => {
const tx = await app.models.Ticket.beginTransaction({}); const tx = await app.models.Ticket.beginTransaction({});
const now = Date.vnNew(); const now = Date.vnNew();
console.log('now', now);
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const ticketBeforeUpdate = await models.Ticket.findById(ticketId, null, options); const ticketBeforeUpdate = await models.TicketLog.findById(ticketId, null, options);
await ticketBeforeUpdate.updateAttributes({ await ticketBeforeUpdate.updateAttributes({
isDeleted: true, creationDate: '2001-01-01T11:00:00.000Z',
updated: now
}, options); }, options);
const ticketAfterUpdate = await models.Ticket.findById(ticketId, null, options); console.log('ticketBeforeUpdate', ticketBeforeUpdate);
const ticketAfterUpdate = await models.TicketLog.findById(ticketId, null, options);
console.log('ticketAfterUpdate: ', ticketAfterUpdate);
expect(ticketAfterUpdate.isDeleted).toBeTruthy(); expect(ticketAfterUpdate.isDeleted).toBeTruthy();
await models.Ticket.restore(ctx, ticketId, options); await models.Ticket.restore(ctx, ticketId, options);
const ticketAfterRestore = await models.Ticket.findById(ticketId, null, options); const ticketAfterRestore = await models.Ticket.findById(ticketId, null, options);
console.log('ticketAfterRestore: ', ticketAfterRestore);
const fullYear = now.getFullYear(); const fullYear = now.getFullYear();
console.log('fullYear: ', fullYear);
const shippedFullYear = ticketAfterRestore.shipped.getFullYear(); const shippedFullYear = ticketAfterRestore.shipped.getFullYear();
console.log('shippedFullYear: ', shippedFullYear);
const landedFullYear = ticketAfterRestore.landed.getFullYear(); const landedFullYear = ticketAfterRestore.landed.getFullYear();
console.log('landedFullYear: ', landedFullYear);
expect(ticketAfterRestore.isDeleted).toBeFalsy(); expect(ticketAfterRestore.isDeleted).toBeFalsy();
expect(shippedFullYear).toEqual(fullYear); expect(shippedFullYear).toEqual(fullYear);