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

140 lines
4.5 KiB
JavaScript
Raw Normal View History

2023-07-05 10:09:52 +00:00
const axios = require('axios');
const models = require('vn-loopback/server/server').models;
describe('Docuware core', () => {
2024-10-16 07:03:47 +00:00
const fileCabinetCode = 'deliveryNote';
beforeAll(async() => {
2023-07-05 10:09:52 +00:00
process.env.NODE_ENV = 'testing';
2024-10-16 07:03:47 +00:00
const docuwareInfo = await models.Docuware.findOne({
where: {
code: fileCabinetCode
}
});
spyOn(axios, 'get').and.callFake(url => {
if (url.includes('IdentityServiceInfo')) return {data: {IdentityServiceUrl: 'IdentityServiceUrl'}};
if (url.includes('IdentityServiceUrl')) return {data: {token_endpoint: 'token_endpoint'}};
if (url.includes('dialogs')) {
return {
data: {
Dialog: [
{
DisplayName: 'find',
Id: 'getDialogTest'
}
]
}
};
}
if (url.includes('FileCabinets')) {
return {data: {
FileCabinet: [
{
Name: docuwareInfo.fileCabinetName,
Id: 'getFileCabinetTest'
}
]
}};
}
});
spyOn(axios, 'post').and.callFake(url => {
if (url.includes('token_endpoint')) {
return {data: {
access_token: 'access_token',
token_type: 'bearer',
expires_in: 10000
}};
}
if (url.includes('DialogExpression')) {
return {data: {
Items: [{
Fields: [
{
ItemElementName: 'integer',
FieldLabel: 'firstRequiredField',
Item: 1
},
{
ItemElementName: 'string',
FieldLabel: 'secondRequiredField',
Item: 'myName'
},
{
ItemElementName: 'integer',
FieldLabel: 'notRequiredField',
Item: 2
}
]
}]
}
};
}
});
2023-07-05 10:09:52 +00:00
});
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();
});
});
2024-10-16 07:03:47 +00:00
describe('Dialog()', () => {
2023-07-05 10:09:52 +00:00
it('should return dialogId', async() => {
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
expect(result).toEqual('getDialogTest');
});
});
describe('getFileCabinet()', () => {
it('should return fileCabinetId', async() => {
2024-10-16 07:03:47 +00:00
const result = await models.Docuware.getFileCabinet(fileCabinetCode);
2023-07-05 10:09:52 +00:00
expect(result).toEqual('getFileCabinetTest');
});
});
describe('get()', () => {
it('should return data without parse', async() => {
2024-10-16 07:03:47 +00:00
const [result] = await models.Docuware.get('deliveryNote');
2023-07-05 10:09:52 +00:00
2024-10-16 07:03:47 +00:00
expect(result.firstRequiredField).toEqual(1);
2023-07-05 10:09:52 +00:00
});
it('should return data with parse', async() => {
const parse = {
'firstRequiredField': 'id',
'secondRequiredField': 'name',
};
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() => {
2024-10-16 07:03:47 +00:00
spyOn(models.Docuware, 'get');
await models.Docuware.getById('deliveryNote', 1);
2023-07-05 10:09:52 +00:00
2024-10-16 07:03:47 +00:00
expect(models.Docuware.get).toHaveBeenCalledWith(
'deliveryNote',
{condition: [Object({DBName: 'N__ALBAR_N', Value: [1]})]},
undefined
);
2023-07-05 10:09:52 +00:00
});
});
});