Mock report pdf
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2022-10-05 16:19:07 +02:00
parent 045825b45d
commit b134aeb0ea
2 changed files with 10 additions and 18 deletions

View File

@ -1,5 +1,5 @@
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
const {Report, storage} = require('vn-print'); const print = require('vn-print');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('createPdf', { Self.remoteMethodCtx('createPdf', {
@ -52,7 +52,7 @@ module.exports = Self => {
hasPdf: true hasPdf: true
}, myOptions); }, myOptions);
const invoiceReport = new Report('invoice', { const invoiceReport = new print.Report('invoice', {
reference: invoiceOut.ref, reference: invoiceOut.ref,
recipientId: invoiceOut.clientFk recipientId: invoiceOut.clientFk
}); });
@ -66,7 +66,7 @@ module.exports = Self => {
const fileName = `${year}${invoiceOut.ref}.pdf`; const fileName = `${year}${invoiceOut.ref}.pdf`;
// Store invoice // Store invoice
storage.write(stream, { print.storage.write(stream, {
type: 'invoice', type: 'invoice',
path: `${year}/${month}/${day}`, path: `${year}/${month}/${day}`,
fileName: fileName fileName: fileName

View File

@ -1,7 +1,6 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
const fs = require('fs-extra'); const print = require('vn-print');
const axios = require('axios');
describe('InvoiceOut createPdf()', () => { describe('InvoiceOut createPdf()', () => {
const userId = 1; const userId = 1;
@ -16,22 +15,15 @@ describe('InvoiceOut createPdf()', () => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx active: activeCtx
}); });
const response = {
data: { spyOn(print, 'Report').and.returnValue({
pipe: () => {}, toPdfStream: () => {
on: () => {}, return '';
} }
};
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(response)));
spyOn(models.InvoiceContainer, 'container').and.returnValue({
client: {root: '/path'}
});
spyOn(fs, 'mkdir').and.returnValue(true);
spyOn(fs, 'createWriteStream').and.returnValue({
on: (event, cb) => cb(),
end: () => {}
}); });
spyOn(print.storage, 'write').and.returnValue(true);
const tx = await models.InvoiceOut.beginTransaction({}); const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};