7983-testToMaster_2438 #2977

Merged
alexm merged 212 commits from 7983-testToMaster_2438 into master 2024-09-17 05:36:47 +00:00
3 changed files with 48 additions and 53 deletions
Showing only changes of commit e2f1fea6be - Show all commits

View File

@ -15,9 +15,7 @@ describe('ticket assignCollection()', () => {
args: {} args: {}
}; };
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req});
active: ctx.req
});
options = {transaction: tx}; options = {transaction: tx};
tx = await models.Sale.beginTransaction({}); tx = await models.Sale.beginTransaction({});
@ -25,7 +23,7 @@ describe('ticket assignCollection()', () => {
}); });
afterEach(async() => { afterEach(async() => {
await tx.rollback(); if (tx) await tx.rollback();
}); });
it('should throw an error when there is not picking tickets', async() => { it('should throw an error when there is not picking tickets', async() => {

View File

@ -14,7 +14,7 @@ describe('InvoiceOut refundAndInvoice()', () => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: activeCtx}); spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: activeCtx});
}); });
fit('should refund an invoice and create a new invoice', async() => { it('should refund an invoice and create a new invoice', async() => {
const tx = await models.InvoiceOut.beginTransaction({}); const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};

View File

@ -2,16 +2,11 @@ const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
describe('InvoiceOut transfer()', () => { fdescribe('InvoiceOut transfer()', () => {
const userId = 5; const userId = 5;
const ctx = { let options;
req: { let tx;
accessToken: {userId}, let ctx;
__: (key, obj) => `Translated: ${key}, ${JSON.stringify(obj)}`,
getLocale: () => 'es'
},
args: {}
};
const activeCtx = {accessToken: {userId}}; const activeCtx = {accessToken: {userId}};
const id = 4; const id = 4;
const newClientFk = 1101; const newClientFk = 1101;
@ -19,13 +14,28 @@ describe('InvoiceOut transfer()', () => {
const siiTypeInvoiceOutFk = 1; const siiTypeInvoiceOutFk = 1;
const invoiceCorrectionTypeFk = 1; const invoiceCorrectionTypeFk = 1;
beforeEach(() => { beforeEach(async() => {
ctx = {
req: {
accessToken: {userId: 1106},
headers: {origin: 'http://localhost'},
__: value => value,
getLocale: () => 'es'
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: activeCtx}); spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: activeCtx});
options = {transaction: tx};
tx = await models.Sale.beginTransaction({});
options.transaction = tx;
});
afterEach(async() => {
await tx.rollback();
}); });
it('should transfer an invoice to a new client and return the new invoice ID', async() => { it('should transfer an invoice to a new client and return the new invoice ID', async() => {
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
const makeInvoice = true; const makeInvoice = true;
try { try {
@ -45,7 +55,7 @@ describe('InvoiceOut transfer()', () => {
const transferredTickets = await models.Ticket.find({ const transferredTickets = await models.Ticket.find({
where: { where: {
invoiceOutFk: result, refFk: result,
clientFk: newClientFk clientFk: newClientFk
} }
}, options); }, options);
@ -60,8 +70,6 @@ describe('InvoiceOut transfer()', () => {
}); });
it('should throw an error if original invoice is not found', async() => { it('should throw an error if original invoice is not found', async() => {
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
const makeInvoice = true; const makeInvoice = true;
try { try {
await models.InvoiceOut.transfer( await models.InvoiceOut.transfer(
@ -83,8 +91,6 @@ describe('InvoiceOut transfer()', () => {
}); });
it('should throw an error if the new client is the same as the original client', async() => { it('should throw an error if the new client is the same as the original client', async() => {
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
const makeInvoice = true; const makeInvoice = true;
const originalInvoice = await models.InvoiceOut.findById(id); const originalInvoice = await models.InvoiceOut.findById(id);
@ -107,13 +113,9 @@ describe('InvoiceOut transfer()', () => {
} }
}); });
it('should not create a new invoice if makeInvoice is false', async() => { fit('should not create a new invoice if makeInvoice is false', async() => {
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
try {
const originalTickets = await models.Ticket.find({ const originalTickets = await models.Ticket.find({
where: {clientFk: newClientFk, invoiceOutFk: null}, where: {clientFk: newClientFk, refFk: null},
options options
}); });
@ -130,17 +132,12 @@ describe('InvoiceOut transfer()', () => {
expect(result).toBeUndefined(); expect(result).toBeUndefined();
// await tx.commit();
const transferredTickets = await models.Ticket.find({ const transferredTickets = await models.Ticket.find({
where: {clientFk: newClientFk, invoiceOutFk: null}, where: {clientFk: newClientFk, refFk: null},
options options
}); });
expect(transferredTickets.length).toBeGreaterThan(originalTickets.length); expect(transferredTickets.length).toBeGreaterThan(originalTickets.length);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
}); });
}); });