136 lines
4.9 KiB
JavaScript
136 lines
4.9 KiB
JavaScript
const axios = require('axios');
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
describe('Docuware core', () => {
|
|
beforeAll(() => {
|
|
process.env.NODE_ENV = 'testing';
|
|
});
|
|
|
|
afterAll(() => {
|
|
delete process.env.NODE_ENV;
|
|
});
|
|
|
|
describe('getOptions()', () => {
|
|
it('should return url and headers', async() => {
|
|
const result = await models.Docuware.getOptions();
|
|
|
|
expect(result.url).toBeDefined();
|
|
expect(result.headers).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('getDialog()', () => {
|
|
it('should return dialogId', async() => {
|
|
const dialogs = {
|
|
data: {
|
|
Dialog: [
|
|
{
|
|
DisplayName: 'find',
|
|
Id: 'getDialogTest'
|
|
}
|
|
]
|
|
}
|
|
};
|
|
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
|
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
|
|
|
|
expect(result).toEqual('getDialogTest');
|
|
});
|
|
});
|
|
|
|
describe('getFileCabinet()', () => {
|
|
it('should return fileCabinetId', async() => {
|
|
const code = 'deliveryNote';
|
|
const docuwareInfo = await models.Docuware.findOne({
|
|
where: {
|
|
code
|
|
}
|
|
});
|
|
const dialogs = {
|
|
data: {
|
|
FileCabinet: [
|
|
{
|
|
Name: docuwareInfo.fileCabinetName,
|
|
Id: 'getFileCabinetTest'
|
|
}
|
|
]
|
|
}
|
|
};
|
|
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
|
const result = await models.Docuware.getFileCabinet(code);
|
|
|
|
expect(result).toEqual('getFileCabinetTest');
|
|
});
|
|
});
|
|
|
|
describe('get()', () => {
|
|
it('should return data without parse', async() => {
|
|
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
const data = {
|
|
data: {
|
|
id: 1
|
|
}
|
|
};
|
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
|
const result = await models.Docuware.get('deliveryNote');
|
|
|
|
expect(result.id).toEqual(1);
|
|
});
|
|
|
|
it('should return data with parse', async() => {
|
|
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
const data = {
|
|
data: {
|
|
Items: [{
|
|
Fields: [
|
|
{
|
|
ItemElementName: 'integer',
|
|
FieldLabel: 'firstRequiredField',
|
|
Item: 1
|
|
},
|
|
{
|
|
ItemElementName: 'string',
|
|
FieldLabel: 'secondRequiredField',
|
|
Item: 'myName'
|
|
},
|
|
{
|
|
ItemElementName: 'integer',
|
|
FieldLabel: 'notRequiredField',
|
|
Item: 2
|
|
}
|
|
]
|
|
}]
|
|
}
|
|
};
|
|
const parse = {
|
|
'firstRequiredField': 'id',
|
|
'secondRequiredField': 'name',
|
|
};
|
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
|
const [result] = await models.Docuware.get('deliveryNote', null, parse);
|
|
|
|
expect(result.id).toEqual(1);
|
|
expect(result.name).toEqual('myName');
|
|
expect(result.notRequiredField).not.toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('getById()', () => {
|
|
it('should return data', async() => {
|
|
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
const data = {
|
|
data: {
|
|
id: 1
|
|
}
|
|
};
|
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
|
const result = await models.Docuware.getById('deliveryNote', 1);
|
|
|
|
expect(result.id).toEqual(1);
|
|
});
|
|
});
|
|
});
|