fix: refs #6184 Requested changes
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Guillermo Bonet 2024-02-06 08:04:19 +01:00
parent d6ae1fd1f8
commit f2946e4168
3 changed files with 50 additions and 29 deletions

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);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});