refs #6184 saveCmr #1788
|
@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models;
|
|||
|
||||
describe('route downloadCmrsZip()', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(models.Route, 'downloadCmrsZip').and.returnValue([true]);
|
||||
spyOn(models.Route, 'downloadCmrsZip').and.returnValue(true);
|
||||
});
|
||||
|
||||
it('should create a zip file with the given cmr ids', async() => {
|
||||
|
@ -17,13 +17,13 @@ describe('route downloadCmrsZip()', () => {
|
|||
};
|
||||
let cmrs = '1,2';
|
||||
try {
|
||||
await models.Route.downloadCmrsZip(ctx, cmrs);
|
||||
const stream = await models.Route.downloadCmrsZip(ctx, cmrs);
|
||||
|
||||
expect(stream).toBeTrue();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('ticket saveCmr()', () => {
|
||||
let ctx = {req: {
|
||||
accessToken: {userId: 9}
|
||||
}};
|
||||
|
||||
it(`should throw error if the cmr can't save`, async() => {
|
||||
const tx = await models.Route.beginTransaction({});
|
||||
let error;
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const ticket = [1];
|
||||
await models.Route.saveCmr(ctx, ticket, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,45 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('ticket saveCmr()', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(models.Ticket, 'saveCmr').and.returnValue(true);
|
||||
});
|
||||
|
||||
it(`should throw error if the cmr can't save`, async() => {
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
const ctx = {
|
||||
req: {
|
||||
getLocale: () => {
|
||||
return 'en';
|
||||
},
|
||||
accessToken: {userId: 9}
|
||||
},
|
||||
args: {}
|
||||
};
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const ticket = [1];
|
||||
await models.Ticket.saveCmr(ctx, ticket);
|
||||
|
||||
const hasDmsCmr = await models.TicketDms.findOne({
|
||||
where: {ticketFk: ticket[1]},
|
||||
include: [{
|
||||
relation: 'dms',
|
||||
fields: ['id'],
|
||||
scope: {
|
||||
relation: 'dmsType',
|
||||
scope: {
|
||||
where: {code: 'cmr'}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, options);
|
||||
|
||||
expect(hasDmsCmr?.dms()?.dmsType()).toEqual(1);
|
||||
guillermo marked this conversation as resolved
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Si el titul del test es 'should throw error if the cmr can't save' el test deuria de testejar que falle la peticio