fix: backTest
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2022-10-26 09:49:58 +02:00
parent ec81b12239
commit e0e015c268
2 changed files with 31 additions and 9 deletions

View File

@ -33,7 +33,7 @@ module.exports = Self => {
const zip = new JSZip();
let totalSize = 0;
const zipConfig = await models.ZipConfig.findOne();
const zipConfig = await models.ZipConfig.findOne(null, myOptions);
for (let id of ids) {
if (zipConfig && totalSize > zipConfig.maxSize) throw new UserError('Files are too large');
const invoiceOutPdf = await models.InvoiceOut.download(ctx, id, myOptions);

View File

@ -1,4 +1,5 @@
const models = require('vn-loopback/server/server').models;
const UserError = require('vn-loopback/util/user-error');
describe('InvoiceOut downloadZip()', () => {
const userId = 9;
@ -12,20 +13,41 @@ describe('InvoiceOut downloadZip()', () => {
};
it('should return part of link to dowloand the zip', async() => {
const result = await models.InvoiceOut.downloadZip(ctx, invoiceIds);
const tx = await models.Order.beginTransaction({});
expect(result).toBeDefined();
try {
const options = {transaction: tx};
const result = await models.InvoiceOut.downloadZip(ctx, invoiceIds, options);
expect(result).toBeDefined();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should return an error if the size of the files is too large', async() => {
const zipConfig = {
maxSize: 0
};
const tx = await models.Order.beginTransaction({});
await models.ZipConfig.create(zipConfig);
let error;
try {
const options = {transaction: tx};
const zipConfig = {
maxSize: 0
};
await models.ZipConfig.create(zipConfig, options);
const result = await models.InvoiceOut.downloadZip(ctx, invoiceIds);
await models.InvoiceOut.downloadZip(ctx, invoiceIds, options);
expect(result).toBe(false);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error).toEqual(new UserError(`Files are too large`));
});
});