Merge branch 'master' into 8119-itemCampaignQuantity
gitea/salix/pipeline/pr-master There was a failure building this commit
Details
gitea/salix/pipeline/pr-master There was a failure building this commit
Details
This commit is contained in:
commit
a8525c5ba8
|
@ -4,21 +4,45 @@ module.exports = Self => {
|
|||
/**
|
||||
* Returns basic headers
|
||||
*
|
||||
* @param {string} cookie - The docuware cookie
|
||||
* @return {object} - The headers
|
||||
*/
|
||||
Self.getOptions = async() => {
|
||||
const docuwareConfig = await Self.app.models.DocuwareConfig.findOne();
|
||||
const now = Date.vnNow();
|
||||
let {url, username, password, token, expired} = docuwareConfig;
|
||||
|
||||
if (process.env.NODE_ENV && (!expired || expired < now + 60)) {
|
||||
const {data: {IdentityServiceUrl}} = await axios.get(`${url}/Home/IdentityServiceInfo`);
|
||||
const {data: {token_endpoint}} = await axios.get(`${IdentityServiceUrl}/.well-known/openid-configuration`);
|
||||
const {data} = await axios.post(token_endpoint, {
|
||||
grant_type: 'password',
|
||||
scope: 'docuware.platform',
|
||||
client_id: 'docuware.platform.net.client',
|
||||
username,
|
||||
password
|
||||
}, {headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}});
|
||||
|
||||
const newToken = data.access_token;
|
||||
token = data.token_type + ' ' + newToken;
|
||||
await docuwareConfig.updateAttributes({
|
||||
token,
|
||||
expired: now + data.expires_in
|
||||
});
|
||||
}
|
||||
|
||||
const headers = {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'Cookie': docuwareConfig.cookie
|
||||
'Authorization': token
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
url: docuwareConfig.url,
|
||||
url,
|
||||
headers
|
||||
};
|
||||
};
|
||||
|
|
|
@ -2,26 +2,21 @@ const axios = require('axios');
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Docuware core', () => {
|
||||
beforeAll(() => {
|
||||
const fileCabinetCode = 'deliveryNote';
|
||||
beforeAll(async() => {
|
||||
process.env.NODE_ENV = 'testing';
|
||||
|
||||
const docuwareInfo = await models.Docuware.findOne({
|
||||
where: {
|
||||
code: fileCabinetCode
|
||||
}
|
||||
});
|
||||
|
||||
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 = {
|
||||
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: [
|
||||
{
|
||||
|
@ -31,58 +26,30 @@ describe('Docuware core', () => {
|
|||
]
|
||||
}
|
||||
};
|
||||
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: {
|
||||
|
||||
if (url.includes('FileCabinets')) {
|
||||
return {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.callFake(url => {
|
||||
if (url.includes('token_endpoint')) {
|
||||
return {data: {
|
||||
access_token: 'access_token',
|
||||
token_type: 'bearer',
|
||||
expires_in: 10000
|
||||
}};
|
||||
}
|
||||
};
|
||||
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: {
|
||||
if (url.includes('DialogExpression')) {
|
||||
return {data: {
|
||||
Items: [{
|
||||
Fields: [
|
||||
{
|
||||
|
@ -104,11 +71,51 @@ describe('Docuware core', () => {
|
|||
}]
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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('Dialog()', () => {
|
||||
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() => {
|
||||
const result = await models.Docuware.getFileCabinet(fileCabinetCode);
|
||||
|
||||
expect(result).toEqual('getFileCabinetTest');
|
||||
});
|
||||
});
|
||||
|
||||
describe('get()', () => {
|
||||
it('should return data without parse', async() => {
|
||||
const [result] = await models.Docuware.get('deliveryNote');
|
||||
|
||||
expect(result.firstRequiredField).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return data with parse', async() => {
|
||||
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);
|
||||
|
@ -119,17 +126,14 @@ describe('Docuware core', () => {
|
|||
|
||||
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);
|
||||
spyOn(models.Docuware, 'get');
|
||||
await models.Docuware.getById('deliveryNote', 1);
|
||||
|
||||
expect(result.id).toEqual(1);
|
||||
expect(models.Docuware.get).toHaveBeenCalledWith(
|
||||
'deliveryNote',
|
||||
{condition: [Object({DBName: 'N__ALBAR_N', Value: [1]})]},
|
||||
undefined
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -143,7 +143,7 @@ module.exports = Self => {
|
|||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
'X-File-ModifiedDate': Date.vnNew(),
|
||||
'Cookie': docuwareOptions.headers.headers.Cookie,
|
||||
'Authorization': docuwareOptions.headers.headers.Authorization,
|
||||
...data.getHeaders()
|
||||
},
|
||||
};
|
||||
|
|
|
@ -16,17 +16,17 @@
|
|||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"cookie": {
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"property": "*",
|
||||
"accessType": "*",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"expired":{
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS username varchar(100) NULL;
|
||||
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS password varchar(100) NULL;
|
||||
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS token text NULL;
|
||||
ALTER TABLE vn.docuwareConfig ADD IF NOT EXISTS expired int(11) NULL;
|
Loading…
Reference in New Issue