diff --git a/modules/invoiceOut/back/methods/invoiceOut/downloadZip.js b/modules/invoiceOut/back/methods/invoiceOut/downloadZip.js index 834d3c031..72a00b764 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/downloadZip.js +++ b/modules/invoiceOut/back/methods/invoiceOut/downloadZip.js @@ -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); diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js index c39b41567..7a9e184ea 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js @@ -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`)); }); });