7983-testToMaster_2438 #2977
|
@ -15,9 +15,7 @@ describe('ticket assignCollection()', () => {
|
|||
args: {}
|
||||
};
|
||||
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: ctx.req
|
||||
});
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req});
|
||||
|
||||
options = {transaction: tx};
|
||||
tx = await models.Sale.beginTransaction({});
|
||||
|
@ -25,7 +23,7 @@ describe('ticket assignCollection()', () => {
|
|||
});
|
||||
|
||||
afterEach(async() => {
|
||||
await tx.rollback();
|
||||
if (tx) await tx.rollback();
|
||||
});
|
||||
|
||||
it('should throw an error when there is not picking tickets', async() => {
|
||||
|
|
|
@ -14,7 +14,7 @@ describe('InvoiceOut refundAndInvoice()', () => {
|
|||
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 options = {transaction: tx};
|
||||
|
||||
|
|
|
@ -2,16 +2,11 @@ const models = require('vn-loopback/server/server').models;
|
|||
const LoopBackContext = require('loopback-context');
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
describe('InvoiceOut transfer()', () => {
|
||||
fdescribe('InvoiceOut transfer()', () => {
|
||||
const userId = 5;
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId},
|
||||
__: (key, obj) => `Translated: ${key}, ${JSON.stringify(obj)}`,
|
||||
getLocale: () => 'es'
|
||||
},
|
||||
args: {}
|
||||
};
|
||||
let options;
|
||||
let tx;
|
||||
let ctx;
|
||||
const activeCtx = {accessToken: {userId}};
|
||||
const id = 4;
|
||||
const newClientFk = 1101;
|
||||
|
@ -19,13 +14,28 @@ describe('InvoiceOut transfer()', () => {
|
|||
const siiTypeInvoiceOutFk = 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});
|
||||
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() => {
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const makeInvoice = true;
|
||||
|
||||
try {
|
||||
|
@ -45,7 +55,7 @@ describe('InvoiceOut transfer()', () => {
|
|||
|
||||
const transferredTickets = await models.Ticket.find({
|
||||
where: {
|
||||
invoiceOutFk: result,
|
||||
refFk: result,
|
||||
clientFk: newClientFk
|
||||
}
|
||||
}, options);
|
||||
|
@ -60,8 +70,6 @@ describe('InvoiceOut transfer()', () => {
|
|||
});
|
||||
|
||||
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;
|
||||
try {
|
||||
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() => {
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const makeInvoice = true;
|
||||
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() => {
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
fit('should not create a new invoice if makeInvoice is false', async() => {
|
||||
const originalTickets = await models.Ticket.find({
|
||||
where: {clientFk: newClientFk, invoiceOutFk: null},
|
||||
where: {clientFk: newClientFk, refFk: null},
|
||||
options
|
||||
});
|
||||
|
||||
|
@ -130,17 +132,12 @@ describe('InvoiceOut transfer()', () => {
|
|||
|
||||
expect(result).toBeUndefined();
|
||||
|
||||
// await tx.commit();
|
||||
const transferredTickets = await models.Ticket.find({
|
||||
where: {clientFk: newClientFk, invoiceOutFk: null},
|
||||
where: {clientFk: newClientFk, refFk: null},
|
||||
options
|
||||
});
|
||||
|
||||
expect(transferredTickets.length).toBeGreaterThan(originalTickets.length);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue