7744-closeAllTest #3114
|
@ -37,7 +37,7 @@ module.exports = Self => {
|
||||||
const tickets = await models.Ticket.find({
|
const tickets = await models.Ticket.find({
|
||||||
where: {refFk: invoiceOut.ref}
|
where: {refFk: invoiceOut.ref}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const [bookEntry] = await models.Xdiario.find({
|
const [bookEntry] = await models.Xdiario.find({
|
||||||
where: {
|
where: {
|
||||||
SERIE: invoiceOut.ref[0],
|
SERIE: invoiceOut.ref[0],
|
||||||
|
@ -55,13 +55,13 @@ module.exports = Self => {
|
||||||
if (bookEntry) {
|
if (bookEntry) {
|
||||||
if (bookEntry.enlazadoSage) {
|
if (bookEntry.enlazadoSage) {
|
||||||
const params = {
|
const params = {
|
||||||
bookEntry: bookEntry.ASIEN,
|
bookEntry: bookEntry.ASIEN,
|
||||||
invoiceOutRef: invoiceOut.ref
|
invoiceOutRef: invoiceOut.ref
|
||||||
}
|
};
|
||||||
await Self.rawSql(`SELECT util.notification_send('book-entry-deleted', ?, NULL)`,
|
await Self.rawSql(`SELECT util.notification_send('book-entry-deleted', ?, NULL)`,
|
||||||
[JSON.stringify(params)],
|
[JSON.stringify(params)],
|
||||||
myOptions);
|
myOptions);
|
||||||
};
|
}
|
||||||
|
|
||||||
await models.Xdiario.destroyAll({
|
await models.Xdiario.destroyAll({
|
||||||
ASIEN: bookEntry.ASIEN
|
ASIEN: bookEntry.ASIEN
|
||||||
|
|
|
@ -19,8 +19,7 @@ module.exports = async function(ctx, Self, tickets, options) {
|
||||||
const failedtickets = [];
|
const failedtickets = [];
|
||||||
for (const ticket of tickets) {
|
for (const ticket of tickets) {
|
||||||
try {
|
try {
|
||||||
await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId},
|
await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], myOptions);
|
||||||
myOptions);
|
|
||||||
|
|
||||||
await Self.app.models.InvoiceOut.getSerial(
|
await Self.app.models.InvoiceOut.getSerial(
|
||||||
ticket.clientFk,
|
ticket.clientFk,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
fdescribe('Ticket Closure - closeAll function', () => {
|
describe('Ticket Closure - closeAll function', () => {
|
||||||
let ctx = {
|
let ctx = {
|
||||||
req: {
|
req: {
|
||||||
getLocale: () => 'es',
|
getLocale: () => 'es',
|
||||||
|
@ -17,6 +17,7 @@ fdescribe('Ticket Closure - closeAll function', () => {
|
||||||
|
|
||||||
beforeEach(async() => {
|
beforeEach(async() => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req});
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req});
|
||||||
|
|
||||||
tx = await models.Ticket.beginTransaction({});
|
tx = await models.Ticket.beginTransaction({});
|
||||||
options = {transaction: tx};
|
options = {transaction: tx};
|
||||||
originalVnNew = Date.vnNew;
|
originalVnNew = Date.vnNew;
|
||||||
|
@ -32,34 +33,7 @@ fdescribe('Ticket Closure - closeAll function', () => {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should successfully close all tickets when conditions are met', async() => {
|
it('should set routeFk to NULL when conditions are met', async() => {
|
||||||
const ticketsBefore = await models.Ticket.find({
|
|
||||||
where: {
|
|
||||||
packages: {neq: 0}
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
const packedTicketsIds = ticketsBefore.map(ticket => ticket.id);
|
|
||||||
|
|
||||||
const packedTicketsBefore = await models.TicketLastState.find({
|
|
||||||
where: {
|
|
||||||
ticketFk: {inq: packedTicketsIds},
|
|
||||||
lastState: 'Encajado'
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
await models.Ticket.closeAll(ctx, options);
|
|
||||||
|
|
||||||
const packedTicketsAfter = await models.TicketLastState.find({
|
|
||||||
where: {
|
|
||||||
ticketFk: {inq: packedTicketsIds},
|
|
||||||
lastState: 'Encajado'
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(packedTicketsBefore.length).toBeGreaterThan(packedTicketsAfter.length);
|
|
||||||
});
|
|
||||||
|
|
||||||
fit('should set routeFk to NULL when conditions are met', async() => {
|
|
||||||
const ticketsBefore = await models.Ticket.find({
|
const ticketsBefore = await models.Ticket.find({
|
||||||
where: {
|
where: {
|
||||||
routeFk: {neq: null}
|
routeFk: {neq: null}
|
||||||
|
|
Loading…
Reference in New Issue