test(salix): refs #5926 docuware.core.spec
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
82fcc157be
commit
23553a3694
|
@ -114,6 +114,9 @@ module.exports = Self => {
|
|||
* @return {number} - The fileCabinet id
|
||||
*/
|
||||
Self.getDialog = async(code, action, fileCabinetId) => {
|
||||
if (!env && !Self.hasDeviceReady())
|
||||
return Math.floor(Math.random() + 100);
|
||||
|
||||
const docuwareInfo = await Self.getDocuware({
|
||||
where: {
|
||||
code,
|
||||
|
@ -138,8 +141,8 @@ module.exports = Self => {
|
|||
* @return {number} - The fileCabinet id
|
||||
*/
|
||||
Self.getFileCabinet = async code => {
|
||||
// if (!process.env.NODE_ENV)
|
||||
// return Math.floor(Math.random() + 100);
|
||||
if (!env && !Self.hasDeviceReady())
|
||||
return Math.floor(Math.random() + 100);
|
||||
|
||||
const options = await Self.getOptions();
|
||||
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
||||
|
@ -164,6 +167,8 @@ module.exports = Self => {
|
|||
* @return {object} - The data
|
||||
*/
|
||||
Self.get = async(code, filter, parse) => {
|
||||
if (!env && !Self.hasDeviceReady()) return;
|
||||
|
||||
const options = await Self.getOptions();
|
||||
const fileCabinetId = await Self.getFileCabinet(code);
|
||||
const dialogId = await Self.getDialog(code, 'find', fileCabinetId);
|
||||
|
@ -185,7 +190,7 @@ module.exports = Self => {
|
|||
* @return {object} - The data
|
||||
*/
|
||||
Self.getById = async(code, id, parse) => {
|
||||
if (!process.env.NODE_ENV) return;
|
||||
if (!env && !Self.hasDeviceReady()) return;
|
||||
|
||||
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
||||
fields: ['findById'],
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
const axios = require('axios');
|
||||
const models = require('vn-loopback/server/server').models;
|
||||
const {Docuware} = require('vn-loopback/server/server').models;
|
||||
|
||||
fdescribe('Docuware core', () => {
|
||||
beforeAll(() => {
|
||||
process.env.NODE_ENV = 'testing';
|
||||
spyOn(Docuware, 'hasDeviceReady').and.returnValue(true);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
@ -12,19 +13,19 @@ fdescribe('Docuware core', () => {
|
|||
|
||||
describe('hasDeviceReady()', () => {
|
||||
it('should return true', async() => {
|
||||
const result = await models.Docuware.hasDeviceReady({device: 'Tablet 1'});
|
||||
const result = await Docuware.hasDeviceReady({device: 'Tablet 1'});
|
||||
|
||||
expect(result).toBeTrue();
|
||||
});
|
||||
|
||||
it('should return false', async() => {
|
||||
const result = await models.Docuware.hasDeviceReady({device: null});
|
||||
const result = await Docuware.hasDeviceReady({device: null});
|
||||
|
||||
expect(result).toBeFalse();
|
||||
});
|
||||
|
||||
it('should not exists return false ', async() => {
|
||||
const result = await models.Docuware.hasDeviceReady();
|
||||
const result = await Docuware.hasDeviceReady();
|
||||
|
||||
expect(result).toBeFalse();
|
||||
});
|
||||
|
@ -32,14 +33,14 @@ fdescribe('Docuware core', () => {
|
|||
|
||||
describe('getOptions()', () => {
|
||||
it('should return url and headers', async() => {
|
||||
const result = await models.Docuware.getOptions();
|
||||
const result = await Docuware.getOptions();
|
||||
|
||||
expect(result.url).toBeDefined();
|
||||
expect(result.headers).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDialog()', () => {
|
||||
fdescribe('getDialog()', () => {
|
||||
it('should return dialogId', async() => {
|
||||
const dialogs = {
|
||||
data: {
|
||||
|
@ -52,7 +53,7 @@ fdescribe('Docuware core', () => {
|
|||
}
|
||||
};
|
||||
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
||||
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
|
||||
const result = await Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
|
||||
|
||||
expect(result).toEqual('getDialogTest');
|
||||
});
|
||||
|
@ -78,7 +79,7 @@ fdescribe('Docuware core', () => {
|
|||
value: 'Tablet123'
|
||||
}
|
||||
};
|
||||
const result = await models.Docuware.buildTemplateJSON(config);
|
||||
const result = await Docuware.buildTemplateJSON(config);
|
||||
|
||||
expect(result).toEqual({
|
||||
'Fields': [
|
||||
|
@ -109,7 +110,7 @@ fdescribe('Docuware core', () => {
|
|||
|
||||
describe('uploadOptions()', () => {
|
||||
it('should return uploadOptions', async() => {
|
||||
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
spyOn(Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
|
||||
// const dialogs = {
|
||||
// data: {
|
||||
|
@ -122,7 +123,7 @@ fdescribe('Docuware core', () => {
|
|||
// }
|
||||
// };
|
||||
// spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
||||
const {uploadOptions: result} = await models.Docuware.uploadOptions(1, {
|
||||
const {uploadOptions: result} = await Docuware.uploadOptions(1, {
|
||||
'N__DOCUMENTO': {
|
||||
type: 'string',
|
||||
value: '12345'
|
||||
|
@ -136,7 +137,7 @@ fdescribe('Docuware core', () => {
|
|||
|
||||
describe('deleteOld()', () => {
|
||||
it('should return deleteOld', async() => {
|
||||
await models.Docuware.deleteOld(1, 'deliveryNote', {
|
||||
await Docuware.deleteOld(1, 'deliveryNote', {
|
||||
'N__DOCUMENTO': {
|
||||
type: 'string',
|
||||
value: '12345'
|
||||
|
@ -144,10 +145,10 @@ fdescribe('Docuware core', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('getFileCabinet()', () => {
|
||||
fdescribe('getFileCabinet()', () => {
|
||||
it('should return fileCabinetId', async() => {
|
||||
const code = 'deliveryNote';
|
||||
const docuwareInfo = await models.Docuware.findOne({
|
||||
const docuwareInfo = await Docuware.findOne({
|
||||
where: {
|
||||
code
|
||||
}
|
||||
|
@ -163,30 +164,30 @@ fdescribe('Docuware core', () => {
|
|||
}
|
||||
};
|
||||
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
||||
const result = await models.Docuware.getFileCabinet(code);
|
||||
const result = await Docuware.getFileCabinet(code);
|
||||
|
||||
expect(result).toEqual('getFileCabinetTest');
|
||||
});
|
||||
});
|
||||
|
||||
describe('get()', () => {
|
||||
fdescribe('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()))));
|
||||
spyOn(Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
spyOn(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');
|
||||
const result = await 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()))));
|
||||
fit('should return data with parse', async() => {
|
||||
spyOn(Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
spyOn(Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
const data = {
|
||||
data: {
|
||||
Items: [{
|
||||
|
@ -215,7 +216,7 @@ fdescribe('Docuware core', () => {
|
|||
'secondRequiredField': 'name',
|
||||
};
|
||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
||||
const [result] = await models.Docuware.get('deliveryNote', null, parse);
|
||||
const [result] = await Docuware.get('deliveryNote', null, parse);
|
||||
|
||||
expect(result.id).toEqual(1);
|
||||
expect(result.name).toEqual('myName');
|
||||
|
@ -223,17 +224,17 @@ fdescribe('Docuware core', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('getById()', () => {
|
||||
fdescribe('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()))));
|
||||
spyOn(Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||
spyOn(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);
|
||||
const result = await Docuware.getById('deliveryNote', 1);
|
||||
|
||||
expect(result.id).toEqual(1);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue