refs #6184 saveCmr #1788

Merged
guillermo merged 58 commits from 6184-saveCmr into dev 2024-02-13 06:47:06 +00:00
3 changed files with 50 additions and 29 deletions
Showing only changes of commit f2946e4168 - Show all commits

View File

@ -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();
});
});

View File

@ -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();
});
});

View File

@ -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
Review

Si el titul del test es 'should throw error if the cmr can't save' el test deuria de testejar que falle la peticio

Si el titul del test es 'should throw error if the cmr can't save' el test deuria de testejar que falle la peticio
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});