salix/back/methods/docuware/specs/checkFile.spec.js

83 lines
2.5 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
2023-01-12 14:16:38 +00:00
const axios = require('axios');
describe('docuware download()', () => {
const ticketId = 1;
const userId = 9;
const ctx = {
req: {
accessToken: {userId: userId},
headers: {origin: 'http://localhost:5000'},
}
};
2023-01-12 14:16:38 +00:00
const docuwareModel = models.Docuware;
const fileCabinetName = 'deliveryNote';
2023-01-12 14:16:38 +00:00
beforeAll(() => {
spyOn(docuwareModel, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
spyOn(docuwareModel, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
});
2023-01-12 14:16:38 +00:00
it('should return false if there are no documents', async() => {
const response = {
data: {
Items: []
}
};
2023-01-12 14:16:38 +00:00
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
2023-01-12 14:16:38 +00:00
expect(result).toEqual(false);
2022-02-16 13:57:47 +00:00
});
2023-01-12 14:16:38 +00:00
it('should return false if the document is unsigned', async() => {
const response = {
data: {
Items: [
{
Id: 1,
Fields: [
{
FieldName: 'ESTADO',
Item: 'Unsigned'
}
]
}
]
}
};
2023-01-12 14:16:38 +00:00
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
2022-02-16 13:57:47 +00:00
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
2022-02-16 13:57:47 +00:00
expect(result).toEqual(false);
2022-02-16 13:57:47 +00:00
});
2023-01-12 14:16:38 +00:00
it('should return the document data', async() => {
const docuwareId = 1;
const response = {
data: {
Items: [
{
Id: docuwareId,
Fields: [
{
FieldName: 'ESTADO',
Item: 'Firmado'
}
]
}
]
}
};
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
2023-01-12 14:16:38 +00:00
expect(result.id).toEqual(docuwareId);
});
2022-02-16 13:57:47 +00:00
});