83 lines
2.5 KiB
JavaScript
83 lines
2.5 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
const axios = require('axios');
|
|
|
|
fdescribe('docuware download()', () => {
|
|
const ticketId = 1;
|
|
const userId = 9;
|
|
const ctx = {
|
|
req: {
|
|
|
|
accessToken: {userId: userId},
|
|
headers: {origin: 'http://localhost:5000'},
|
|
}
|
|
};
|
|
|
|
const docuwareModel = models.Docuware;
|
|
const fileCabinetName = 'deliveryNote';
|
|
|
|
beforeAll(() => {
|
|
spyOn(docuwareModel, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
spyOn(docuwareModel, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
});
|
|
|
|
it('should return false if there are no documents', async() => {
|
|
const response = {
|
|
data: {
|
|
Items: []
|
|
}
|
|
};
|
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
|
|
|
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName);
|
|
|
|
expect(result).toEqual(false);
|
|
});
|
|
|
|
it('should return false if the document is unsigned', async() => {
|
|
const response = {
|
|
data: {
|
|
Items: [
|
|
{
|
|
Id: 1,
|
|
Fields: [
|
|
{
|
|
FieldName: 'ESTADO',
|
|
Item: 'Unsigned'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
};
|
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
|
|
|
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName);
|
|
|
|
expect(result).toEqual(false);
|
|
});
|
|
|
|
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);
|
|
|
|
expect(result.id).toEqual(docuwareId);
|
|
});
|
|
});
|