29 lines
974 B
JavaScript
29 lines
974 B
JavaScript
|
const models = require('vn-loopback/server/server').models;
|
||
|
const fs = require('fs-extra');
|
||
|
|
||
|
describe('image download()', () => {
|
||
|
const userId = 9;
|
||
|
const invoiceId = 1;
|
||
|
const ctx = {
|
||
|
req: {
|
||
|
|
||
|
accessToken: {userId: userId},
|
||
|
headers: {origin: 'http://localhost:5000'},
|
||
|
}
|
||
|
};
|
||
|
|
||
|
it('should return the downloaded file name', async() => {
|
||
|
spyOn(models.DocuwareContainer, 'container').and.returnValue({
|
||
|
client: {root: '/path'}
|
||
|
});
|
||
|
spyOn(fs, 'createReadStream').and.returnValue(new Promise(resolve => resolve('streamObject')));
|
||
|
spyOn(fs, 'access').and.returnValue(true);
|
||
|
spyOn(models.InvoiceOut, 'createPdf').and.returnValue(new Promise(resolve => resolve(true)));
|
||
|
|
||
|
const result = await models.InvoiceOut.download(ctx, invoiceId);
|
||
|
|
||
|
expect(result[1]).toEqual('application/pdf');
|
||
|
expect(result[2]).toMatch(/filename="\d{4}T1111111.pdf"/);
|
||
|
});
|
||
|
});
|