mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[PRODENG-211] integrate JS-API with monorepo (part 1) (#9081)
* integrate JS-API with monorepo * [ci:force] fix token issue [ci:force] migrate docs folder [ci:force] clean personal tokens * [ci:force] gha workflow support * [ci:force] npm publish target * fix js-api test linting * [ci:force] fix test linting, mocks, https scheme * [ci:force] fix https scheme * [ci:force] typescript mappings * [ci:force] update scripts * lint fixes * linting fixes * fix linting * [ci:force] linting fixes * linting fixes * [ci:force] remove js-api upstream and corresponding scripts * [ci:force] jsdoc fixes * fix jsdoc linting * [ci:force] jsdoc fixes * [ci:force] jsdoc fixes * jsdoc fixes * jsdoc fixes * jsdoc fixes * [ci:force] fix jsdoc * [ci:force] reduce code duplication * replace 'chai' expect with node.js assert * replace 'chai' expect with node.js assert * [ci:force] remove chai and chai-spies for js-api testing * [ci:force] cleanup and fix imports * [ci:force] fix linting * [ci:force] fix unit test * [ci:force] fix sonar linting findings * [ci:force] switch activiti api models to interfaces (-2.5% reduction of bundle) * [ci:force] switch activiti api models to interfaces * [ci:force] switch AGS api models to interfaces * [ci:force] switch AGS api models to interfaces * [ci:force] switch search api models to interfaces * [ci:force] switch content api models to interfaces where applicable
This commit is contained in:
309
lib/js-api/test/alfrescoApi.spec.ts
Normal file
309
lib/js-api/test/alfrescoApi.spec.ts
Normal file
@@ -0,0 +1,309 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi } from '../src';
|
||||
import { BpmAuthMock, EcmAuthMock, OAuthMock } from './mockObjects';
|
||||
|
||||
describe('Basic configuration test', () => {
|
||||
describe('config parameter ', () => {
|
||||
it('Should basePath have a default value', () => {
|
||||
const alfrescoJsApi = new AlfrescoApi({});
|
||||
|
||||
assert.equal(alfrescoJsApi.contentClient.basePath, 'http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1');
|
||||
});
|
||||
|
||||
it('should be reflected in the client', () => {
|
||||
const config = {
|
||||
hostEcm: 'https://testServer.com:1616',
|
||||
contextRoot: 'strangeContextRoot'
|
||||
};
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi(config);
|
||||
|
||||
assert.equal(
|
||||
alfrescoJsApi.contentClient.basePath,
|
||||
'https://testServer.com:1616/strangeContextRoot/api/-default-/public/alfresco/versions/1'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setconfig parameter ', () => {
|
||||
it('should be possible change the host in the client', () => {
|
||||
const config = {
|
||||
hostEcm: 'https://testServer.com:1616',
|
||||
contextRoot: 'strangeContextRoot'
|
||||
};
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi(config);
|
||||
|
||||
assert.equal(
|
||||
alfrescoJsApi.contentClient.basePath,
|
||||
'https://testServer.com:1616/strangeContextRoot/api/-default-/public/alfresco/versions/1'
|
||||
);
|
||||
|
||||
const newConfig = {
|
||||
hostEcm: 'https://testServer.com:2616',
|
||||
contextRoot: 'strangeContextRoot'
|
||||
};
|
||||
|
||||
alfrescoJsApi.setConfig(newConfig);
|
||||
|
||||
assert.equal(
|
||||
alfrescoJsApi.contentClient.basePath,
|
||||
'https://testServer.com:2616/strangeContextRoot/api/-default-/public/alfresco/versions/1'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('CSRF', () => {
|
||||
it('should disableCsrf true parameter should be reflected in the clients', () => {
|
||||
const config = {
|
||||
hostEcm: 'https://testServer.com:1616',
|
||||
contextRoot: 'strangeContextRoot',
|
||||
disableCsrf: true
|
||||
};
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi(config);
|
||||
|
||||
assert.equal(alfrescoJsApi.contentClient.isCsrfEnabled(), false);
|
||||
assert.equal(alfrescoJsApi.processClient.isCsrfEnabled(), false);
|
||||
});
|
||||
|
||||
it('should disableCsrf false parameter should be reflected in the clients', () => {
|
||||
const config = {
|
||||
hostEcm: 'https://testServer.com:1616',
|
||||
contextRoot: 'strangeContextRoot',
|
||||
disableCsrf: false
|
||||
};
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi(config);
|
||||
|
||||
assert.equal(alfrescoJsApi.contentClient.isCsrfEnabled(), true);
|
||||
assert.equal(alfrescoJsApi.processClient.isCsrfEnabled(), true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('WithCredentials', () => {
|
||||
it('should withCredentials true parameter should be reflected in the clients', () => {
|
||||
const config = {
|
||||
hostEcm: 'https://testServer.com:1616',
|
||||
contextRoot: 'strangeContextRoot',
|
||||
withCredentials: true
|
||||
};
|
||||
const alfrescoJsApi = new AlfrescoApi(config);
|
||||
assert.equal(alfrescoJsApi.contentClient.isWithCredentials(), true);
|
||||
assert.equal(alfrescoJsApi.processClient.isWithCredentials(), true);
|
||||
});
|
||||
|
||||
it('should withCredentials true parameter with hostEcm should be reflected in isEcmLoggedIn', () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm,
|
||||
provider: 'ECM',
|
||||
withCredentials: true
|
||||
});
|
||||
|
||||
assert.equal(alfrescoJsApi.isEcmLoggedIn(), true);
|
||||
});
|
||||
|
||||
it('should withCredentials true parameter with hostEcm should be reflected in isLoggedIn', () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm,
|
||||
provider: 'ECM',
|
||||
withCredentials: true
|
||||
});
|
||||
|
||||
assert.equal(alfrescoJsApi.isLoggedIn(), true);
|
||||
});
|
||||
|
||||
it('should withCredentials true parameter with ALL provider should be reflected in isLoggedIn', () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm,
|
||||
provider: 'ALL',
|
||||
withCredentials: true
|
||||
});
|
||||
|
||||
assert.equal(alfrescoJsApi.isLoggedIn(), true);
|
||||
});
|
||||
|
||||
it('should withCredentials false parameter should be reflected in the clients', () => {
|
||||
const config = {
|
||||
hostEcm: 'https://testServer.com:1616',
|
||||
contextRoot: 'strangeContextRoot',
|
||||
withCredentials: false
|
||||
};
|
||||
const alfrescoJsApi = new AlfrescoApi(config);
|
||||
assert.equal(alfrescoJsApi.contentClient.isWithCredentials(), false);
|
||||
assert.equal(alfrescoJsApi.processClient.isWithCredentials(), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('login', () => {
|
||||
it('Should login be rejected if username or password are not provided', async () => {
|
||||
const config = {
|
||||
hostEcm: 'https://testServer.com:1616',
|
||||
contextRoot: 'strangeContextRoot',
|
||||
withCredentials: true
|
||||
};
|
||||
const alfrescoJsApi = new AlfrescoApi(config);
|
||||
|
||||
let error;
|
||||
|
||||
try {
|
||||
await alfrescoJsApi.login(undefined, undefined);
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
|
||||
assert.equal(error, 'missing username or password');
|
||||
|
||||
error = undefined;
|
||||
|
||||
try {
|
||||
await alfrescoJsApi.login('username', undefined);
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
|
||||
assert.equal(error, 'missing username or password');
|
||||
|
||||
error = undefined;
|
||||
|
||||
try {
|
||||
await alfrescoJsApi.login(undefined, 'password');
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
|
||||
assert.equal(error, 'missing username or password');
|
||||
|
||||
error = undefined;
|
||||
|
||||
try {
|
||||
await alfrescoJsApi.login('', '');
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
|
||||
assert.equal(error, 'missing username or password');
|
||||
|
||||
error = undefined;
|
||||
|
||||
try {
|
||||
await alfrescoJsApi.login('username', '');
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
|
||||
assert.equal(error, 'missing username or password');
|
||||
|
||||
error = undefined;
|
||||
|
||||
try {
|
||||
await alfrescoJsApi.login('', 'password');
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
|
||||
assert.equal(error, 'missing username or password');
|
||||
});
|
||||
|
||||
it('Should logged-in be emitted when log in ECM', (done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
const authEcmMock = new EcmAuthMock(hostEcm);
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm,
|
||||
provider: 'ECM'
|
||||
});
|
||||
|
||||
authEcmMock.get201Response();
|
||||
|
||||
alfrescoJsApi.on('logged-in', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('Should logged-in be emitted when log in BPM', (done) => {
|
||||
const hostBpm = 'https://127.0.0.1:9999';
|
||||
const authBpmMock = new BpmAuthMock(hostBpm);
|
||||
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app',
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
alfrescoJsApi.on('logged-in', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('Should logged-in be emitted when log in OAUTH', (done) => {
|
||||
const oauth2Mock = new OAuthMock('https://myOauthUrl:30081');
|
||||
|
||||
oauth2Mock.get200Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
});
|
||||
|
||||
alfrescoJsApi.on('logged-in', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('Should logged-in be emitted when the ticket is in the store', (done) => {
|
||||
const hostBpm = 'https://127.0.0.1:9999';
|
||||
const authBpmMock = new BpmAuthMock(hostBpm);
|
||||
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app',
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
alfrescoJsApi.reply('logged-in', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
79
lib/js-api/test/alfrescoApiClient.spec.ts
Normal file
79
lib/js-api/test/alfrescoApiClient.spec.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, DateAlfresco } from '../src';
|
||||
import { EcmAuthMock } from './mockObjects';
|
||||
|
||||
describe('Alfresco Core API Client', () => {
|
||||
describe('type conversion', () => {
|
||||
it('should return the username after login', (done) => {
|
||||
const authResponseEcmMock = new EcmAuthMock('https://127.0.0.1:8080');
|
||||
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm: 'https://127.0.0.1:8080'
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
assert.equal(alfrescoJsApi.getEcmUsername(), 'admin');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('date parsing', () => {
|
||||
const equalTime = (actual: Date, expected: Date) => actual.getTime() === expected.getTime();
|
||||
|
||||
it('should convert dates falling in GMT without a timezone', () => {
|
||||
assert.equal(equalTime(DateAlfresco.parseDate('2015-11-17T03:33:17'), new Date(Date.UTC(2015, 10, 17, 3, 33, 17))), true);
|
||||
});
|
||||
|
||||
it('should convert dates falling in BST without a timezone', () => {
|
||||
assert.equal(equalTime(DateAlfresco.parseDate('2015-10-17T03:33:17'), new Date(Date.UTC(2015, 9, 17, 3, 33, 17))), true);
|
||||
});
|
||||
|
||||
it('should convert dates with a UTC Zulu-time timezone', () => {
|
||||
assert.equal(equalTime(DateAlfresco.parseDate('2015-11-17T03:33:17Z'), new Date(Date.UTC(2015, 10, 17, 3, 33, 17))), true);
|
||||
});
|
||||
|
||||
it('should convert dates with a UTC zero-offset timezone', () => {
|
||||
assert.equal(equalTime(DateAlfresco.parseDate('2015-11-17T03:33:17+0000'), new Date(Date.UTC(2015, 10, 17, 3, 33, 17))), true);
|
||||
});
|
||||
|
||||
it('should convert dates with a positive offset timezone', () => {
|
||||
assert.equal(equalTime(DateAlfresco.parseDate('2015-11-17T03:33:17+0200'), new Date(Date.UTC(2015, 10, 17, 1, 33, 17))), true);
|
||||
});
|
||||
|
||||
it('should convert dates with a negative offset timezone', () => {
|
||||
assert.equal(equalTime(DateAlfresco.parseDate('2015-11-17T03:33:17-0200'), new Date(Date.UTC(2015, 10, 17, 5, 33, 17))), true);
|
||||
});
|
||||
|
||||
it('should convert dates with a part-hour offset', () => {
|
||||
assert.equal(equalTime(DateAlfresco.parseDate('2015-11-17T03:23:17-0930'), new Date(Date.UTC(2015, 10, 17, 12, 53, 17))), true);
|
||||
});
|
||||
|
||||
it('should convert dates with a timezone HH:MM separator', () => {
|
||||
assert.equal(equalTime(DateAlfresco.parseDate('2015-11-17T03:33:17+02:00'), new Date(Date.UTC(2015, 10, 17, 1, 33, 17))), true);
|
||||
});
|
||||
|
||||
it('should convert dates with a timezone with hours only', () => {
|
||||
assert.equal(equalTime(DateAlfresco.parseDate('2015-11-17T03:33:17+02'), new Date(Date.UTC(2015, 10, 17, 1, 33, 17))), true);
|
||||
});
|
||||
});
|
||||
});
|
230
lib/js-api/test/alfrescoContent.spec.ts
Normal file
230
lib/js-api/test/alfrescoContent.spec.ts
Normal file
@@ -0,0 +1,230 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, ContentApi } from '../src';
|
||||
import { EcmAuthMock } from './mockObjects';
|
||||
|
||||
describe('AlfrescoContent', () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
const nodesUrl = hostEcm + '/alfresco/api/-default-/public/alfresco/versions/1/nodes/';
|
||||
const sharedLinksUrl = hostEcm + '/alfresco/api/-default-/public/alfresco/versions/1/shared-links/';
|
||||
const nodeId = '1a0b110f-1e09-4ca2-b367-fe25e4964a4';
|
||||
const versionId = '1.1';
|
||||
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let contentApi: ContentApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
authResponseMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
contentApi = new ContentApi(alfrescoJsApi);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('outputs thumbnail url', () => {
|
||||
const thumbnailUrl = contentApi.getDocumentThumbnailUrl(nodeId);
|
||||
|
||||
assert.equal(
|
||||
thumbnailUrl,
|
||||
nodesUrl + nodeId + '/renditions/doclib/content?attachment=false&' + 'alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs thumbnail url as attachment', () => {
|
||||
const thumbnailUrl = contentApi.getDocumentThumbnailUrl(nodeId, true);
|
||||
|
||||
assert.equal(
|
||||
thumbnailUrl,
|
||||
nodesUrl + nodeId + '/renditions/doclib/content?attachment=true&' + 'alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs thumbnail url with custom ticket', () => {
|
||||
const thumbnailUrl = contentApi.getDocumentThumbnailUrl(nodeId, true, 'custom_ticket');
|
||||
|
||||
assert.equal(thumbnailUrl, nodesUrl + nodeId + '/renditions/doclib/content?attachment=true&' + 'alf_ticket=custom_ticket');
|
||||
});
|
||||
|
||||
it('outputs preview url', () => {
|
||||
const thumbnailUrl = contentApi.getDocumentPreviewUrl(nodeId);
|
||||
|
||||
assert.equal(
|
||||
thumbnailUrl,
|
||||
nodesUrl + nodeId + '/renditions/imgpreview/content?attachment=false&' + 'alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs preview url as attachment', () => {
|
||||
const thumbnailUrl = contentApi.getDocumentPreviewUrl(nodeId, true);
|
||||
|
||||
assert.equal(
|
||||
thumbnailUrl,
|
||||
nodesUrl + nodeId + '/renditions/imgpreview/content?attachment=true&' + 'alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs preview url with custom ticket', () => {
|
||||
const thumbnailUrl = contentApi.getDocumentPreviewUrl(nodeId, true, 'custom_ticket');
|
||||
|
||||
assert.equal(thumbnailUrl, nodesUrl + nodeId + '/renditions/imgpreview/content?attachment=true&' + 'alf_ticket=custom_ticket');
|
||||
});
|
||||
|
||||
it('outputs content url', () => {
|
||||
const contentUrl = contentApi.getContentUrl(nodeId);
|
||||
|
||||
assert.equal(contentUrl, nodesUrl + nodeId + '/content?attachment=false' + '&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
});
|
||||
|
||||
it('outputs content url as attachment', () => {
|
||||
const contentUrl = contentApi.getContentUrl(nodeId, true);
|
||||
|
||||
assert.equal(contentUrl, nodesUrl + nodeId + '/content?attachment=true' + '&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
});
|
||||
|
||||
it('outputs content url with custom ticket', () => {
|
||||
const contentUrl = contentApi.getContentUrl(nodeId, true, 'custom_ticket');
|
||||
|
||||
assert.equal(contentUrl, nodesUrl + nodeId + '/content?attachment=true' + '&alf_ticket=custom_ticket');
|
||||
});
|
||||
|
||||
it('outputs rendition url', () => {
|
||||
const encoding = 'pdf';
|
||||
const contentUrl = contentApi.getRenditionUrl(nodeId, encoding);
|
||||
|
||||
assert.equal(
|
||||
contentUrl,
|
||||
nodesUrl +
|
||||
nodeId +
|
||||
'/renditions/' +
|
||||
encoding +
|
||||
'/content?attachment=false' +
|
||||
'&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs rendition url as attachment', () => {
|
||||
const encoding = 'pdf';
|
||||
const contentUrl = contentApi.getRenditionUrl(nodeId, encoding, true);
|
||||
|
||||
assert.equal(
|
||||
contentUrl,
|
||||
nodesUrl + nodeId + '/renditions/' + encoding + '/content?attachment=true' + '&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs rendition url with custom ticket', () => {
|
||||
const encoding = 'pdf';
|
||||
const contentUrl = contentApi.getRenditionUrl(nodeId, encoding, true, 'custom_ticket');
|
||||
|
||||
assert.equal(contentUrl, nodesUrl + nodeId + '/renditions/' + encoding + '/content?attachment=true' + '&alf_ticket=custom_ticket');
|
||||
});
|
||||
|
||||
it('outputs version rendition url', () => {
|
||||
const encoding = 'pdf';
|
||||
const contentUrl = contentApi.getVersionRenditionUrl(nodeId, versionId, encoding);
|
||||
|
||||
assert.equal(
|
||||
contentUrl,
|
||||
nodesUrl +
|
||||
nodeId +
|
||||
'/versions/' +
|
||||
versionId +
|
||||
'/renditions/' +
|
||||
encoding +
|
||||
'/content?attachment=false' +
|
||||
'&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs version rendition url as attachment', () => {
|
||||
const encoding = 'pdf';
|
||||
const contentUrl = contentApi.getVersionRenditionUrl(nodeId, versionId, encoding, true);
|
||||
|
||||
assert.equal(
|
||||
contentUrl,
|
||||
nodesUrl +
|
||||
nodeId +
|
||||
'/versions/' +
|
||||
versionId +
|
||||
'/renditions/' +
|
||||
encoding +
|
||||
'/content?attachment=true' +
|
||||
'&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs version rendition url with custom ticket', () => {
|
||||
const encoding = 'pdf';
|
||||
const contentUrl = contentApi.getVersionRenditionUrl(nodeId, versionId, encoding, true, 'custom_ticket');
|
||||
|
||||
assert.equal(
|
||||
contentUrl,
|
||||
nodesUrl + nodeId + '/versions/' + versionId + '/renditions/' + encoding + '/content?attachment=true' + '&alf_ticket=custom_ticket'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs version content url', () => {
|
||||
const contentUrl = contentApi.getVersionContentUrl(nodeId, versionId);
|
||||
|
||||
assert.equal(
|
||||
contentUrl,
|
||||
nodesUrl + nodeId + '/versions/' + versionId + '/content?attachment=false' + '&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs version content url as attachment', () => {
|
||||
const contentUrl = contentApi.getVersionContentUrl(nodeId, versionId, true);
|
||||
|
||||
assert.equal(
|
||||
contentUrl,
|
||||
nodesUrl + nodeId + '/versions/' + versionId + '/content?attachment=true' + '&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs version content url with custom ticket', () => {
|
||||
const contentUrl = contentApi.getVersionContentUrl(nodeId, versionId, true, 'custom_ticket');
|
||||
assert.equal(contentUrl, nodesUrl + nodeId + '/versions/' + versionId + '/content?attachment=true' + '&alf_ticket=custom_ticket');
|
||||
});
|
||||
|
||||
it('should output shared link content url', () => {
|
||||
const url = contentApi.getSharedLinkContentUrl(nodeId);
|
||||
assert.equal(url, sharedLinksUrl + nodeId + '/content?attachment=false');
|
||||
});
|
||||
|
||||
it('should output shared link content as attachment', () => {
|
||||
const url = contentApi.getSharedLinkContentUrl(nodeId, true);
|
||||
assert.equal(url, sharedLinksUrl + nodeId + '/content?attachment=true');
|
||||
});
|
||||
|
||||
it('should generate shared link rendition url', () => {
|
||||
const url = contentApi.getSharedLinkRenditionUrl(nodeId, 'pdf');
|
||||
assert.equal(url, sharedLinksUrl + nodeId + '/renditions/pdf/content?attachment=false');
|
||||
});
|
||||
|
||||
it('should generate shared link rendition url for download', () => {
|
||||
const url = contentApi.getSharedLinkRenditionUrl(nodeId, 'pdf', true);
|
||||
assert.equal(url, sharedLinksUrl + nodeId + '/renditions/pdf/content?attachment=true');
|
||||
});
|
||||
});
|
522
lib/js-api/test/auth.spec.ts
Normal file
522
lib/js-api/test/auth.spec.ts
Normal file
@@ -0,0 +1,522 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { EcmAuthMock, BpmAuthMock, NodeMock, ProfileMock } from './mockObjects';
|
||||
import { NodesApi, UserProfileApi, AlfrescoApi } from '../src';
|
||||
|
||||
const NOOP = () => {
|
||||
/* empty */
|
||||
};
|
||||
const ECM_HOST = 'https://127.0.0.1:8080';
|
||||
const BPM_HOST = 'https://127.0.0.1:9999';
|
||||
|
||||
interface ErrorResponse {
|
||||
status: number;
|
||||
}
|
||||
|
||||
describe('Auth', () => {
|
||||
describe('ECM Provider config', () => {
|
||||
let authResponseEcmMock: EcmAuthMock;
|
||||
let nodeMock: NodeMock;
|
||||
let nodesApi: NodesApi;
|
||||
|
||||
beforeEach(() => {
|
||||
authResponseEcmMock = new EcmAuthMock(ECM_HOST);
|
||||
nodeMock = new NodeMock(ECM_HOST);
|
||||
});
|
||||
|
||||
describe('With Authentication', () => {
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
|
||||
beforeEach(() => {
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm: ECM_HOST
|
||||
});
|
||||
|
||||
nodesApi = new NodesApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
describe('login', () => {
|
||||
it('should return the Ticket if all is ok', (done) => {
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then((data: string) => {
|
||||
assert.equal(data, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if wrong credential are used 403 the login fails', (done) => {
|
||||
authResponseEcmMock.get403Response();
|
||||
|
||||
alfrescoJsApi.login('wrong', 'name').then(NOOP, (error: ErrorResponse) => {
|
||||
assert.equal(error.status, 403);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isLoggedIn', () => {
|
||||
it('should return true if the api is logged in', (done) => {
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
assert.equal(alfrescoJsApi.isLoggedIn(), true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if the api is logged out', (done) => {
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').catch(NOOP);
|
||||
|
||||
authResponseEcmMock.get204ResponseLogout();
|
||||
|
||||
alfrescoJsApi.logout().then(() => {
|
||||
assert.equal(alfrescoJsApi.isLoggedIn(), false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Events ', () => {
|
||||
it('should login fire an event if is unauthorized 401', (done) => {
|
||||
authResponseEcmMock.get401Response();
|
||||
|
||||
const authPromise: any = alfrescoJsApi.login('wrong', 'name');
|
||||
|
||||
authPromise.catch(NOOP);
|
||||
authPromise.on('unauthorized', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should login fire success event if is all ok 201', (done) => {
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
const authPromise: any = alfrescoJsApi.login('admin', 'admin');
|
||||
|
||||
authPromise.catch(NOOP);
|
||||
authPromise.on('success', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should login fire logout event if the logout is successfull', (done) => {
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin');
|
||||
|
||||
authResponseEcmMock.get204ResponseLogout();
|
||||
|
||||
const authPromise: any = alfrescoJsApi.logout();
|
||||
|
||||
authPromise.catch(NOOP);
|
||||
authPromise.on('logout', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('With Ticket Authentication', () => {
|
||||
it('should Ticket be present in the client', () => {
|
||||
authResponseEcmMock.get400Response();
|
||||
|
||||
const api = new AlfrescoApi({
|
||||
ticketEcm: 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1',
|
||||
hostEcm: ECM_HOST
|
||||
});
|
||||
|
||||
assert.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1', api.contentClient.authentications.basicAuth.password);
|
||||
});
|
||||
|
||||
it('should Ticket login be validate against the server if is valid', (done) => {
|
||||
const ticket = 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1';
|
||||
|
||||
authResponseEcmMock.get200ValidTicket(ticket);
|
||||
|
||||
alfrescoJsApi.loginTicket(ticket, null).then((data: string) => {
|
||||
assert.equal(alfrescoJsApi.contentAuth.authentications.basicAuth.password, ticket);
|
||||
assert.equal(data, ticket);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should Ticket login be validate against the server d is NOT valid', (done) => {
|
||||
const ticket = 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1';
|
||||
|
||||
authResponseEcmMock.get400Response();
|
||||
|
||||
alfrescoJsApi.loginTicket(ticket, null).then(NOOP, () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Logout Api', () => {
|
||||
beforeEach(async () => {
|
||||
authResponseEcmMock.get201Response('TICKET_22d7a5a83d78b9cc9666ec4e412475e5455b33bd');
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('should Ticket be absent in the client and the resolve promise should be called', (done) => {
|
||||
authResponseEcmMock.get204ResponseLogout();
|
||||
|
||||
alfrescoJsApi.logout().then(() => {
|
||||
assert.equal(alfrescoJsApi.config.ticket, undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should Logout be rejected if the Ticket is already expired', (done) => {
|
||||
authResponseEcmMock.get404ResponseLogout();
|
||||
alfrescoJsApi.logout().then(NOOP, (error: any) => {
|
||||
assert.equal(error.error.toString(), 'Error: Not Found');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Unauthorized', () => {
|
||||
beforeEach((done) => {
|
||||
authResponseEcmMock.get201Response('TICKET_22d7a5a83d78b9cc9666ec4e412475e5455b33bd');
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should 401 invalidate the ticket', (done) => {
|
||||
nodeMock.get401CreationFolder();
|
||||
|
||||
nodesApi.createFolder('newFolder', null, null).then(NOOP, () => {
|
||||
assert.equal(alfrescoJsApi.contentAuth.authentications.basicAuth.password, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should 401 invalidate the session and logout', (done) => {
|
||||
nodeMock.get401CreationFolder();
|
||||
|
||||
nodesApi.createFolder('newFolder', null, null).then(NOOP, () => {
|
||||
assert.equal(alfrescoJsApi.isLoggedIn(), false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit an error event if a failing call is executed', (done) => {
|
||||
alfrescoJsApi.on('error', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
nodeMock.get401CreationFolder();
|
||||
|
||||
nodesApi.createFolder('newFolder', null, null).then(NOOP);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('BPM Provider config', () => {
|
||||
let profileMock: ProfileMock;
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
let profileApi: UserProfileApi;
|
||||
|
||||
beforeEach(() => {
|
||||
profileMock = new ProfileMock(BPM_HOST);
|
||||
authResponseBpmMock = new BpmAuthMock(BPM_HOST);
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm: BPM_HOST,
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
profileApi = new UserProfileApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
describe('With Authentication', () => {
|
||||
describe('login', () => {
|
||||
it('should return the Ticket if all is ok', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then((data: string) => {
|
||||
assert.equal(data, 'Basic YWRtaW46YWRtaW4=');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if wrong credential are used 401 the login fails', (done) => {
|
||||
authResponseBpmMock.get401Response();
|
||||
|
||||
alfrescoJsApi.login('wrong', 'name').then(NOOP, (error: ErrorResponse) => {
|
||||
assert.equal(error.status, 401);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isLoggedIn', () => {
|
||||
it('should return true if the api is logged in', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
assert.equal(alfrescoJsApi.isLoggedIn(), true);
|
||||
done();
|
||||
}, NOOP);
|
||||
});
|
||||
|
||||
it('should return false if the api is logged out', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin');
|
||||
|
||||
authResponseBpmMock.get200ResponseLogout();
|
||||
|
||||
alfrescoJsApi.logout().then(() => {
|
||||
assert.equal(alfrescoJsApi.isLoggedIn(), false);
|
||||
done();
|
||||
}, NOOP);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Events ', () => {
|
||||
it('should login fire an event if is unauthorized 401', (done) => {
|
||||
authResponseBpmMock.get401Response();
|
||||
|
||||
const authPromise: any = alfrescoJsApi.login('wrong', 'name');
|
||||
|
||||
authPromise.catch(NOOP);
|
||||
|
||||
authPromise.on('unauthorized', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should the Api fire success event if is all ok 201', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
const authPromise: any = alfrescoJsApi.login('admin', 'admin');
|
||||
|
||||
authPromise.catch(NOOP);
|
||||
|
||||
authPromise.on('success', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should the Api fire logout event if the logout is successfull', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin');
|
||||
|
||||
authResponseBpmMock.get200ResponseLogout();
|
||||
|
||||
const authPromise: any = alfrescoJsApi.logout();
|
||||
|
||||
authPromise.catch(NOOP);
|
||||
authPromise.on('logout', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Unauthorized', () => {
|
||||
beforeEach((done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should 401 invalidate the ticket', (done) => {
|
||||
profileMock.get401getProfile();
|
||||
|
||||
profileApi.getProfile().then(NOOP, () => {
|
||||
assert.equal(alfrescoJsApi.processAuth.authentications.basicAuth.ticket, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should 401 invalidate the session and logout', (done) => {
|
||||
profileMock.get401getProfile();
|
||||
|
||||
profileApi.getProfile().then(
|
||||
() => NOOP,
|
||||
() => {
|
||||
assert.equal(alfrescoJsApi.isLoggedIn(), false);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('BPM and ECM Provider config', () => {
|
||||
let authResponseEcmMock: EcmAuthMock;
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
|
||||
beforeEach(() => {
|
||||
authResponseEcmMock = new EcmAuthMock(ECM_HOST);
|
||||
authResponseBpmMock = new BpmAuthMock(BPM_HOST);
|
||||
|
||||
authResponseEcmMock.cleanAll();
|
||||
authResponseBpmMock.cleanAll();
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm: ECM_HOST,
|
||||
hostBpm: BPM_HOST,
|
||||
provider: 'ALL'
|
||||
});
|
||||
});
|
||||
|
||||
describe('With Authentication', () => {
|
||||
it('should Ticket be present in the client', () => {
|
||||
authResponseBpmMock.get200Response();
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
const api = new AlfrescoApi({
|
||||
ticketEcm: 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1',
|
||||
ticketBpm: 'Basic YWRtaW46YWRtaW4=',
|
||||
hostEcm: ECM_HOST,
|
||||
hostBpm: BPM_HOST,
|
||||
provider: 'ALL'
|
||||
});
|
||||
|
||||
assert.equal('Basic YWRtaW46YWRtaW4=', api.processClient.authentications.basicAuth.ticket);
|
||||
assert.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1', api.contentClient.authentications.basicAuth.password);
|
||||
});
|
||||
|
||||
describe('login', () => {
|
||||
it('should return the Ticket if all is ok', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then((data: string[]) => {
|
||||
assert.equal(data[0], 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
assert.equal(data[1], 'Basic YWRtaW46YWRtaW4=');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail if only ECM fail', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
authResponseEcmMock.get401Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(NOOP, () => {
|
||||
done();
|
||||
});
|
||||
|
||||
authResponseEcmMock.cleanAll();
|
||||
});
|
||||
|
||||
it('should fail if only BPM fail', (done) => {
|
||||
authResponseBpmMock.get401Response();
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(NOOP, () => {
|
||||
done();
|
||||
});
|
||||
|
||||
authResponseBpmMock.cleanAll();
|
||||
});
|
||||
});
|
||||
|
||||
describe('isLoggedIn', () => {
|
||||
it('should return false if the api is logged out', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin');
|
||||
|
||||
authResponseBpmMock.get200ResponseLogout();
|
||||
authResponseEcmMock.get204ResponseLogout();
|
||||
|
||||
alfrescoJsApi.logout().then(() => {
|
||||
assert.equal(alfrescoJsApi.isLoggedIn(), false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if wrong credential are used 401 the login fails', (done) => {
|
||||
authResponseBpmMock.get401Response();
|
||||
authResponseEcmMock.get401Response();
|
||||
|
||||
alfrescoJsApi.login('wrong', 'name').then(NOOP, (error: ErrorResponse) => {
|
||||
assert.equal(error.status, 401);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return true if the api is logged in', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
assert.equal(alfrescoJsApi.isLoggedIn(), true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Events ', () => {
|
||||
it('should login fire an event if is unauthorized 401', (done) => {
|
||||
authResponseBpmMock.get401Response();
|
||||
authResponseEcmMock.get401Response();
|
||||
|
||||
const authPromise: any = alfrescoJsApi.login('wrong', 'name');
|
||||
|
||||
authPromise.catch(NOOP);
|
||||
authPromise.on('unauthorized', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should The Api fire success event if is all ok 201', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
const authPromise: any = alfrescoJsApi.login('admin', 'admin');
|
||||
|
||||
authPromise.catch(NOOP);
|
||||
authPromise.on('success', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should The Api fire logout event if the logout is successful', (done) => {
|
||||
authResponseBpmMock.get200Response();
|
||||
authResponseEcmMock.get201Response();
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin');
|
||||
|
||||
authResponseBpmMock.get200ResponseLogout();
|
||||
authResponseEcmMock.get204ResponseLogout();
|
||||
|
||||
(alfrescoJsApi.logout() as any).on('logout', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
304
lib/js-api/test/bpmAuth.spec.ts
Normal file
304
lib/js-api/test/bpmAuth.spec.ts
Normal file
@@ -0,0 +1,304 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { ProcessAuth } from '../src';
|
||||
import { SuperagentHttpClient } from '../src/superagentHttpClient';
|
||||
import { BpmAuthMock } from './mockObjects';
|
||||
|
||||
describe('Bpm Auth test', () => {
|
||||
const hostBpm = 'https://127.0.0.1:9999';
|
||||
let authBpmMock: BpmAuthMock;
|
||||
|
||||
beforeEach(() => {
|
||||
authBpmMock = new BpmAuthMock(hostBpm);
|
||||
});
|
||||
|
||||
it('should remember username on login', () => {
|
||||
const auth = new ProcessAuth({});
|
||||
auth.login('johndoe', 'password');
|
||||
assert.equal(auth.authentications.basicAuth.username, 'johndoe');
|
||||
});
|
||||
|
||||
it('should forget username on logout', (done) => {
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
authBpmMock.get200Response();
|
||||
|
||||
processAuth.login('admin', 'admin').then(() => {
|
||||
assert.equal(processAuth.authentications.basicAuth.username, 'admin');
|
||||
|
||||
authBpmMock.get200ResponseLogout();
|
||||
|
||||
processAuth.logout().then(() => {
|
||||
assert.equal(processAuth.authentications.basicAuth.username, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('With Authentication', () => {
|
||||
it('login should return the Ticket if all is ok', (done) => {
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
processAuth.login('admin', 'admin').then((data) => {
|
||||
assert.equal(data, 'Basic YWRtaW46YWRtaW4=');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('login password should be removed after login', (done) => {
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
processAuth.login('admin', 'admin').then((data) => {
|
||||
assert.equal(data, 'Basic YWRtaW46YWRtaW4=');
|
||||
assert.notEqual(processAuth.authentications.basicAuth.password, 'admin');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('isLoggedIn should return true if the api is logged in', (done) => {
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
processAuth.login('admin', 'admin').then(() => {
|
||||
assert.equal(processAuth.isLoggedIn(), true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('isLoggedIn should return false if the api is logged out', (done) => {
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
processAuth.login('admin', 'admin');
|
||||
|
||||
authBpmMock.get200ResponseLogout();
|
||||
|
||||
processAuth.logout().then(() => {
|
||||
assert.equal(processAuth.isLoggedIn(), false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('isLoggedIn should return false if the host change', (done) => {
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
processAuth.login('admin', 'admin').then(() => {
|
||||
assert.equal(processAuth.isLoggedIn(), true);
|
||||
processAuth.changeHost();
|
||||
assert.equal(processAuth.isLoggedIn(), false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('login should return an error if wrong credential are used 401 the login fails', (done) => {
|
||||
authBpmMock.get401Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
processAuth.login('wrong', 'name').then(
|
||||
() => {},
|
||||
(error) => {
|
||||
assert.equal(error.status, 401);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('Events ', () => {
|
||||
it('login should fire an event if is unauthorized 401', (done) => {
|
||||
authBpmMock.get401Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
const loginPromise = processAuth.login('wrong', 'name');
|
||||
|
||||
loginPromise.catch(() => {});
|
||||
loginPromise.on('unauthorized', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('login should fire an event if is forbidden 403', (done) => {
|
||||
authBpmMock.get403Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
const loginPromise = processAuth.login('wrong', 'name');
|
||||
loginPromise.catch(() => {});
|
||||
loginPromise.on('forbidden', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('The Api Should fire success event if is all ok 201', (done) => {
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
const loginPromise = processAuth.login('admin', 'admin');
|
||||
|
||||
loginPromise.catch(() => {});
|
||||
loginPromise.on('success', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('The Api Should fire logout event if the logout is successfull', (done) => {
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
processAuth.login('admin', 'admin');
|
||||
|
||||
authBpmMock.get200ResponseLogout();
|
||||
|
||||
const promise = processAuth.logout();
|
||||
promise.on('logout', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('With Ticket Authentication', () => {
|
||||
it('Ticket should be present in the client', () => {
|
||||
const processAuth = new ProcessAuth({
|
||||
ticketBpm: 'Basic YWRtaW46YWRtaW4=',
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
assert.equal('Basic YWRtaW46YWRtaW4=', processAuth.authentications.basicAuth.ticket);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Logout Api', () => {
|
||||
let processAuth: ProcessAuth;
|
||||
|
||||
beforeEach((done) => {
|
||||
authBpmMock.get200Response();
|
||||
|
||||
processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
processAuth.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Ticket should be absent in the client and the resolve promise should be called', (done) => {
|
||||
authBpmMock.get200ResponseLogout();
|
||||
|
||||
processAuth.logout().then(() => {
|
||||
assert.equal(processAuth.getTicket(), null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('CSRF Token', () => {
|
||||
let originalMethod: any;
|
||||
let setCsrfTokenCalled = false;
|
||||
|
||||
beforeEach(() => {
|
||||
originalMethod = SuperagentHttpClient.prototype.setCsrfToken;
|
||||
setCsrfTokenCalled = false;
|
||||
|
||||
SuperagentHttpClient.prototype.setCsrfToken = () => {
|
||||
setCsrfTokenCalled = true;
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
SuperagentHttpClient.prototype.setCsrfToken = originalMethod;
|
||||
setCsrfTokenCalled = false;
|
||||
});
|
||||
|
||||
it('should be enabled by default', (done) => {
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app'
|
||||
});
|
||||
|
||||
processAuth.login('admin', 'admin').then(() => {
|
||||
assert.equal(setCsrfTokenCalled, true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be disabled if disableCsrf is true', (done) => {
|
||||
authBpmMock.get200Response();
|
||||
|
||||
const processAuth = new ProcessAuth({
|
||||
hostBpm,
|
||||
contextRootBpm: 'activiti-app',
|
||||
disableCsrf: true
|
||||
});
|
||||
|
||||
processAuth.login('admin', 'admin').then(() => {
|
||||
assert.equal(setCsrfTokenCalled, false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
72
lib/js-api/test/changeConfig.spec.ts
Normal file
72
lib/js-api/test/changeConfig.spec.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi } from '../src';
|
||||
import { EcmAuthMock, BpmAuthMock } from './mockObjects';
|
||||
|
||||
describe('Change config', () => {
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
|
||||
beforeEach(async () => {
|
||||
const config = {
|
||||
hostBpm: 'https://127.0.0.1:9999',
|
||||
hostEcm: 'https://127.0.0.1:8080',
|
||||
provider: 'ALL'
|
||||
};
|
||||
|
||||
authResponseBpmMock = new BpmAuthMock(config.hostBpm);
|
||||
authResponseMock = new EcmAuthMock(config.hostEcm);
|
||||
|
||||
authResponseMock.get201Response();
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi(config);
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
describe('Change hosts', () => {
|
||||
it('Change host Ecm', () => {
|
||||
assert.equal(alfrescoJsApi.contentClient.basePath, 'https://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1');
|
||||
|
||||
alfrescoJsApi.changeEcmHost('https://differenTserverEcm:9898');
|
||||
|
||||
assert.equal(alfrescoJsApi.contentClient.basePath, 'https://differenTserverEcm:9898/alfresco/api/-default-/public/alfresco/versions/1');
|
||||
});
|
||||
|
||||
it('Change host bpm', () => {
|
||||
assert.equal(alfrescoJsApi.processClient.basePath, 'https://127.0.0.1:9999/activiti-app');
|
||||
|
||||
alfrescoJsApi.changeBpmHost('https://differenTserverBpm:2222');
|
||||
|
||||
assert.equal(alfrescoJsApi.processClient.basePath, 'https://differenTserverBpm:2222/activiti-app');
|
||||
});
|
||||
|
||||
it('Change host ecm bpm', () => {
|
||||
assert.equal(alfrescoJsApi.contentClient.basePath, 'https://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1');
|
||||
assert.equal(alfrescoJsApi.processClient.basePath, 'https://127.0.0.1:9999/activiti-app');
|
||||
|
||||
alfrescoJsApi.changeEcmHost('https://differenTserverEcm:9898');
|
||||
alfrescoJsApi.changeBpmHost('https://differenTserverBpm:2222');
|
||||
|
||||
assert.equal(alfrescoJsApi.contentClient.basePath, 'https://differenTserverEcm:9898/alfresco/api/-default-/public/alfresco/versions/1');
|
||||
assert.equal(alfrescoJsApi.processClient.basePath, 'https://differenTserverBpm:2222/activiti-app');
|
||||
});
|
||||
});
|
||||
});
|
263
lib/js-api/test/content-services/categoriesApi.spec.ts
Normal file
263
lib/js-api/test/content-services/categoriesApi.spec.ts
Normal file
@@ -0,0 +1,263 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, CategoriesApi, CategoryPaging, CategoryEntry } from '../../src';
|
||||
import { EcmAuthMock, CategoriesMock } from '../mockObjects';
|
||||
|
||||
describe('Categories', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let categoriesMock: CategoriesMock;
|
||||
let categoriesApi: CategoriesApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
categoriesMock = new CategoriesMock(hostEcm);
|
||||
|
||||
authResponseMock.get201Response();
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => done());
|
||||
categoriesApi = new CategoriesApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
it('should return 200 while getting subcategories for category with categoryId if all is ok', (done) => {
|
||||
categoriesMock.get200ResponseSubcategories('-root-');
|
||||
categoriesApi.getSubcategories('-root-').then((response: CategoryPaging) => {
|
||||
assert.equal(response.list.pagination.count, 2);
|
||||
assert.equal(response.list.entries[0].entry.parentId, '-root-');
|
||||
assert.equal(response.list.entries[0].entry.id, 'testId1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 404 while getting subcategories for not existing category', (done) => {
|
||||
categoriesMock.get404SubcategoryNotExist('notExistingId');
|
||||
categoriesApi.getSubcategories('notExistingId').then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 200 while getting category with categoryId if category exists', (done) => {
|
||||
categoriesMock.get200ResponseCategory('testId1');
|
||||
categoriesApi.getCategory('testId1').then((response: CategoryEntry) => {
|
||||
assert.equal(response.entry.parentId, '-root-');
|
||||
assert.equal(response.entry.id, 'testId1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 404 while getting category with categoryId when category not exists', (done) => {
|
||||
categoriesMock.get404CategoryNotExist('notExistingId');
|
||||
categoriesApi.getCategory('notExistingId').then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 200 while getting categories linked to node with nodeId if node has some categories assigned', (done) => {
|
||||
categoriesMock.get200ResponseNodeCategoryLinks('testNode');
|
||||
categoriesApi.getCategoryLinksForNode('testNode').then((response: CategoryPaging) => {
|
||||
assert.equal(response.list.entries[0].entry.parentId, 'testNode');
|
||||
assert.equal(response.list.entries[0].entry.id, 'testId1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 403 while getting categories linked to node with nodeId if user has no rights to get from node', (done) => {
|
||||
categoriesMock.get403NodeCategoryLinksPermissionDenied('testNode');
|
||||
categoriesApi.getCategoryLinksForNode('testNode').then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 404 while getting categories linked to node with nodeId if node does not exist', (done) => {
|
||||
categoriesMock.get404NodeNotExist('testNode');
|
||||
categoriesApi.getCategoryLinksForNode('testNode').then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 204 after unlinking category', (done) => {
|
||||
categoriesMock.get204CategoryUnlinked('testNode', 'testId1');
|
||||
categoriesApi.unlinkNodeFromCategory('testNode', 'testId1').then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 404 while unlinking category if category with categoryId or node with nodeId does not exist', (done) => {
|
||||
categoriesMock.get404CategoryUnlinkNotFound('testNode', 'testId1');
|
||||
categoriesApi.unlinkNodeFromCategory('testNode', 'testId1').then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 403 while unlinking category if user has no rights to unlink', (done) => {
|
||||
categoriesMock.get403CategoryUnlinkPermissionDenied('testNode', 'testId1');
|
||||
categoriesApi.unlinkNodeFromCategory('testNode', 'testId1').then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 200 while updating category if all is ok', (done) => {
|
||||
categoriesMock.get200ResponseCategoryUpdated('testId1');
|
||||
categoriesApi.updateCategory('testId1', { name: 'testName1' }).then((response) => {
|
||||
assert.equal(response.entry.id, 'testId1');
|
||||
assert.equal(response.entry.name, 'testName1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 404 while updating category if category with categoryId does not exist', (done) => {
|
||||
categoriesMock.get404CategoryUpdateNotFound('testId1');
|
||||
categoriesApi.updateCategory('testId1', { name: 'testName1' }).then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 403 while updating category if user has no rights to update', (done) => {
|
||||
categoriesMock.get403CategoryUpdatePermissionDenied('testId1');
|
||||
categoriesApi.updateCategory('testId1', { name: 'testName1' }).then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 201 while creating category if all is ok', (done) => {
|
||||
categoriesMock.get201ResponseCategoryCreated('testId1');
|
||||
categoriesApi.createSubcategories('testId1', [{ name: 'testName10' }]).then((response: CategoryPaging | CategoryEntry) => {
|
||||
assert.equal((response as CategoryEntry).entry.parentId, 'testId1');
|
||||
assert.equal((response as CategoryEntry).entry.name, 'testName10');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 409 while creating subcategory if subcategory already exists', (done) => {
|
||||
categoriesMock.get409CategoryCreateAlreadyExists('testId1');
|
||||
categoriesApi.createSubcategories('testId1', [{ name: 'testName10' }]).then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 409);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 403 while creating category if user has no rights to create', (done) => {
|
||||
categoriesMock.get403CategoryCreatedPermissionDenied('testId1');
|
||||
categoriesApi.createSubcategories('testId1', [{ name: 'testName10' }]).then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 201 while linking category if all is ok', (done) => {
|
||||
categoriesMock.get201ResponseCategoryLinked('testNode');
|
||||
categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]).then((response) => {
|
||||
if (response instanceof CategoryEntry) {
|
||||
assert.equal(response.entry.id, 'testId1');
|
||||
assert.equal(response.entry.name, 'testName1');
|
||||
done();
|
||||
} else {
|
||||
assert.fail();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 201 while linking multiple categories if all is ok', (done) => {
|
||||
categoriesMock.get201ResponseCategoryLinkedArray('testNodeArr');
|
||||
categoriesApi.linkNodeToCategory('testNodeArr', [{ categoryId: 'testId1' }, { categoryId: 'testId2' }]).then((response) => {
|
||||
const categoriesPaging = response as CategoryPaging;
|
||||
assert.equal(categoriesPaging.list.pagination.count, 2);
|
||||
assert.equal(categoriesPaging.list.entries[0].entry.id, 'testId1');
|
||||
assert.equal(categoriesPaging.list.entries[0].entry.name, 'testName1');
|
||||
assert.equal(categoriesPaging.list.entries[1].entry.id, 'testId2');
|
||||
assert.equal(categoriesPaging.list.entries[1].entry.name, 'testName2');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 404 while linking category if node with nodeId or category with categoryId does not exist', (done) => {
|
||||
categoriesMock.get404CategoryLinkNotFound('testNode');
|
||||
categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]).then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 403 while linking category if user has no rights to link', (done) => {
|
||||
categoriesMock.get403CategoryLinkPermissionDenied('testNode');
|
||||
categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]).then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 405 while linking category if node of this type cannot be assigned to category', (done) => {
|
||||
categoriesMock.get405CategoryLinkCannotAssign('testNode');
|
||||
categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]).then(
|
||||
() => {},
|
||||
(error: { status: number }) => {
|
||||
assert.equal(error.status, 405);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
67
lib/js-api/test/content-services/commentsApi.spec.ts
Normal file
67
lib/js-api/test/content-services/commentsApi.spec.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, CommentsApi } from '../../src';
|
||||
import { CommentMock, EcmAuthMock } from '../mockObjects';
|
||||
|
||||
describe('Comments', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let commentMock: CommentMock;
|
||||
let commentsApi: CommentsApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
commentMock = new CommentMock(hostEcm);
|
||||
|
||||
authResponseMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
commentsApi = new CommentsApi(alfrescoJsApi);
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a comment', (done) => {
|
||||
commentMock.post201Response();
|
||||
|
||||
commentsApi
|
||||
.createComment('74cd8a96-8a21-47e5-9b3b-a1b3e296787d', {
|
||||
content: 'This is a comment'
|
||||
})
|
||||
.then((data) => {
|
||||
assert.equal(data.entry.content, 'This is a comment');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get a comment', (done) => {
|
||||
commentMock.get200Response();
|
||||
|
||||
commentsApi.listComments('74cd8a96-8a21-47e5-9b3b-a1b3e296787d').then((data) => {
|
||||
assert.equal(data.list.entries[0].entry.content, 'This is another comment');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
80
lib/js-api/test/content-services/customModelApi.spec.ts
Normal file
80
lib/js-api/test/content-services/customModelApi.spec.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AlfrescoApi, CustomModelApi } from '../../src';
|
||||
import { EcmAuthMock, CustomModelMock } from '../mockObjects';
|
||||
|
||||
describe('Custom Model Api', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let customModelMock: CustomModelMock;
|
||||
let customModelApi: CustomModelApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
customModelMock = new CustomModelMock(hostEcm);
|
||||
|
||||
authResponseMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
customModelApi = new CustomModelApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
describe('Get', () => {
|
||||
it('All Custom Model', (done) => {
|
||||
customModelMock.get200AllCustomModel();
|
||||
|
||||
customModelApi.getAllCustomModel().then(() => {
|
||||
done();
|
||||
}, console.error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Create', () => {
|
||||
it('createCustomModel', (done) => {
|
||||
customModelMock.create201CustomModel();
|
||||
|
||||
const status = 'DRAFT';
|
||||
const description = 'Test model description';
|
||||
const name = 'testModel';
|
||||
const namespaceUri = 'https://www.alfresco.org/model/testNamespace/1.0';
|
||||
const namespacePrefix = 'test';
|
||||
|
||||
customModelApi.createCustomModel(status, description, name, namespaceUri, namespacePrefix).then(() => {
|
||||
done();
|
||||
}, console.error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT', () => {
|
||||
it('activateCustomModel', (done) => {
|
||||
customModelMock.activateCustomModel200();
|
||||
|
||||
customModelApi.activateCustomModel('testModel').then(() => {
|
||||
done();
|
||||
}, console.error);
|
||||
});
|
||||
});
|
||||
});
|
133
lib/js-api/test/content-services/groupsApi.spec.ts
Normal file
133
lib/js-api/test/content-services/groupsApi.spec.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, GroupsApi } from '../../src';
|
||||
import { EcmAuthMock, GroupsMock } from '../mockObjects';
|
||||
|
||||
describe('Groups', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let groupsMock: GroupsMock;
|
||||
let groupsApi: GroupsApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
groupsMock = new GroupsMock(hostEcm);
|
||||
|
||||
authResponseMock.get201Response();
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
groupsApi = new GroupsApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
it('get groups', (done) => {
|
||||
groupsMock.get200GetGroups();
|
||||
|
||||
groupsApi.listGroups().then((data) => {
|
||||
assert.equal(data.list.pagination.count, 2);
|
||||
assert.equal(data.list.entries[0].entry.id, 'GROUP_alfalfa');
|
||||
assert.equal(data.list.entries[1].entry.id, 'GROUP_CallCenterAA');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('create group', (done) => {
|
||||
groupsMock.get200CreateGroupResponse();
|
||||
|
||||
const groupBody = {
|
||||
id: 'SUB_TEST',
|
||||
displayName: 'SAMPLE'
|
||||
};
|
||||
|
||||
groupsApi.createGroup(groupBody).then((data) => {
|
||||
assert.equal(data.entry.id, 'GROUP_TEST');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('delete group', (done) => {
|
||||
groupsMock.getDeleteGroupSuccessfulResponse('group_test');
|
||||
groupsApi.deleteGroup('group_test').then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get single group', (done) => {
|
||||
groupsMock.get200GetSingleGroup();
|
||||
|
||||
groupsApi.getGroup('GROUP_TEST').then((data) => {
|
||||
assert.equal(data.entry.id, 'GROUP_TEST');
|
||||
assert.equal(data.entry.displayName, 'SAMPLE');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('update group', (done) => {
|
||||
groupsMock.get200UpdateGroupResponse();
|
||||
|
||||
const groupBody = {
|
||||
displayName: 'CHANGED'
|
||||
};
|
||||
|
||||
groupsApi.updateGroup('GROUP_TEST', groupBody).then((data) => {
|
||||
assert.equal(data.entry.id, 'GROUP_TEST');
|
||||
assert.equal(data.entry.displayName, 'CHANGED');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get group members', (done) => {
|
||||
groupsMock.get200GetGroupMemberships();
|
||||
|
||||
groupsApi.listGroupMemberships('GROUP_TEST').then((data) => {
|
||||
assert.equal(data.list.pagination.count, 1);
|
||||
assert.equal(data.list.entries[0].entry.id, 'GROUP_SUB_TEST');
|
||||
assert.equal(data.list.entries[0].entry.displayName, 'SAMPLE');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('add group member', (done) => {
|
||||
groupsMock.get200AddGroupMembershipResponse();
|
||||
|
||||
const groupBody = {
|
||||
id: 'GROUP_SUB_TEST',
|
||||
memberType: 'GROUP'
|
||||
};
|
||||
|
||||
groupsApi.createGroupMembership('GROUP_TEST', groupBody).then((data) => {
|
||||
assert.equal(data.entry.id, 'GROUP_SUB_TEST');
|
||||
assert.equal(data.entry.displayName, 'SAMPLE');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('delete group member', (done) => {
|
||||
groupsMock.getDeleteMemberForGroupSuccessfulResponse('GROUP_TEST', 'GROUP_SUB_TEST');
|
||||
groupsApi.deleteGroupMembership('GROUP_TEST', 'GROUP_SUB_TEST').then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
153
lib/js-api/test/content-services/nodeApi.spec.ts
Normal file
153
lib/js-api/test/content-services/nodeApi.spec.ts
Normal file
@@ -0,0 +1,153 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, NodesApi } from '../../src';
|
||||
import { EcmAuthMock, NodeMock } from '../mockObjects';
|
||||
|
||||
describe('Node', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let nodeMock: NodeMock;
|
||||
let nodesApi: NodesApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
nodeMock = new NodeMock(hostEcm);
|
||||
|
||||
authResponseMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
nodesApi = new NodesApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
describe('Get Children Node', () => {
|
||||
it('information for the node with identifier nodeId should return 200 if is all ok', (done) => {
|
||||
nodeMock.get200ResponseChildren();
|
||||
|
||||
nodesApi.listNodeChildren('b4cff62a-664d-4d45-9302-98723eac1319').then((data) => {
|
||||
assert.equal(data.list.pagination.count, 5);
|
||||
assert.equal(data.list.entries[0].entry.name, 'dataLists');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('information for the node with identifier nodeId should return 404 if the id is does not exist', (done) => {
|
||||
nodeMock.get404ChildrenNotExist();
|
||||
|
||||
nodesApi.listNodeChildren('b4cff62a-664d-4d45-9302-98723eac1319').then(
|
||||
() => {},
|
||||
(error) => {
|
||||
assert.equal(error.status, 404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('dynamic augmenting object parameters', (done) => {
|
||||
nodeMock.get200ResponseChildrenFutureNewPossibleValue();
|
||||
|
||||
nodesApi.listNodeChildren('b4cff62a-664d-4d45-9302-98723eac1319').then((data: any) => {
|
||||
assert.equal(data.list.entries[0].entry.impossibleProperties, 'impossibleRightValue');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return dates as timezone-aware', (done) => {
|
||||
nodeMock.get200ResponseChildrenNonUTCTimes();
|
||||
|
||||
const equalTime = (actual: Date, expected: Date) => actual.getTime() === expected.getTime();
|
||||
|
||||
nodesApi.listNodeChildren('b4cff62a-664d-4d45-9302-98723eac1320').then((data) => {
|
||||
assert.equal(data.list.entries.length, 1);
|
||||
const isEqual = equalTime(data.list.entries[0].entry.createdAt, new Date(Date.UTC(2011, 2, 15, 17, 4, 54, 290)));
|
||||
assert.equal(isEqual, true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Delete', () => {
|
||||
it('delete the node with identifier nodeId', (done) => {
|
||||
nodeMock.get204SuccessfullyDeleted();
|
||||
|
||||
nodesApi.deleteNode('80a94ac8-3ece-47ad-864e-5d939424c47c').then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('delete the node with identifier nodeId should return 404 if the id is does not exist', (done) => {
|
||||
nodeMock.get404DeleteNotFound();
|
||||
|
||||
nodesApi.deleteNode('80a94ac8-test-47ad-864e-5d939424c47c').then(
|
||||
() => {},
|
||||
(error) => {
|
||||
assert.equal(error.status, 404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('delete the node with identifier nodeId should return 403 if current user does not have permission to delete', (done) => {
|
||||
nodeMock.get403DeletePermissionDenied();
|
||||
|
||||
nodesApi.deleteNode('80a94ac8-3ece-47ad-864e-5d939424c47c').then(
|
||||
() => {},
|
||||
() => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Delete nodes', () => {
|
||||
it('should call deleteNode for every id in the given array', (done) => {
|
||||
let calls = 0;
|
||||
|
||||
nodesApi.deleteNode = () => {
|
||||
calls++;
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
nodesApi.deleteNodes(['80a94ac8-3ece-47ad-864e-5d939424c47c', '80a94ac8-3ece-47ad-864e-5d939424c47d']).then(() => {
|
||||
assert.equal(calls, 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return throw an error if one of the promises fails', (done) => {
|
||||
nodeMock.get204SuccessfullyDeleted();
|
||||
nodeMock.get404DeleteNotFound();
|
||||
|
||||
nodesApi.deleteNodes(['80a94ac8-3ece-47ad-864e-5d939424c47c', '80a94ac8-test-47ad-864e-5d939424c47c']).then(
|
||||
() => {},
|
||||
(error) => {
|
||||
assert.equal(error.status, 404);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
68
lib/js-api/test/content-services/peopleApi.spec.ts
Normal file
68
lib/js-api/test/content-services/peopleApi.spec.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AlfrescoApi, PersonBodyCreate, PeopleApi } from '../../src';
|
||||
import { EcmAuthMock, PeopleMock } from '../mockObjects';
|
||||
|
||||
describe('PeopleApi', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let peopleMock: PeopleMock;
|
||||
let peopleApi: PeopleApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
peopleMock = new PeopleMock(hostEcm);
|
||||
authResponseMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
peopleApi = new PeopleApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
it('should add a person', (done) => {
|
||||
peopleMock.get201Response();
|
||||
|
||||
const payload: PersonBodyCreate = {
|
||||
id: 'chewbe',
|
||||
email: 'chewbe@millenniumfalcon.com',
|
||||
lastName: 'Chewbe',
|
||||
firstName: 'chewbacca',
|
||||
password: 'Rrrrrrrghghghghgh'
|
||||
};
|
||||
|
||||
peopleApi.createPerson(payload).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get list of people', (done) => {
|
||||
peopleMock.get200ResponsePersons();
|
||||
|
||||
peopleApi.listPeople().then(() => {
|
||||
peopleMock.play();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
77
lib/js-api/test/content-services/queriesApi.spec.ts
Normal file
77
lib/js-api/test/content-services/queriesApi.spec.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, QueriesApi } from '../../src';
|
||||
import { EcmAuthMock, FindNodesMock } from '../mockObjects';
|
||||
|
||||
describe('Queries', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let nodesMock: FindNodesMock;
|
||||
let queriesApi: QueriesApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
nodesMock = new FindNodesMock(hostEcm);
|
||||
|
||||
authResponseMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
queriesApi = new QueriesApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
describe('nodes', () => {
|
||||
const searchTerm = 'test';
|
||||
|
||||
it('should throw exception if no search term is provided', () => {
|
||||
assert.throws(() => {
|
||||
queriesApi.findNodes(null);
|
||||
}, `Error: Missing param 'term'`);
|
||||
});
|
||||
|
||||
it('should invoke error handler on a server error', (done) => {
|
||||
nodesMock.get401Response();
|
||||
|
||||
queriesApi.findNodes(searchTerm).then(
|
||||
() => {},
|
||||
() => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return query results', (done) => {
|
||||
nodesMock.get200Response();
|
||||
|
||||
queriesApi.findNodes(searchTerm).then((data) => {
|
||||
assert.equal(data.list.pagination.count, 2);
|
||||
assert.equal(data.list.entries[0].entry.name, 'coins1.JPG');
|
||||
assert.equal(data.list.entries[1].entry.name, 'coins2.JPG');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
72
lib/js-api/test/content-services/renditionApi.spec.ts
Normal file
72
lib/js-api/test/content-services/renditionApi.spec.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, RenditionsApi } from '../../src';
|
||||
import { EcmAuthMock, RenditionMock } from '../mockObjects';
|
||||
|
||||
describe('Rendition', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let renditionMock: RenditionMock;
|
||||
let renditionsApi: RenditionsApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
renditionMock = new RenditionMock(hostEcm);
|
||||
|
||||
authResponseMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
renditionsApi = new RenditionsApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
it('Get Rendition', (done) => {
|
||||
renditionMock.get200RenditionResponse();
|
||||
|
||||
renditionsApi.getRendition('97a29e9c-1e4f-4d9d-bb02-1ec920dda045', 'pdf').then((data) => {
|
||||
assert.equal(data.entry.id, 'pdf');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Create Rendition', (done) => {
|
||||
renditionMock.createRendition200();
|
||||
|
||||
renditionsApi.createRendition('97a29e9c-1e4f-4d9d-bb02-1ec920dda045', { id: 'pdf' }).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Get Renditions list for node id', (done) => {
|
||||
renditionMock.get200RenditionList();
|
||||
|
||||
renditionsApi.listRenditions('97a29e9c-1e4f-4d9d-bb02-1ec920dda045').then((data) => {
|
||||
assert.equal(data.list.pagination.count, 6);
|
||||
assert.equal(data.list.entries[0].entry.id, 'avatar');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
151
lib/js-api/test/content-services/tagApi.spec.ts
Normal file
151
lib/js-api/test/content-services/tagApi.spec.ts
Normal file
@@ -0,0 +1,151 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, TagBody, TagEntry, TagsApi } from '../../src';
|
||||
import { EcmAuthMock, TagMock } from '../mockObjects';
|
||||
|
||||
describe('Tags', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let tagMock: TagMock;
|
||||
let tagsApi: TagsApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
tagMock = new TagMock(hostEcm);
|
||||
|
||||
authResponseMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
tagsApi = new TagsApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
describe('listTags', () => {
|
||||
it('should load list of tags', (done) => {
|
||||
tagMock.get200Response();
|
||||
|
||||
tagsApi.listTags().then((data) => {
|
||||
assert.equal(data.list.pagination.count, 2);
|
||||
assert.equal(data.list.entries[0].entry.tag, 'tag-test-1');
|
||||
assert.equal(data.list.entries[1].entry.tag, 'tag-test-2');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle 401 error', (done) => {
|
||||
tagMock.get401Response();
|
||||
|
||||
tagsApi.listTags().then(
|
||||
() => {},
|
||||
() => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return specified tag', (done) => {
|
||||
tagMock.getTagsByNamesFilterByExactTag200Response();
|
||||
|
||||
tagsApi
|
||||
.listTags({
|
||||
tag: 'tag-test-1'
|
||||
})
|
||||
.then((data) => {
|
||||
assert.equal(data.list.entries[0].entry.tag, 'tag-test-1');
|
||||
assert.equal(data.list.entries[0].entry.id, '0d89aa82-f2b8-4a37-9a54-f4c5148174d6');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return tags contained specified value', (done) => {
|
||||
tagMock.getTagsByNameFilteredByMatching200Response();
|
||||
|
||||
tagsApi
|
||||
.listTags({
|
||||
tag: '*tag-test*',
|
||||
matching: true
|
||||
})
|
||||
.then((data) => {
|
||||
assert.equal(data?.list.entries.length, 2);
|
||||
|
||||
assert.equal(data.list.entries[0].entry.tag, 'tag-test-1');
|
||||
assert.equal(data.list.entries[0].entry.id, '0d89aa82-f2b8-4a37-9a54-f4c5148174d6');
|
||||
|
||||
assert.equal(data.list.entries[1].entry.tag, 'tag-test-2');
|
||||
assert.equal(data.list.entries[1].entry.id, 'd79bdbd0-9f55-45bb-9521-811e15bf48f6');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('createTags', () => {
|
||||
it('should return created tags', (done: Mocha.Done) => {
|
||||
tagMock.createTags201Response();
|
||||
tagsApi.createTags([new TagBody(), new TagBody()]).then((tags) => {
|
||||
assert.equal(tags.length, 2);
|
||||
assert.equal(tags[0].entry.tag, 'tag-test-1');
|
||||
assert.equal(tags[1].entry.tag, 'tag-test-2');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw error if tags are not passed', () => {
|
||||
assert.throws(tagsApi.createTags.bind(tagsApi, null));
|
||||
});
|
||||
});
|
||||
|
||||
describe('assignTagsToNode', () => {
|
||||
it('should return tags after assigning them to node', (done) => {
|
||||
const tag1 = new TagBody();
|
||||
tag1.tag = 'tag-test-1';
|
||||
const tag2 = new TagBody();
|
||||
tag2.tag = 'tag-test-2';
|
||||
const tags = [tag1, tag2];
|
||||
tagMock.get201ResponseForAssigningTagsToNode(tags);
|
||||
|
||||
tagsApi.assignTagsToNode('someNodeId', tags).then((tagPaging) => {
|
||||
assert.equal(tagPaging.list.pagination.count, 2);
|
||||
assert.equal(tagPaging.list.entries[0].entry.tag, tag1.tag);
|
||||
assert.equal(tagPaging.list.entries[1].entry.tag, tag2.tag);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return tag after assigning it to node', (done) => {
|
||||
const tag = new TagBody();
|
||||
tag.tag = 'tag-test-1';
|
||||
const tags = [tag];
|
||||
tagMock.get201ResponseForAssigningTagsToNode(tags);
|
||||
|
||||
tagsApi.assignTagsToNode('someNodeId', tags).then((data) => {
|
||||
const tagEntry = data as TagEntry;
|
||||
assert.equal(tagEntry.entry.tag, tag.tag);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
92
lib/js-api/test/content-services/versionsApi.spec.ts
Normal file
92
lib/js-api/test/content-services/versionsApi.spec.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, VersionsApi } from '../../src';
|
||||
import { EcmAuthMock, VersionMock } from '../mockObjects';
|
||||
|
||||
describe('Versions', () => {
|
||||
const nodeId = '74cd8a96-8a21-47e5-9b3b-a1b3e296787d';
|
||||
const versionId = '1.0';
|
||||
const renditionId = 'pdf';
|
||||
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let versionMock: VersionMock;
|
||||
let versionsApi: VersionsApi;
|
||||
|
||||
beforeEach(async () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
versionMock = new VersionMock(hostEcm);
|
||||
authResponseMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({ hostEcm });
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
|
||||
versionsApi = new VersionsApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
it('should list all node version renditions', (done) => {
|
||||
versionMock.get200ResponseVersionRenditions(nodeId, versionId);
|
||||
|
||||
versionsApi.listVersionRenditions(nodeId, versionId).then((data) => {
|
||||
const entries = data.list.entries;
|
||||
assert.equal(entries.length, 6);
|
||||
assert.equal(data.list.entries[0].entry.id, 'avatar');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should create rendition for a node versionId', (done) => {
|
||||
versionMock.create200VersionRendition(nodeId, versionId);
|
||||
|
||||
versionsApi.createVersionRendition(nodeId, versionId, { id: 'pdf' }).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get a node version rendition', (done) => {
|
||||
versionMock.get200VersionRendition(nodeId, versionId, renditionId);
|
||||
|
||||
versionsApi.getVersionRendition(nodeId, versionId, renditionId).then((data) => {
|
||||
assert.equal(data.entry.id, 'pdf');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get version history', (done) => {
|
||||
versionMock.get200Response(nodeId);
|
||||
|
||||
versionsApi.listVersionHistory(nodeId).then((data) => {
|
||||
const entries = data.list.entries;
|
||||
assert.equal(entries.length, 2);
|
||||
assert.equal(entries[0].entry.id, '2.0');
|
||||
assert.equal(entries[1].entry.id, '1.0');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should revert a version', (done) => {
|
||||
versionMock.post201Response(nodeId, versionId);
|
||||
|
||||
versionsApi.revertVersion(nodeId, versionId, { majorVersion: true, comment: '' }).then((data) => {
|
||||
assert.equal(data.entry.id, '3.0');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
111
lib/js-api/test/content-services/webScriptApi.spec.ts
Normal file
111
lib/js-api/test/content-services/webScriptApi.spec.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, WebscriptApi } from '../../src';
|
||||
import { EcmAuthMock, WebScriptMock } from '../mockObjects';
|
||||
|
||||
describe('WebScript', () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
const contextRoot = 'script';
|
||||
const servicePath = 'alfresco';
|
||||
const scriptPath = 'testWebScript';
|
||||
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let webScriptMock: WebScriptMock;
|
||||
let webscriptApi: WebscriptApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
webScriptMock = new WebScriptMock(hostEcm, contextRoot, servicePath, scriptPath);
|
||||
authResponseMock.get201Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
webscriptApi = new WebscriptApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
it('execute webScript return 400 error if is not present on the server should be handled by reject promise', (done) => {
|
||||
webScriptMock.get404Response();
|
||||
|
||||
webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath).catch((error: any) => {
|
||||
assert.equal(error.status, 404);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('execute webScript GET return 200 if all is ok should be handled by resolve promise', (done) => {
|
||||
webScriptMock.get200Response();
|
||||
|
||||
webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('execute webScript that return HTML should not return it as Object', (done) => {
|
||||
webScriptMock.get200ResponseHTMLFormat();
|
||||
|
||||
webscriptApi.executeWebScript('GET', 'sample/folder/Company%20Home').then((data) => {
|
||||
try {
|
||||
JSON.parse(data);
|
||||
} catch (e) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Events', () => {
|
||||
it('WebScript should fire success event at the end', (done) => {
|
||||
webScriptMock.get200Response();
|
||||
|
||||
const webscriptPromise: any = webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath);
|
||||
|
||||
webscriptPromise.catch(() => {});
|
||||
webscriptPromise.on('success', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('WebScript should fire error event if something go wrong', (done) => {
|
||||
webScriptMock.get404Response();
|
||||
|
||||
const webscriptPromise: any = webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath);
|
||||
|
||||
webscriptPromise.catch(() => {});
|
||||
webscriptPromise.on('error', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('WebScript should fire unauthorized event if get 401', (done) => {
|
||||
webScriptMock.get401Response();
|
||||
|
||||
const webscriptPromise: any = webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath);
|
||||
|
||||
webscriptPromise.catch(() => {});
|
||||
webscriptPromise.on('unauthorized', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
54
lib/js-api/test/discoveryApi.spec.ts
Normal file
54
lib/js-api/test/discoveryApi.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, DiscoveryApi } from '../src';
|
||||
import { DiscoveryMock, EcmAuthMock } from './mockObjects';
|
||||
|
||||
describe('Discovery', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let discoveryMock: DiscoveryMock;
|
||||
let discoveryApi: DiscoveryApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
authResponseMock.get201Response();
|
||||
|
||||
discoveryMock = new DiscoveryMock(hostEcm);
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
discoveryApi = new DiscoveryApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
it('should getRepositoryInformation works', (done) => {
|
||||
discoveryMock.get200Response();
|
||||
|
||||
discoveryApi.getRepositoryInformation().then((data) => {
|
||||
assert.equal(data.entry.repository.edition, 'Enterprise');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
236
lib/js-api/test/ecmAuth.spec.ts
Normal file
236
lib/js-api/test/ecmAuth.spec.ts
Normal file
@@ -0,0 +1,236 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, ContentAuth } from '../src';
|
||||
import { EcmAuthMock as AuthEcmMock } from '../test/mockObjects';
|
||||
|
||||
describe('Ecm Auth test', () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
let authEcmMock: AuthEcmMock;
|
||||
let contentAuth: ContentAuth;
|
||||
|
||||
beforeEach(() => {
|
||||
authEcmMock = new AuthEcmMock(hostEcm);
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
contentAuth = new ContentAuth(
|
||||
{
|
||||
contextRoot: 'alfresco',
|
||||
hostEcm
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
});
|
||||
|
||||
it('should remember username on login', () => {
|
||||
const auth = new ContentAuth({}, alfrescoJsApi);
|
||||
auth.login('johndoe', 'password');
|
||||
assert.equal(auth.authentications.basicAuth.username, 'johndoe');
|
||||
});
|
||||
|
||||
it('should forget username on logout', (done) => {
|
||||
const auth = new ContentAuth({}, alfrescoJsApi);
|
||||
|
||||
authEcmMock.get201Response();
|
||||
|
||||
auth.login('johndoe', 'password');
|
||||
assert.equal(auth.authentications.basicAuth.username, 'johndoe');
|
||||
|
||||
authEcmMock.get204ResponseLogout();
|
||||
|
||||
auth.logout().then(() => {
|
||||
assert.equal(auth.authentications.basicAuth.username, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('With Authentication', () => {
|
||||
it('login should return the Ticket if all is ok', (done) => {
|
||||
authEcmMock.get201Response();
|
||||
|
||||
contentAuth.login('admin', 'admin').then((data) => {
|
||||
assert.equal(data, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('login password should be removed after login', (done) => {
|
||||
authEcmMock.get201Response();
|
||||
|
||||
contentAuth.login('admin', 'admin').then(() => {
|
||||
assert.notEqual(contentAuth.authentications.basicAuth.password, 'admin');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('isLoggedIn should return true if the api is logged in', (done) => {
|
||||
authEcmMock.get201Response();
|
||||
|
||||
contentAuth.login('admin', 'admin').then(() => {
|
||||
assert.equal(contentAuth.isLoggedIn(), true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('isLoggedIn should return false if the host change', (done) => {
|
||||
authEcmMock.get201Response();
|
||||
|
||||
contentAuth.login('admin', 'admin').then(() => {
|
||||
assert.equal(contentAuth.isLoggedIn(), true);
|
||||
contentAuth.changeHost();
|
||||
assert.equal(contentAuth.isLoggedIn(), false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('isLoggedIn should return false if the api is logged out', (done) => {
|
||||
authEcmMock.get201Response();
|
||||
|
||||
contentAuth.login('admin', 'admin');
|
||||
|
||||
authEcmMock.get204ResponseLogout();
|
||||
|
||||
contentAuth.logout().then(() => {
|
||||
assert.equal(contentAuth.isLoggedIn(), false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('login should return an error if wrong credential are used 403 the login fails', (done) => {
|
||||
authEcmMock.get403Response();
|
||||
|
||||
contentAuth.login('wrong', 'name').then(
|
||||
() => {},
|
||||
(error: any) => {
|
||||
assert.equal(error.status, 403);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('login should return an error if wrong credential are used 400 userId and/or password are/is not provided', (done) => {
|
||||
authEcmMock.get400Response();
|
||||
|
||||
contentAuth.login(null, null).then(
|
||||
() => {},
|
||||
(error) => {
|
||||
assert.equal(error.status, 400);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('Events ', () => {
|
||||
it('login should fire an event if is unauthorized 401', (done) => {
|
||||
authEcmMock.get401Response();
|
||||
|
||||
const loginPromise: any = contentAuth.login('wrong', 'name');
|
||||
loginPromise.catch(() => {});
|
||||
|
||||
loginPromise.on('unauthorized', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('login should fire an event if is forbidden 403', (done) => {
|
||||
authEcmMock.get403Response();
|
||||
|
||||
const loginPromise: any = contentAuth.login('wrong', 'name');
|
||||
|
||||
loginPromise.catch(() => {});
|
||||
|
||||
loginPromise.on('forbidden', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('The Api Should fire success event if is all ok 201', (done) => {
|
||||
authEcmMock.get201Response();
|
||||
|
||||
const loginPromise: any = contentAuth.login('admin', 'admin');
|
||||
|
||||
loginPromise.catch(() => {});
|
||||
|
||||
loginPromise.on('success', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('The Api Should fire logout event if the logout is successfull', (done) => {
|
||||
authEcmMock.get201Response();
|
||||
contentAuth.login('admin', 'admin');
|
||||
authEcmMock.get204ResponseLogout();
|
||||
|
||||
(contentAuth.logout() as any).on('logout', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('With Ticket Authentication', () => {
|
||||
it('Ticket should be present in the client', () => {
|
||||
authEcmMock.get400Response();
|
||||
|
||||
contentAuth = new ContentAuth(
|
||||
{
|
||||
ticketEcm: 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1',
|
||||
hostEcm
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
assert.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1', contentAuth.authentications.basicAuth.password);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Logout Api', () => {
|
||||
beforeEach((done) => {
|
||||
authEcmMock.get201Response('TICKET_22d7a5a83d78b9cc9666ec4e412475e5455b33bd');
|
||||
|
||||
contentAuth.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Ticket should be absent in the client and the resolve promise should be called', (done) => {
|
||||
authEcmMock.get204ResponseLogout();
|
||||
|
||||
contentAuth.logout().then(() => {
|
||||
assert.equal(contentAuth.config.ticket, undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Logout should be rejected if the Ticket is already expired', (done) => {
|
||||
authEcmMock.get404ResponseLogout();
|
||||
contentAuth.logout().then(
|
||||
() => {},
|
||||
(error) => {
|
||||
assert.equal(error.error.toString(), 'Error: Not Found');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,95 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, NodeSecurityMarkBody, SecurityMarkEntry, SecurityMarkPaging, AuthorityClearanceApi } from '../../src';
|
||||
import { AuthorityClearanceMock, EcmAuthMock } from '../mockObjects';
|
||||
|
||||
const DEFAULT_OPTS = {
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
};
|
||||
|
||||
describe('Authority Clearance API test', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let authorityClearanceMock: AuthorityClearanceMock;
|
||||
let authorityClearanceApi: AuthorityClearanceApi;
|
||||
const nodeSecurityMarkBodyList: Array<NodeSecurityMarkBody> = [
|
||||
{
|
||||
groupId: 'securityGroupFruits',
|
||||
op: 'ADD',
|
||||
id: 'fruitMarkId1'
|
||||
},
|
||||
{
|
||||
groupId: 'securityGroupFruits',
|
||||
op: 'ADD',
|
||||
id: 'fruitMarkId1'
|
||||
}
|
||||
];
|
||||
const nodeSecurityMarkBodySingle: Array<NodeSecurityMarkBody> = [
|
||||
{
|
||||
groupId: 'securityGroupFruits',
|
||||
op: 'ADD',
|
||||
id: 'fruitMarkId1'
|
||||
}
|
||||
];
|
||||
|
||||
beforeEach(async () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
authResponseMock.get201Response();
|
||||
authorityClearanceMock = new AuthorityClearanceMock(hostEcm);
|
||||
const alfrescoApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
authorityClearanceApi = new AuthorityClearanceApi(alfrescoApi);
|
||||
await alfrescoApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('get authority clearances for an authority', async () => {
|
||||
const nodeId = 'testAuthorityId';
|
||||
authorityClearanceMock.get200AuthorityClearanceForAuthority(nodeId);
|
||||
await authorityClearanceApi.getAuthorityClearanceForAuthority(nodeId, DEFAULT_OPTS).then((response) => {
|
||||
assert.equal(response.list.entries[0].entry.id, 'securityGroupFruits');
|
||||
assert.equal(response.list.entries[0].entry.displayLabel, 'Security Group FRUITS');
|
||||
assert.equal(response.list.entries[0].entry.type, 'USER_REQUIRES_ALL');
|
||||
assert.equal(response.list.entries[0].entry.marks.length, 3);
|
||||
});
|
||||
});
|
||||
|
||||
it('add single security marks to an authority', async () => {
|
||||
const nodeId = 'testAuthorityId';
|
||||
authorityClearanceMock.post200AuthorityClearanceWithSingleItem(nodeId);
|
||||
await authorityClearanceApi.updateAuthorityClearance(nodeId, nodeSecurityMarkBodySingle).then((data) => {
|
||||
const response = data as SecurityMarkEntry;
|
||||
assert.equal(response.entry.id, 'fruitMarkId1');
|
||||
assert.equal(response.entry.name, 'APPLES');
|
||||
assert.equal(response.entry.groupId, 'securityGroupFruits');
|
||||
});
|
||||
});
|
||||
|
||||
it('add multiple security marks on an authority', async () => {
|
||||
const nodeId = 'testAuthorityId';
|
||||
authorityClearanceMock.post200AuthorityClearanceWithList(nodeId);
|
||||
await authorityClearanceApi.updateAuthorityClearance(nodeId, nodeSecurityMarkBodyList).then((data) => {
|
||||
const response = data as SecurityMarkPaging;
|
||||
assert.equal(response.list.entries[0].entry.id, 'fruitMarkId1');
|
||||
assert.equal(response.list.entries[0].entry.name, 'APPLES');
|
||||
assert.equal(response.list.entries[0].entry.groupId, 'securityGroupFruits');
|
||||
});
|
||||
});
|
||||
});
|
50
lib/js-api/test/governance-services/gsSitesApi.spec.ts
Normal file
50
lib/js-api/test/governance-services/gsSitesApi.spec.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, GsSitesApi } from '../../src';
|
||||
import { EcmAuthMock, GsSitesApiMock } from '../mockObjects';
|
||||
|
||||
describe('Governance API test', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let gsSitesApiMock: GsSitesApiMock;
|
||||
let gsSitesApi: GsSitesApi;
|
||||
|
||||
beforeEach(() => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
authResponseMock.get201Response();
|
||||
|
||||
gsSitesApiMock = new GsSitesApiMock(hostEcm);
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
gsSitesApi = new GsSitesApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
it('should getRMSite return the RM site', (done) => {
|
||||
gsSitesApiMock.get200Response();
|
||||
|
||||
gsSitesApi.getRMSite().then((data) => {
|
||||
assert.equal(data.entry.description, 'Records Management Description Test');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,70 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, NodeSecurityMarksApi, NodeSecurityMarkBody } from '../../src';
|
||||
import { EcmAuthMock, NodeSecurityMarksApiMock } from '../mockObjects';
|
||||
|
||||
describe('Node Security Mark API test', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let nodeSecurityMarksMock: NodeSecurityMarksApiMock;
|
||||
let nodeSecurityMarksApi: NodeSecurityMarksApi;
|
||||
const nodeSecurityMarkBody: Array<NodeSecurityMarkBody> = [
|
||||
{
|
||||
groupId: 'securityGroupId1',
|
||||
op: 'ADD',
|
||||
id: 'Sh1G8vTQ'
|
||||
},
|
||||
{
|
||||
groupId: 'securityGroupId2',
|
||||
op: 'ADD',
|
||||
id: 'Sh1G8vTR'
|
||||
}
|
||||
];
|
||||
|
||||
beforeEach(async () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
authResponseMock.get201Response();
|
||||
nodeSecurityMarksMock = new NodeSecurityMarksApiMock(hostEcm);
|
||||
const alfrescoApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
nodeSecurityMarksApi = new NodeSecurityMarksApi(alfrescoApi);
|
||||
await alfrescoApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('add or remove security marks on a node', async () => {
|
||||
const nodeId = 'h3bdk2knw2kn';
|
||||
nodeSecurityMarksMock.post200manageSecurityMarkOnNode(nodeId);
|
||||
await nodeSecurityMarksApi.manageSecurityMarksOnNode(nodeId, nodeSecurityMarkBody).then((data) => {
|
||||
assert.equal(data.list.entries[0].entry.groupId, 'securityGroupId1');
|
||||
assert.equal(data.list.entries[0].entry.id, 'Sh1G8vTQ');
|
||||
assert.equal(data.list.entries[0].entry.name, 'SecurityMarkTest1');
|
||||
});
|
||||
});
|
||||
|
||||
it('get security marks on a node', async () => {
|
||||
const nodeId = 'h3bdk2knw2kn';
|
||||
nodeSecurityMarksMock.get200SecurityMarkOnNode(nodeId);
|
||||
await nodeSecurityMarksApi.getSecurityMarksOnNode(nodeId).then((data) => {
|
||||
assert.equal(data.list.entries[1].entry.groupId, 'securityGroupId2');
|
||||
assert.equal(data.list.entries[1].entry.id, 'Sh1G8vTR');
|
||||
assert.equal(data.list.entries[1].entry.name, 'SecurityMarkTest2');
|
||||
});
|
||||
});
|
||||
});
|
93
lib/js-api/test/governance-services/securityGroupApi.spec.ts
Normal file
93
lib/js-api/test/governance-services/securityGroupApi.spec.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AlfrescoApi, SecurityGroupsApi, SecurityGroupBody } from '../../src';
|
||||
import assert from 'assert';
|
||||
import { EcmAuthMock, SecurityGroupApiMock } from '../mockObjects';
|
||||
|
||||
describe('Security Group API test', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let securityGroupMock: SecurityGroupApiMock;
|
||||
let securityGroupApi: SecurityGroupsApi;
|
||||
const securityGroupBody: SecurityGroupBody = {
|
||||
groupName: 'Alfresco',
|
||||
groupType: 'HIERARCHICAL'
|
||||
};
|
||||
let securityGroupId: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
authResponseMock.get201Response();
|
||||
securityGroupMock = new SecurityGroupApiMock(hostEcm);
|
||||
const alfrescoApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
securityGroupApi = new SecurityGroupsApi(alfrescoApi);
|
||||
await alfrescoApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('create Security Group', async () => {
|
||||
securityGroupMock.createSecurityGroup200Response();
|
||||
await securityGroupApi.createSecurityGroup(securityGroupBody).then((data) => {
|
||||
securityGroupId = data.entry.id;
|
||||
assert.notEqual(data.entry.id, null);
|
||||
assert.equal(data.entry.groupName, 'Alfresco');
|
||||
assert.equal(data.entry.groupType, 'HIERARCHICAL');
|
||||
});
|
||||
});
|
||||
|
||||
it('get All Security Groups', async () => {
|
||||
securityGroupMock.getSecurityGroups200Response();
|
||||
await securityGroupApi.getSecurityGroups().then((data) => {
|
||||
assert.equal(data.list.entries.length > 0, true);
|
||||
});
|
||||
});
|
||||
|
||||
it('get Security Group Information', async () => {
|
||||
securityGroupMock.getSecurityGroupInfo200Response(securityGroupId);
|
||||
await securityGroupApi.getSecurityGroupInfo(securityGroupId).then((data) => {
|
||||
assert.notEqual(data.entry.id, null);
|
||||
assert.equal(data.entry.groupName, 'Alfresco');
|
||||
assert.equal(data.entry.groupType, 'HIERARCHICAL');
|
||||
});
|
||||
});
|
||||
|
||||
it('update Security Group', async () => {
|
||||
securityGroupMock.updateSecurityGroup200Response(securityGroupId);
|
||||
const updatedSecurityGroupBody: SecurityGroupBody = {
|
||||
groupName: 'Nasa'
|
||||
};
|
||||
await securityGroupApi.updateSecurityGroup(securityGroupId, updatedSecurityGroupBody).then((data) => {
|
||||
assert.notEqual(data.entry.id, null);
|
||||
assert.equal(data.entry.groupName, 'Nasa');
|
||||
assert.equal(data.entry.groupType, 'HIERARCHICAL');
|
||||
});
|
||||
});
|
||||
|
||||
it('delete Security Group', async () => {
|
||||
securityGroupMock.deleteSecurityGroup200Response(securityGroupId);
|
||||
await securityGroupApi
|
||||
.deleteSecurityGroup(securityGroupId)
|
||||
.then((data) => {
|
||||
Promise.resolve(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
Promise.reject(err);
|
||||
});
|
||||
});
|
||||
});
|
130
lib/js-api/test/governance-services/securityMarksApi.spec.ts
Normal file
130
lib/js-api/test/governance-services/securityMarksApi.spec.ts
Normal file
@@ -0,0 +1,130 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, SecurityGroupBody, SecurityGroupsApi, SecurityMarkBody, SecurityMarksApi, SecurityMarksBody } from '../../src';
|
||||
import { EcmAuthMock, SecurityGroupApiMock, SecurityMarkApiMock } from '../mockObjects';
|
||||
|
||||
describe('Security Mark API test', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let securityMarkApiMock: SecurityMarkApiMock;
|
||||
let securityGroupMock: SecurityGroupApiMock;
|
||||
let securityGroupApi: SecurityGroupsApi;
|
||||
let securityMarksApi: SecurityMarksApi;
|
||||
let securityGroupId = 'a0a7b107-84ba-4c3d-b0b7-a8509e8c1c33';
|
||||
let securityMarkId = 'Sh1G8vTQ';
|
||||
const securityMarksBodySingle: SecurityMarksBody = [
|
||||
{
|
||||
name: 'SecurityMarkTest'
|
||||
}
|
||||
];
|
||||
const securityGroupBody: SecurityGroupBody = {
|
||||
groupName: 'Alfresco',
|
||||
groupType: 'HIERARCHICAL'
|
||||
};
|
||||
const securityMarksBody: SecurityMarksBody = [
|
||||
{
|
||||
name: 'SecurityMark3'
|
||||
},
|
||||
{
|
||||
name: 'SecurityMark4'
|
||||
}
|
||||
];
|
||||
|
||||
beforeEach(async () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
authResponseMock.get201Response();
|
||||
securityGroupMock = new SecurityGroupApiMock(hostEcm);
|
||||
securityMarkApiMock = new SecurityMarkApiMock(hostEcm);
|
||||
const alfrescoApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
securityGroupApi = new SecurityGroupsApi(alfrescoApi);
|
||||
securityMarksApi = new SecurityMarksApi(alfrescoApi);
|
||||
await alfrescoApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('create Security Group', async () => {
|
||||
securityGroupMock.createSecurityGroup200Response();
|
||||
await securityGroupApi.createSecurityGroup(securityGroupBody).then((data) => {
|
||||
securityGroupId = data.entry.id;
|
||||
assert.notEqual(data.entry.id, null);
|
||||
assert.equal(data.entry.groupName, 'Alfresco');
|
||||
assert.equal(data.entry.groupType, 'HIERARCHICAL');
|
||||
});
|
||||
});
|
||||
|
||||
it('create Security Mark', async () => {
|
||||
securityMarkApiMock.createSecurityMark200Response(securityGroupId);
|
||||
await securityMarksApi.createSecurityMarks(securityGroupId, securityMarksBodySingle).then((data: any) => {
|
||||
securityMarkId = data.entry.id;
|
||||
assert.notEqual(data.entry.id, null);
|
||||
assert.equal(data.entry.name, 'SecurityMarkTest');
|
||||
assert.equal(data.entry.groupId, securityGroupId);
|
||||
});
|
||||
});
|
||||
|
||||
it('create multiple Security Mark', async () => {
|
||||
securityMarkApiMock.createSecurityMarks200Response(securityGroupId);
|
||||
await securityMarksApi.createSecurityMarks(securityGroupId, securityMarksBody).then((data: any) => {
|
||||
assert.notEqual(data.list.entries[0].entry.id, null);
|
||||
assert.equal(data.list.entries[0].entry.name, 'SecurityMark3');
|
||||
assert.equal(data.list.entries[0].entry.groupId, securityGroupId);
|
||||
});
|
||||
});
|
||||
|
||||
it('get All Security Marks', async () => {
|
||||
securityMarkApiMock.get200GetSecurityMark(securityGroupId);
|
||||
await securityMarksApi.getSecurityMarks(securityGroupId).then((data) => {
|
||||
assert.equal(data.list.entries.length > 0, true);
|
||||
});
|
||||
});
|
||||
|
||||
it('get Security Mark Information', async () => {
|
||||
securityMarkApiMock.get200GetSingleSecurityMark(securityGroupId, securityMarkId);
|
||||
await securityMarksApi.getSecurityMark(securityGroupId, securityMarkId).then((data) => {
|
||||
assert.notEqual(data.entry.id, null);
|
||||
assert.equal(data.entry.name, 'SecurityMarkTest');
|
||||
assert.equal(data.entry.groupId, securityGroupId);
|
||||
});
|
||||
});
|
||||
|
||||
it('update Security Mark', async () => {
|
||||
const updatedSecurityMarkBody: SecurityMarkBody = {
|
||||
name: 'AlfrescoSecurityMark'
|
||||
};
|
||||
securityMarkApiMock.put200UpdateSecurityMarkResponse(securityGroupId, securityMarkId);
|
||||
await securityMarksApi.updateSecurityMark(securityGroupId, securityMarkId, updatedSecurityMarkBody).then((data) => {
|
||||
assert.notEqual(data.entry.id, null);
|
||||
assert.equal(data.entry.name, 'AlfrescoSecurityMark');
|
||||
assert.equal(data.entry.groupId, securityGroupId);
|
||||
});
|
||||
});
|
||||
|
||||
it('delete Security Mark', async () => {
|
||||
securityMarkApiMock.getDeleteSecurityMarkSuccessfulResponse(securityGroupId, securityMarkId);
|
||||
await securityGroupApi
|
||||
.deleteSecurityGroup(securityGroupId)
|
||||
.then((data) => {
|
||||
Promise.resolve(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
Promise.reject(err);
|
||||
});
|
||||
});
|
||||
});
|
1
lib/js-api/test/mockObjects/assets/testFile.txt
Normal file
1
lib/js-api/test/mockObjects/assets/testFile.txt
Normal file
@@ -0,0 +1 @@
|
||||
this is a test upload File.
|
1
lib/js-api/test/mockObjects/assets/testFile2.txt
Normal file
1
lib/js-api/test/mockObjects/assets/testFile2.txt
Normal file
@@ -0,0 +1 @@
|
||||
this is a test form multiple upload File.
|
38
lib/js-api/test/mockObjects/base.mock.ts
Normal file
38
lib/js-api/test/mockObjects/base.mock.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
|
||||
export class BaseMock {
|
||||
host: string;
|
||||
|
||||
constructor(host?: string) {
|
||||
this.host = host || 'https://127.0.0.1:8080';
|
||||
}
|
||||
|
||||
put200GenericResponse(scriptSlug: string): void {
|
||||
nock(this.host, { encodedQueryParams: true }).put(scriptSlug).reply(200);
|
||||
}
|
||||
|
||||
play(): void {
|
||||
nock.recorder.play();
|
||||
}
|
||||
|
||||
cleanAll(): void {
|
||||
nock.cleanAll();
|
||||
}
|
||||
}
|
347
lib/js-api/test/mockObjects/content-services/categories.mock.ts
Normal file
347
lib/js-api/test/mockObjects/content-services/categories.mock.ts
Normal file
@@ -0,0 +1,347 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class CategoriesMock extends BaseMock {
|
||||
get200ResponseSubcategories(categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`)
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: 'testId1',
|
||||
name: 'testName1',
|
||||
parentId: '-root-',
|
||||
hasChildren: true,
|
||||
count: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'testId2',
|
||||
name: 'testName2',
|
||||
parentId: '-root-',
|
||||
hasChildren: true,
|
||||
count: 0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get404SubcategoryNotExist(categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`)
|
||||
.reply(404, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.EntityNotFound',
|
||||
statusCode: 404,
|
||||
briefSummary: `05220073 The entity with id: ${categoryId} was not found`,
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200ResponseCategory(categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`)
|
||||
.reply(200, {
|
||||
entry: {
|
||||
id: 'testId1',
|
||||
name: 'testName1',
|
||||
parentId: '-root-',
|
||||
hasChildren: true,
|
||||
count: 0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get404CategoryNotExist(categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`)
|
||||
.reply(404, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.EntityNotFound',
|
||||
statusCode: 404,
|
||||
briefSummary: `05220073 The entity with id: ${categoryId} was not found`,
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200ResponseNodeCategoryLinks(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`)
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 1,
|
||||
hasMoreItems: false,
|
||||
totalItems: 1,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: 'testId1',
|
||||
name: 'testName1',
|
||||
parentId: 'testNode',
|
||||
hasChildren: true,
|
||||
count: 0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get403NodeCategoryLinksPermissionDenied(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`)
|
||||
.reply(403, {
|
||||
error: {
|
||||
statusCode: 403
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get404NodeNotExist(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`)
|
||||
.reply(404, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.EntityNotFound',
|
||||
statusCode: 404,
|
||||
briefSummary: `05220073 The entity with id: ${nodeId} was not found`,
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get204CategoryUnlinked(nodeId: string, categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links/${categoryId}`)
|
||||
.reply(204);
|
||||
}
|
||||
|
||||
get403CategoryUnlinkPermissionDenied(nodeId: string, categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links/${categoryId}`)
|
||||
.reply(403, {
|
||||
error: {
|
||||
statusCode: 403
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get404CategoryUnlinkNotFound(nodeId: string, categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links/${categoryId}`)
|
||||
.reply(404, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.EntityNotFound',
|
||||
statusCode: 404,
|
||||
briefSummary: `05230078 The entity with id: ${nodeId} or ${categoryId} was not found`,
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200ResponseCategoryUpdated(categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`, { name: 'testName1' })
|
||||
.reply(200, {
|
||||
entry: {
|
||||
id: 'testId1',
|
||||
name: 'testName1',
|
||||
parentId: '-root-',
|
||||
hasChildren: true,
|
||||
count: 0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get403CategoryUpdatePermissionDenied(categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`, { name: 'testName1' })
|
||||
.reply(403, {
|
||||
error: {
|
||||
statusCode: 403
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get404CategoryUpdateNotFound(categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`, { name: 'testName1' })
|
||||
.reply(404, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.EntityNotFound',
|
||||
statusCode: 404,
|
||||
briefSummary: `05230078 The entity with id: ${categoryId} was not found`,
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get201ResponseCategoryCreated(categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`, [{ name: 'testName10' }])
|
||||
.reply(201, {
|
||||
entry: {
|
||||
id: 'testId10',
|
||||
name: 'testName10',
|
||||
parentId: categoryId,
|
||||
hasChildren: true,
|
||||
count: 0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get403CategoryCreatedPermissionDenied(categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`, [{ name: 'testName10' }])
|
||||
.reply(403, {
|
||||
error: {
|
||||
statusCode: 403
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get409CategoryCreateAlreadyExists(categoryId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`, [{ name: 'testName10' }])
|
||||
.reply(409, {
|
||||
error: {
|
||||
errorKey: 'Duplicate child name not allowed: testName10',
|
||||
statusCode: 409,
|
||||
briefSummary: '06050055 Duplicate child name not allowed: testName10',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get201ResponseCategoryLinked(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }])
|
||||
.reply(201, {
|
||||
entry: {
|
||||
id: 'testId1',
|
||||
name: 'testName1',
|
||||
parentId: nodeId,
|
||||
hasChildren: true,
|
||||
count: 0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get201ResponseCategoryLinkedArray(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [
|
||||
{ categoryId: 'testId1' },
|
||||
{ categoryId: 'testId2' }
|
||||
])
|
||||
.reply(201, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: 'testId1',
|
||||
name: 'testName1',
|
||||
parentId: 'testNodeArr',
|
||||
hasChildren: true,
|
||||
count: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'testId2',
|
||||
name: 'testName2',
|
||||
parentId: 'testNodeArr',
|
||||
hasChildren: true,
|
||||
count: 0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get403CategoryLinkPermissionDenied(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }])
|
||||
.reply(403, {
|
||||
error: {
|
||||
statusCode: 403
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get404CategoryLinkNotFound(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }])
|
||||
.reply(404, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.EntityNotFound',
|
||||
statusCode: 404,
|
||||
briefSummary: `05230078 The entity with id: ${nodeId} or testId1 was not found`,
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get405CategoryLinkCannotAssign(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }])
|
||||
.reply(405, {
|
||||
error: {
|
||||
errorKey: 'Cannot assign node of this type to a category',
|
||||
statusCode: 405,
|
||||
briefSummary: `05230078 Cannot assign a node of this type to a category`,
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
105
lib/js-api/test/mockObjects/content-services/comment.mock.ts
Normal file
105
lib/js-api/test/mockObjects/content-services/comment.mock.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
const adminUser = {
|
||||
aspectNames: ['cm:ownable'],
|
||||
firstName: 'Administrator',
|
||||
emailNotificationsEnabled: true,
|
||||
company: {},
|
||||
id: 'admin',
|
||||
enabled: true,
|
||||
email: 'admin@alfresco.com',
|
||||
properties: {
|
||||
'cm:homeFolderProvider': 'bootstrapHomeFolderProvider',
|
||||
'cm:authorizationStatus': 'AUTHORIZED',
|
||||
'cm:homeFolder': '72866d2e-64ee-45a2-ae00-30a5ced96a41',
|
||||
'cm:name': '56f78250-37a7-4e22-b35a-64b53ae1e5ca',
|
||||
'cm:owner': { id: 'admin', displayName: 'Administrator' },
|
||||
'cm:organizationId': ''
|
||||
}
|
||||
};
|
||||
|
||||
export class CommentMock extends BaseMock {
|
||||
post201Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/74cd8a96-8a21-47e5-9b3b-a1b3e296787d/comments', {
|
||||
content: 'This is a comment'
|
||||
})
|
||||
.reply(201, {
|
||||
entry: {
|
||||
createdAt: '2017-04-11T09:31:21.452+0000',
|
||||
createdBy: adminUser,
|
||||
edited: false,
|
||||
modifiedAt: '2017-04-11T09:31:21.452+0000',
|
||||
canEdit: true,
|
||||
modifiedBy: adminUser,
|
||||
canDelete: true,
|
||||
id: 'c294cf79-49c1-483e-ac86-39c8fe3cce8f',
|
||||
content: 'This is a comment'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/74cd8a96-8a21-47e5-9b3b-a1b3e296787d/comments')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2017-04-11T09:31:21.658+0000',
|
||||
createdBy: adminUser,
|
||||
edited: false,
|
||||
modifiedAt: '2017-04-11T09:31:21.658+0000',
|
||||
canEdit: true,
|
||||
modifiedBy: adminUser,
|
||||
canDelete: true,
|
||||
id: '539fc9b2-7d5b-4966-9e44-fcf433647f25',
|
||||
content: 'This is another comment'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2017-04-11T09:31:21.452+0000',
|
||||
createdBy: adminUser,
|
||||
edited: false,
|
||||
modifiedAt: '2017-04-11T09:31:21.452+0000',
|
||||
canEdit: true,
|
||||
modifiedBy: adminUser,
|
||||
canDelete: true,
|
||||
id: 'c294cf79-49c1-483e-ac86-39c8fe3cce8f',
|
||||
content: 'This is a comment'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class CustomModelMock extends BaseMock {
|
||||
get200AllCustomModel(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/private/alfresco/versions/1/cmm')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 0,
|
||||
hasMoreItems: false,
|
||||
totalItems: 0,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: []
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
create201CustomModel(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/private/alfresco/versions/1/cmm')
|
||||
.reply(201, {
|
||||
entry: {
|
||||
author: 'Administrator',
|
||||
name: 'testModel',
|
||||
description: 'Test model description',
|
||||
namespaceUri: 'https://www.alfresco.org/model/testNamespace/1.0',
|
||||
namespacePrefix: 'test',
|
||||
status: 'DRAFT'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
activateCustomModel200(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put('/alfresco/api/-default-/private/alfresco/versions/1/cmm/testModel', { status: 'ACTIVE' })
|
||||
.query({ select: 'status' })
|
||||
.reply(200, {
|
||||
entry: {
|
||||
author: 'Administrator',
|
||||
name: 'testModel',
|
||||
description: 'Test model description',
|
||||
namespaceUri: 'https://www.alfresco.org/model/testNamespace/1.0',
|
||||
namespacePrefix: 'test',
|
||||
status: 'ACTIVE'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class DiscoveryMock extends BaseMock {
|
||||
get200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/discovery')
|
||||
.reply(200, {
|
||||
entry: {
|
||||
repository: {
|
||||
edition: 'Enterprise',
|
||||
version: {
|
||||
major: '5',
|
||||
minor: '2',
|
||||
patch: '1',
|
||||
hotfix: '0',
|
||||
schema: 10052,
|
||||
label: 'r133188-b433',
|
||||
display: '5.2.1.0 (r133188-b433) schema 10052'
|
||||
},
|
||||
license: {
|
||||
issuedAt: '2017-04-10T10:45:00.177+0000',
|
||||
expiresAt: '2017-05-10T00:00:00.000+0000',
|
||||
remainingDays: 16,
|
||||
holder: 'Trial User',
|
||||
mode: 'ENTERPRISE',
|
||||
entitlements: { isClusterEnabled: false, isCryptodocEnabled: false }
|
||||
},
|
||||
status: {
|
||||
isReadOnly: false,
|
||||
isAuditEnabled: true,
|
||||
isQuickShareEnabled: true,
|
||||
isThumbnailGenerationEnabled: true
|
||||
},
|
||||
modules: [
|
||||
{
|
||||
id: 'alfresco-share-services',
|
||||
title: 'Alfresco Share Services AMP',
|
||||
description: 'Module to be applied to alfresco.war, containing APIs for Alfresco Share',
|
||||
version: '5.2.0',
|
||||
installDate: '2016-11-28T18:59:22.555+0000',
|
||||
installState: 'INSTALLED',
|
||||
versionMin: '5.1',
|
||||
versionMax: '999'
|
||||
},
|
||||
{
|
||||
id: 'alfresco-trashcan-cleaner',
|
||||
title: 'alfresco-trashcan-cleaner project',
|
||||
description: 'The Alfresco Trash Can Cleaner (Alfresco Module)',
|
||||
version: '2.2',
|
||||
installState: 'UNKNOWN',
|
||||
versionMin: '0',
|
||||
versionMax: '999'
|
||||
},
|
||||
{
|
||||
id: 'enablecors',
|
||||
title: 'Enable Cors support',
|
||||
description: 'Adds a web-fragment with the filter config for Cors support',
|
||||
version: '1.0-SNAPSHOT',
|
||||
installState: 'UNKNOWN',
|
||||
versionMin: '0',
|
||||
versionMax: '999'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
108
lib/js-api/test/mockObjects/content-services/ecm-auth.mock.ts
Normal file
108
lib/js-api/test/mockObjects/content-services/ecm-auth.mock.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class EcmAuthMock extends BaseMock {
|
||||
username: string;
|
||||
password: string;
|
||||
|
||||
constructor(host?: string, username?: string, password?: string) {
|
||||
super(host);
|
||||
this.username = username || 'admin';
|
||||
this.password = password || 'admin';
|
||||
}
|
||||
|
||||
get201Response(forceTicket?: string): void {
|
||||
const returnMockTicket = forceTicket || 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1';
|
||||
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/authentication/versions/1/tickets', {
|
||||
userId: this.username,
|
||||
password: this.password
|
||||
})
|
||||
.reply(201, { entry: { id: returnMockTicket, userId: 'admin' } });
|
||||
}
|
||||
|
||||
get200ValidTicket(forceTicket?: string): void {
|
||||
const returnMockTicket = forceTicket || 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1';
|
||||
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/authentication/versions/1/tickets/-me-')
|
||||
.reply(200, { entry: { id: returnMockTicket } });
|
||||
}
|
||||
|
||||
get403Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/authentication/versions/1/tickets', {
|
||||
userId: 'wrong',
|
||||
password: 'name'
|
||||
})
|
||||
.reply(403, {
|
||||
error: {
|
||||
errorKey: 'Login failed',
|
||||
statusCode: 403,
|
||||
briefSummary: '05150009 Login failed',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get400Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/authentication/versions/1/tickets', {
|
||||
userId: null,
|
||||
password: null
|
||||
})
|
||||
.reply(400, {
|
||||
error: {
|
||||
errorKey: 'Invalid login details.',
|
||||
statusCode: 400,
|
||||
briefSummary: '05160045 Invalid login details.',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get401Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/authentication/versions/1/tickets', {
|
||||
userId: 'wrong',
|
||||
password: 'name'
|
||||
})
|
||||
.reply(401, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.ApiDefault',
|
||||
statusCode: 401,
|
||||
briefSummary: '05210059 Authentication failed for Web Script org/alfresco/api/ResourceWebScript.get',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get204ResponseLogout(): void {
|
||||
nock(this.host, { encodedQueryParams: true }).delete('/alfresco/api/-default-/public/authentication/versions/1/tickets/-me-').reply(204, '');
|
||||
}
|
||||
|
||||
get404ResponseLogout(): void {
|
||||
nock(this.host, { encodedQueryParams: true }).delete('/alfresco/api/-default-/public/authentication/versions/1/tickets/-me-').reply(404, '');
|
||||
}
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class FindNodesMock extends BaseMock {
|
||||
get200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/queries/nodes?term=test')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2011-03-03T10:34:52.092+0000',
|
||||
isFolder: false,
|
||||
isFile: true,
|
||||
createdByUser: { id: 'abeecher', displayName: 'Alice Beecher' },
|
||||
modifiedAt: '2011-03-03T10:34:52.092+0000',
|
||||
modifiedByUser: { id: 'abeecher', displayName: 'Alice Beecher' },
|
||||
name: 'coins1.JPG',
|
||||
id: '7bb9c846-fcc5-43b5-a893-39e46ebe94d4',
|
||||
nodeType: 'cm:content',
|
||||
content: {
|
||||
mimeType: 'image/jpeg',
|
||||
mimeTypeName: 'JPEG Image',
|
||||
sizeInBytes: 501641,
|
||||
encoding: 'UTF-8'
|
||||
},
|
||||
parentId: '880a0f47-31b1-4101-b20b-4d325e54e8b1'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2011-03-03T10:34:52.092+0000',
|
||||
isFolder: false,
|
||||
isFile: true,
|
||||
createdByUser: { id: 'abeecher', displayName: 'Alice Beecher' },
|
||||
modifiedAt: '2011-03-03T10:34:52.092+0000',
|
||||
modifiedByUser: { id: 'abeecher', displayName: 'Alice Beecher' },
|
||||
name: 'coins2.JPG',
|
||||
id: '7bb9c846-fcc5-43b5-a893-39e46ebe94d4',
|
||||
nodeType: 'cm:content',
|
||||
content: {
|
||||
mimeType: 'image/jpeg',
|
||||
mimeTypeName: 'JPEG Image',
|
||||
sizeInBytes: 501641,
|
||||
encoding: 'UTF-8'
|
||||
},
|
||||
parentId: '880a0f47-31b1-4101-b20b-4d325e54e8b1'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get401Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/queries/nodes?term=test')
|
||||
.reply(401, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.ApiDefault',
|
||||
statusCode: 401,
|
||||
briefSummary: '05210059 Authentication failed for Web Script org/alfresco/api/ResourceWebScript.get',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
139
lib/js-api/test/mockObjects/content-services/groups.mock.ts
Normal file
139
lib/js-api/test/mockObjects/content-services/groups.mock.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class GroupsMock extends BaseMock {
|
||||
get200GetGroups(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/groups')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: true,
|
||||
totalItems: 279,
|
||||
skipCount: 0,
|
||||
maxItems: 2
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
isRoot: true,
|
||||
displayName: 'alfalfb',
|
||||
id: 'GROUP_alfalfa'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
isRoot: true,
|
||||
displayName: 'Call CenterAA',
|
||||
id: 'GROUP_CallCenterAA'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getDeleteGroupSuccessfulResponse(groupName: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete('/alfresco/api/-default-/public/alfresco/versions/1/groups/' + groupName)
|
||||
.query({ cascade: 'false' })
|
||||
.reply(200);
|
||||
}
|
||||
|
||||
getDeleteMemberForGroupSuccessfulResponse(groupName: string, memberName: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete('/alfresco/api/-default-/public/alfresco/versions/1/groups/' + groupName + '/members/' + memberName)
|
||||
.reply(200);
|
||||
}
|
||||
|
||||
get200CreateGroupResponse(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/groups')
|
||||
.reply(200, {
|
||||
entry: {
|
||||
isRoot: true,
|
||||
displayName: 'SAMPLE',
|
||||
id: 'GROUP_TEST'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200GetSingleGroup(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/groups/GROUP_TEST')
|
||||
.reply(200, {
|
||||
entry: {
|
||||
isRoot: true,
|
||||
displayName: 'SAMPLE',
|
||||
id: 'GROUP_TEST'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200UpdateGroupResponse(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put('/alfresco/api/-default-/public/alfresco/versions/1/groups/GROUP_TEST')
|
||||
.reply(200, {
|
||||
entry: {
|
||||
isRoot: true,
|
||||
displayName: 'CHANGED',
|
||||
id: 'GROUP_TEST'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200GetGroupMemberships(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/groups/GROUP_TEST/members')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 1,
|
||||
hasMoreItems: false,
|
||||
totalItems: 1,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
displayName: 'SAMPLE',
|
||||
id: 'GROUP_SUB_TEST',
|
||||
memberType: 'GROUP'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200AddGroupMembershipResponse(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/groups/GROUP_TEST/members')
|
||||
.reply(200, {
|
||||
entry: {
|
||||
displayName: 'SAMPLE',
|
||||
id: 'GROUP_SUB_TEST',
|
||||
memberType: 'GROUP'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
233
lib/js-api/test/mockObjects/content-services/node.mock.ts
Normal file
233
lib/js-api/test/mockObjects/content-services/node.mock.ts
Normal file
@@ -0,0 +1,233 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class NodeMock extends BaseMock {
|
||||
get200ResponseChildren(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/children')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 5,
|
||||
hasMoreItems: false,
|
||||
totalItems: 5,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2011-02-15T20:19:00.007+0000',
|
||||
isFolder: true,
|
||||
isFile: false,
|
||||
createdByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
modifiedAt: '2011-02-15T20:19:00.007+0000',
|
||||
modifiedByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
name: 'dataLists',
|
||||
id: '64f69e69-f61e-42a3-8697-95eea1f2bda2',
|
||||
nodeType: 'cm:folder',
|
||||
parentId: 'b4cff62a-664d-4d45-9302-98723eac1319'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2011-02-15T22:04:54.290+0000',
|
||||
isFolder: true,
|
||||
isFile: false,
|
||||
createdByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
modifiedAt: '2011-02-15T22:04:54.290+0000',
|
||||
modifiedByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
name: 'discussions',
|
||||
id: '059c5bc7-2d38-4dc5-96b8-d09cd3c69b4c',
|
||||
nodeType: 'cm:folder',
|
||||
parentId: 'b4cff62a-664d-4d45-9302-98723eac1319'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2011-02-15T20:16:28.292+0000',
|
||||
isFolder: true,
|
||||
isFile: false,
|
||||
createdByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
modifiedAt: '2016-06-27T14:31:10.007+0000',
|
||||
modifiedByUser: { id: 'admin', displayName: 'Administrator' },
|
||||
name: 'documentLibrary',
|
||||
id: '8f2105b4-daaf-4874-9e8a-2152569d109b',
|
||||
nodeType: 'cm:folder',
|
||||
parentId: 'b4cff62a-664d-4d45-9302-98723eac1319'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2011-02-15T20:18:59.808+0000',
|
||||
isFolder: true,
|
||||
isFile: false,
|
||||
createdByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
modifiedAt: '2011-02-15T20:18:59.808+0000',
|
||||
modifiedByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
name: 'links',
|
||||
id: '0e24b99c-41f0-43e1-a55e-fb9f50d73820',
|
||||
nodeType: 'cm:folder',
|
||||
parentId: 'b4cff62a-664d-4d45-9302-98723eac1319'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2011-02-15T21:46:01.603+0000',
|
||||
isFolder: true,
|
||||
isFile: false,
|
||||
createdByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
modifiedAt: '2011-02-15T21:46:01.603+0000',
|
||||
modifiedByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
name: 'wiki',
|
||||
id: 'cdefb3a9-8f55-4771-a9e3-06fa370250f6',
|
||||
nodeType: 'cm:folder',
|
||||
parentId: 'b4cff62a-664d-4d45-9302-98723eac1319'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200ResponseChildrenNonUTCTimes(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1320/children')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 5,
|
||||
hasMoreItems: false,
|
||||
totalItems: 5,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2011-03-15T12:04:54.290-0500',
|
||||
isFolder: true,
|
||||
isFile: false,
|
||||
createdByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
modifiedAt: '2011-03-15T12:04:54.290-0500',
|
||||
modifiedByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
name: 'discussions',
|
||||
id: '059c5bc7-2d38-4dc5-96b8-d09cd3c69b4c',
|
||||
nodeType: 'cm:folder',
|
||||
parentId: 'b4cff62a-664d-4d45-9302-98723eac1320'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get404ChildrenNotExist(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/children')
|
||||
.reply(404, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.EntityNotFound',
|
||||
statusCode: 404,
|
||||
briefSummary: '05220073 The entity with id: 80a94ac4-3ec4-47ad-864e-5d939424c47c was not found',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get401CreationFolder(): void {
|
||||
nock(this.host, { encodedQueryParams: true }).post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children').reply(401);
|
||||
}
|
||||
|
||||
get204SuccessfullyDeleted(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete('/alfresco/api/-default-/public/alfresco/versions/1/nodes/80a94ac8-3ece-47ad-864e-5d939424c47c')
|
||||
.reply(204);
|
||||
}
|
||||
|
||||
get403DeletePermissionDenied(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete('/alfresco/api/-default-/public/alfresco/versions/1/nodes/80a94ac8-3ece-47ad-864e-5d939424c47c')
|
||||
.reply(403);
|
||||
}
|
||||
|
||||
get404DeleteNotFound(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete('/alfresco/api/-default-/public/alfresco/versions/1/nodes/80a94ac8-test-47ad-864e-5d939424c47c')
|
||||
.reply(404, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.EntityNotFound',
|
||||
statusCode: 404,
|
||||
briefSummary: '05230078 The entity with id: 80a94ac8-test-47ad-864e-5d939424c47c was not found',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200ResponseChildrenFutureNewPossibleValue(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/children')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2011-02-15T20:19:00.007+0000',
|
||||
isFolder: true,
|
||||
isFile: false,
|
||||
createdByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
modifiedAt: '2011-02-15T20:19:00.007+0000',
|
||||
modifiedByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
name: 'dataLists',
|
||||
id: '64f69e69-f61e-42a3-8697-95eea1f2bda2',
|
||||
nodeType: 'cm:folder',
|
||||
parentId: 'b4cff62a-664d-4d45-9302-98723eac1319',
|
||||
impossibleProperties: 'impossibleRightValue'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2011-02-15T22:04:54.290+0000',
|
||||
isFolder: true,
|
||||
isFile: false,
|
||||
createdByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
modifiedAt: '2011-02-15T22:04:54.290+0000',
|
||||
modifiedByUser: { id: 'mjackson', displayName: 'Mike Jackson' },
|
||||
name: 'discussions',
|
||||
id: '059c5bc7-2d38-4dc5-96b8-d09cd3c69b4c',
|
||||
nodeType: 'cm:folder',
|
||||
parentId: 'b4cff62a-664d-4d45-9302-98723eac1319',
|
||||
impossibleProperties: 'impossibleRightValue'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
115
lib/js-api/test/mockObjects/content-services/people.mock.ts
Normal file
115
lib/js-api/test/mockObjects/content-services/people.mock.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class PeopleMock extends BaseMock {
|
||||
get201Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/people')
|
||||
.reply(201, {
|
||||
entry: {
|
||||
firstName: 'chewbacca',
|
||||
lastName: 'Chewbe',
|
||||
emailNotificationsEnabled: true,
|
||||
company: {},
|
||||
id: 'chewbe',
|
||||
enabled: true,
|
||||
email: 'chewbe@millenniumfalcon.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200ResponsePersons(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/people')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 5,
|
||||
hasMoreItems: true,
|
||||
totalItems: 153,
|
||||
skipCount: 0,
|
||||
maxItems: 5
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
firstName: 'anSNSlXA',
|
||||
lastName: '3PhtPlBO',
|
||||
jobTitle: 'N/A',
|
||||
emailNotificationsEnabled: true,
|
||||
company: {},
|
||||
id: '0jl2FBTc',
|
||||
enabled: true,
|
||||
email: 'owAwLISy'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
firstName: '84N1jji3',
|
||||
lastName: '748zEwJV',
|
||||
jobTitle: 'N/A',
|
||||
emailNotificationsEnabled: true,
|
||||
company: {},
|
||||
id: '0kd3jA3b',
|
||||
enabled: true,
|
||||
email: 'm1ooPRIu'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
firstName: 'cPuvOYnb',
|
||||
lastName: 'GZK6IenG',
|
||||
jobTitle: 'N/A',
|
||||
emailNotificationsEnabled: true,
|
||||
company: {},
|
||||
id: '1BJSWj5u',
|
||||
enabled: true,
|
||||
email: 'UtKzKjje'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
firstName: '87vRSHzf',
|
||||
lastName: 'OiLjkq9z',
|
||||
jobTitle: 'N/A',
|
||||
emailNotificationsEnabled: true,
|
||||
company: {},
|
||||
id: '1pvBqbmT',
|
||||
enabled: true,
|
||||
email: '72GemSCB'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
firstName: 'QTxD4AWn',
|
||||
lastName: 'IHb5JiaR',
|
||||
jobTitle: 'N/A',
|
||||
emailNotificationsEnabled: true,
|
||||
company: {},
|
||||
id: '2fOamhbL',
|
||||
enabled: true,
|
||||
email: 'hhhQHpmZ'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class RenditionMock extends BaseMock {
|
||||
get200RenditionResponse(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/97a29e9c-1e4f-4d9d-bb02-1ec920dda045/renditions/pdf')
|
||||
.reply(200, {
|
||||
entry: {
|
||||
id: 'pdf',
|
||||
content: { mimeType: 'application/pdf', mimeTypeName: 'Adobe PDF Document' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
createRendition200(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/97a29e9c-1e4f-4d9d-bb02-1ec920dda045/renditions', { id: 'pdf' })
|
||||
.reply(202, '');
|
||||
}
|
||||
|
||||
get200RenditionList(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/97a29e9c-1e4f-4d9d-bb02-1ec920dda045/renditions')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 6,
|
||||
hasMoreItems: false,
|
||||
totalItems: 6,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: 'avatar',
|
||||
content: { mimeType: 'image/png', mimeTypeName: 'PNG Image' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'avatar32',
|
||||
content: { mimeType: 'image/png', mimeTypeName: 'PNG Image' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'doclib',
|
||||
content: { mimeType: 'image/png', mimeTypeName: 'PNG Image' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'imgpreview',
|
||||
content: { mimeType: 'image/jpeg', mimeTypeName: 'JPEG Image' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'medium',
|
||||
content: { mimeType: 'image/jpeg', mimeTypeName: 'JPEG Image' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'pdf',
|
||||
content: { mimeType: 'application/pdf', mimeTypeName: 'Adobe PDF Document' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
53
lib/js-api/test/mockObjects/content-services/search.mock.ts
Normal file
53
lib/js-api/test/mockObjects/content-services/search.mock.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class SearchMock extends BaseMock {
|
||||
get200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/search/versions/1/search', {
|
||||
query: {
|
||||
query: 'select * from cmis:folder',
|
||||
language: 'cmis'
|
||||
}
|
||||
})
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: { count: 100, hasMoreItems: true, skipCount: 0, maxItems: 100 },
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
createdAt: '2017-04-10T10:52:30.868+0000',
|
||||
isFolder: true,
|
||||
search: { score: 1 },
|
||||
isFile: false,
|
||||
createdByUser: { id: 'admin', displayName: 'Administrator' },
|
||||
modifiedAt: '2017-04-10T10:52:30.868+0000',
|
||||
modifiedByUser: { id: 'admin', displayName: 'Administrator' },
|
||||
name: 'user',
|
||||
id: '224e30f4-a7b3-4192-b6e6-dc27d95e26ef',
|
||||
nodeType: 'cm:folder',
|
||||
parentId: '83551834-75d6-4e07-a318-46d5d176738a'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
99
lib/js-api/test/mockObjects/content-services/tag.mock.ts
Normal file
99
lib/js-api/test/mockObjects/content-services/tag.mock.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
import { TagBody, TagEntry, TagPaging } from '../../../src/api/content-rest-api';
|
||||
|
||||
export class TagMock extends BaseMock {
|
||||
get200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/tags')
|
||||
.reply(200, this.getPaginatedListOfTags());
|
||||
}
|
||||
|
||||
getTagsByNameFilteredByMatching200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/tags?where=(tag%20matches%20(%27*tag-test*%27))')
|
||||
.reply(200, this.getPaginatedListOfTags());
|
||||
}
|
||||
|
||||
getTagsByNamesFilterByExactTag200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/tags?where=(tag%3D%27tag-test-1%27)')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 1,
|
||||
hasMoreItems: false,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [this.mockTagEntry()]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get401Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/tags')
|
||||
.reply(401, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.ApiDefault',
|
||||
statusCode: 401,
|
||||
briefSummary: '05210059 Authentication failed for Web Script org/alfresco/api/ResourceWebScript.get',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
createTags201Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/tags')
|
||||
.reply(201, [this.mockTagEntry(), this.mockTagEntry('tag-test-2', 'd79bdbd0-9f55-45bb-9521-811e15bf48f6')]);
|
||||
}
|
||||
|
||||
get201ResponseForAssigningTagsToNode(body: TagBody[]): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/someNodeId/tags', JSON.stringify(body))
|
||||
.reply(201, body.length > 1 ? this.getPaginatedListOfTags() : this.mockTagEntry());
|
||||
}
|
||||
|
||||
private getPaginatedListOfTags(): TagPaging {
|
||||
return {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [this.mockTagEntry(), this.mockTagEntry('tag-test-2', 'd79bdbd0-9f55-45bb-9521-811e15bf48f6')]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private mockTagEntry(tag = 'tag-test-1', id = '0d89aa82-f2b8-4a37-9a54-f4c5148174d6'): TagEntry {
|
||||
return {
|
||||
entry: {
|
||||
tag,
|
||||
id
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
104
lib/js-api/test/mockObjects/content-services/upload.mock.ts
Normal file
104
lib/js-api/test/mockObjects/content-services/upload.mock.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class UploadMock extends BaseMock {
|
||||
get201CreationFile(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children')
|
||||
.reply(201, {
|
||||
entry: {
|
||||
isFile: true,
|
||||
createdByUser: { id: 'admin', displayName: 'Administrator' },
|
||||
modifiedAt: '2016-07-08T16:08:10.218+0000',
|
||||
nodeType: 'cm:content',
|
||||
content: {
|
||||
mimeType: 'text/plain',
|
||||
mimeTypeName: 'Plain Text',
|
||||
sizeInBytes: 28,
|
||||
encoding: 'ISO-8859-2'
|
||||
},
|
||||
parentId: '55290409-3c61-41e5-80f6-8354ed133ce0',
|
||||
aspectNames: ['cm:versionable', 'cm:titled', 'cm:auditable', 'cm:author'],
|
||||
createdAt: '2016-07-08T16:08:10.218+0000',
|
||||
isFolder: false,
|
||||
modifiedByUser: { id: 'admin', displayName: 'Administrator' },
|
||||
name: 'testFile.txt',
|
||||
id: '2857abfd-0ac6-459d-a22d-ec78770570f3',
|
||||
properties: { 'cm:versionLabel': '1.0', 'cm:versionType': 'MAJOR' }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get201CreationFileAutoRename(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children')
|
||||
.query({ autoRename: 'true' })
|
||||
.reply(201, {
|
||||
entry: {
|
||||
isFile: true,
|
||||
createdByUser: { id: 'admin', displayName: 'Administrator' },
|
||||
modifiedAt: '2016-07-08T17:04:34.684+0000',
|
||||
nodeType: 'cm:content',
|
||||
content: {
|
||||
mimeType: 'text/plain',
|
||||
mimeTypeName: 'Plain Text',
|
||||
sizeInBytes: 28,
|
||||
encoding: 'ISO-8859-2'
|
||||
},
|
||||
parentId: '55290409-3c61-41e5-80f6-8354ed133ce0',
|
||||
aspectNames: ['cm:versionable', 'cm:titled', 'cm:auditable', 'cm:author'],
|
||||
createdAt: '2016-07-08T17:04:34.684+0000',
|
||||
isFolder: false,
|
||||
modifiedByUser: { id: 'admin', displayName: 'Administrator' },
|
||||
name: 'testFile-2.txt',
|
||||
id: 'ae314293-27e8-4221-9a09-699f103db5f3',
|
||||
properties: { 'cm:versionLabel': '1.0', 'cm:versionType': 'MAJOR' }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get409CreationFileNewNameClashes(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children')
|
||||
.reply(409, {
|
||||
error: {
|
||||
errorKey: 'Duplicate child name not allowed: newFile',
|
||||
statusCode: 409,
|
||||
briefSummary: '06070090 Duplicate child name not allowed: newFile',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get401Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/-root-/children')
|
||||
.reply(401, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.ApiDefault',
|
||||
statusCode: 401,
|
||||
briefSummary: '05210059 Authentication failed for Web Script org/alfresco/api/ResourceWebScript.get',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
122
lib/js-api/test/mockObjects/content-services/version.mock.ts
Normal file
122
lib/js-api/test/mockObjects/content-services/version.mock.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class VersionMock extends BaseMock {
|
||||
post201Response(nodeId: string, versionId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeId + '/versions/' + versionId + '/revert')
|
||||
.reply(201, { entry: { id: '3.0' } });
|
||||
}
|
||||
|
||||
get200Response(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeId + '/versions')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [{ entry: { id: '2.0' } }, { entry: { id: '1.0' } }]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200ResponseVersionRenditions(nodeId: string, versionId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeId + '/versions/' + versionId + '/renditions')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 6,
|
||||
hasMoreItems: false,
|
||||
totalItems: 6,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: 'avatar',
|
||||
content: { mimeType: 'image/png', mimeTypeName: 'PNG Image' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'avatar32',
|
||||
content: { mimeType: 'image/png', mimeTypeName: 'PNG Image' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'doclib',
|
||||
content: { mimeType: 'image/png', mimeTypeName: 'PNG Image' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'imgpreview',
|
||||
content: { mimeType: 'image/jpeg', mimeTypeName: 'JPEG Image' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'medium',
|
||||
content: { mimeType: 'image/jpeg', mimeTypeName: 'JPEG Image' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'pdf',
|
||||
content: { mimeType: 'application/pdf', mimeTypeName: 'Adobe PDF Document' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200VersionRendition(nodeId: string, versionId: string, renditionId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeId + '/versions/' + versionId + '/renditions/' + renditionId)
|
||||
.reply(200, {
|
||||
entry: {
|
||||
id: 'pdf',
|
||||
content: { mimeType: 'application/pdf', mimeTypeName: 'Adobe PDF Document' },
|
||||
status: 'NOT_CREATED'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
create200VersionRendition(nodeId: string, versionId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/alfresco/versions/1/nodes/' + nodeId + '/versions/' + versionId + '/renditions', { id: 'pdf' })
|
||||
.reply(202, '');
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class WebScriptMock extends BaseMock {
|
||||
contextRoot: string;
|
||||
servicePath: string;
|
||||
scriptPath: string;
|
||||
scriptSlug: string;
|
||||
|
||||
constructor(host?: string, contextRoot?: string, servicePath?: string, scriptPath?: string) {
|
||||
super(host);
|
||||
this.contextRoot = contextRoot || 'alfresco';
|
||||
this.servicePath = servicePath || 'service';
|
||||
this.scriptPath = scriptPath;
|
||||
|
||||
this.scriptSlug = '/' + this.contextRoot + '/' + this.servicePath + '/' + this.scriptPath;
|
||||
}
|
||||
|
||||
get404Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get(this.scriptSlug)
|
||||
.reply(404, {
|
||||
error: {
|
||||
errorKey: 'Unable to locate resource resource for :alfresco ',
|
||||
statusCode: 404,
|
||||
briefSummary: '06130000 Unable to locate resource resource for :alfresco ',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get(this.scriptSlug)
|
||||
.reply(200, {
|
||||
randomStructure: {
|
||||
exampleInt: 1,
|
||||
exampleString: 'string test'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200ResponseHTMLFormat(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/service/sample/folder/Company%20Home')
|
||||
.reply(
|
||||
200,
|
||||
// eslint-disable-next-line max-len
|
||||
'<html>\n <head>\n <title>/Company Home</title>\n </head>\n <body>\n Folder: /Company Home\n <br>\n <table>\n <tr>\n <td>><td><a href="/alfresco/service/sample/folder/Company%20Home/Data%20Dictionary">Data Dictionary</a>\n </tr>\n <tr>\n <td>><td><a href="/alfresco/service/sample/folder/Company%20Home/Guest%20Home">Guest Home</a>\n </tr>\n <tr>\n <td>><td><a href="/alfresco/service/sample/folder/Company%20Home/User%20Homes">User Homes</a>\n </tr>\n <tr>\n <td>><td><a href="/alfresco/service/sample/folder/Company%20Home/Shared">Shared</a>\n </tr>\n <tr>\n <td>><td><a href="/alfresco/service/sample/folder/Company%20Home/Imap%20Attachments">Imap Attachments</a>\n </tr>\n <tr>\n <td>><td><a href="/alfresco/service/sample/folder/Company%20Home/IMAP%20Home">IMAP Home</a>\n </tr>\n <tr>\n <td>><td><a href="/alfresco/service/sample/folder/Company%20Home/Sites">Sites</a>\n </tr>\n <tr>\n <td>><td><a href="/alfresco/service/sample/folder/Company%20Home/x">x</a>\n </tr>\n <tr>\n <td><td><a href="/alfresco/service/api/node/content/workspace/SpacesStore/2857abfd-0ac6-459d-a22d-ec78770570f3/testFile.txt">testFile.txt</a>\n </tr>\n <tr>\n <td>><td><a href="/alfresco/service/sample/folder/Company%20Home/newFolder">newFolder</a>\n </tr>\n <tr>\n <td>><td><a href="/alfresco/service/sample/folder/Company%20Home/newFolder-1">newFolder-1</a>\n </tr>\n <tr>\n <td><td><a href="/alfresco/service/api/node/content/workspace/SpacesStore/21ce66a9-6bc5-4c49-8ad3-43d3b824a9a3/testFile-1.txt">testFile-1.txt</a>\n </tr>\n <tr>\n <td><td><a href="/alfresco/service/api/node/content/workspace/SpacesStore/ae314293-27e8-4221-9a09-699f103db5f3/testFile-2.txt">testFile-2.txt</a>\n </tr>\n <tr>\n <td><td><a href="/alfresco/service/api/node/content/workspace/SpacesStore/935c1a72-647f-4c8f-aab6-e3b161978427/testFile-3.txt">testFile-3.txt</a>\n </tr>\n </table>\n </body>\n</html>\n\n'
|
||||
); // jshint ignore:line
|
||||
}
|
||||
|
||||
get401Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get(this.scriptSlug)
|
||||
.reply(401, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.ApiDefault',
|
||||
statusCode: 401,
|
||||
briefSummary: '05210059 Authentication failed for Web Script org/alfresco/api/ResourceWebScript.get',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { BaseMock } from '../base.mock';
|
||||
import nock from 'nock';
|
||||
|
||||
export class AuthorityClearanceMock extends BaseMock {
|
||||
get200AuthorityClearanceForAuthority(authorityId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/gs/versions/1/cleared-authorities/' + authorityId + '/clearing-marks?skipCount=0&maxItems=100')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: 'securityGroupFruits',
|
||||
displayLabel: 'Security Group FRUITS',
|
||||
systemGroup: false,
|
||||
type: 'USER_REQUIRES_ALL',
|
||||
marks: [
|
||||
{
|
||||
id: 'fruitMarkId1',
|
||||
displayLabel: 'APPLES',
|
||||
applied: true,
|
||||
inherited: false
|
||||
},
|
||||
{
|
||||
id: 'fruitMarkId2',
|
||||
displayLabel: 'BANANAS',
|
||||
applied: false,
|
||||
inherited: false
|
||||
},
|
||||
{
|
||||
id: 'fruitMarkId3',
|
||||
displayLabel: 'MANGOES',
|
||||
applied: false,
|
||||
inherited: true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'securityGroupAnimals',
|
||||
displayLabel: 'Security Group ANIMALS',
|
||||
systemGroup: false,
|
||||
type: 'USER_REQUIRES_ANY',
|
||||
marks: [
|
||||
{
|
||||
id: 'animalMarkId1',
|
||||
displayLabel: 'LION',
|
||||
applied: true,
|
||||
inherited: false
|
||||
},
|
||||
{
|
||||
id: 'animalMarkId1',
|
||||
displayLabel: 'TIGER',
|
||||
applied: true,
|
||||
inherited: false
|
||||
},
|
||||
{
|
||||
id: 'animalMarkId1',
|
||||
displayLabel: 'ZEBRA',
|
||||
applied: true,
|
||||
inherited: false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
post200AuthorityClearanceWithSingleItem(authorityId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/gs/versions/1/cleared-authorities/' + authorityId + '/clearing-marks')
|
||||
.reply(200, {
|
||||
entry: {
|
||||
id: 'fruitMarkId1',
|
||||
name: 'APPLES',
|
||||
groupId: 'securityGroupFruits'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
post200AuthorityClearanceWithList(authorityId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/gs/versions/1/cleared-authorities/' + authorityId + '/clearing-marks')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
id: 'fruitMarkId1',
|
||||
name: 'APPLES',
|
||||
groupId: 'securityGroupFruits'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
id: 'fruitMarkId2',
|
||||
name: 'BANANAS',
|
||||
groupId: 'securityGroupFruits'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class GsSitesApiMock extends BaseMock {
|
||||
get200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/gs/versions/1/gs-sites/rm')
|
||||
.reply(200, {
|
||||
entry: {
|
||||
role: 'SiteManager',
|
||||
visibility: 'PUBLIC',
|
||||
compliance: 'STANDARD',
|
||||
guid: 'fd870d47-57a0-46f7-83c8-c523a4da13c4',
|
||||
description: 'Records Management Description Test',
|
||||
id: 'rm',
|
||||
title: 'Records Management'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class NodeSecurityMarksApiMock extends BaseMock {
|
||||
post200manageSecurityMarkOnNode(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/gs/versions/1/secured-nodes/' + nodeId + '/securing-marks')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
groupId: 'securityGroupId1',
|
||||
name: 'SecurityMarkTest1',
|
||||
id: 'Sh1G8vTQ'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
groupId: 'securityGroupId2',
|
||||
name: 'SecurityMarkTest2',
|
||||
id: 'Sh1G8vTR'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get200SecurityMarkOnNode(nodeId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/gs/versions/1/secured-nodes/' + nodeId + '/securing-marks')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
groupId: 'securityGroupId1',
|
||||
name: 'SecurityMarkTest1',
|
||||
id: 'Sh1G8vTQ'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
groupId: 'securityGroupId2',
|
||||
name: 'SecurityMarkTest2',
|
||||
id: 'Sh1G8vTR'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class SecurityGroupApiMock extends BaseMock {
|
||||
createSecurityGroup200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/gs/versions/1/security-groups')
|
||||
.reply(200, {
|
||||
entry: {
|
||||
groupName: 'Alfresco',
|
||||
groupType: 'HIERARCHICAL',
|
||||
id: 'a0a7b107-84ba-4c3d-b0b7-a8509e8c1c33'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getSecurityGroups200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/gs/versions/1/security-groups')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
groupName: 'Alfresco',
|
||||
groupType: 'HIERARCHICAL',
|
||||
id: 'a0a7b107-84ba-4c3d-b0b7-a8509e8c1c33'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
groupName: 'Classification',
|
||||
groupType: 'HIERARCHICAL',
|
||||
id: 'classification'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getSecurityGroupInfo200Response(securityGroupId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId)
|
||||
.reply(200, {
|
||||
entry: {
|
||||
groupName: 'Alfresco',
|
||||
groupType: 'HIERARCHICAL',
|
||||
id: 'a0a7b107-84ba-4c3d-b0b7-a8509e8c1c33'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateSecurityGroup200Response(securityGroupId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId)
|
||||
.reply(200, {
|
||||
entry: {
|
||||
groupName: 'Nasa',
|
||||
groupType: 'HIERARCHICAL',
|
||||
id: 'a0a7b107-84ba-4c3d-b0b7-a8509e8c1c33'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteSecurityGroup200Response(securityGroupId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete('/alfresco/api/-default-/public/alfresco/versions/1/security-groups/' + securityGroupId)
|
||||
.reply(200);
|
||||
}
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class SecurityMarkApiMock extends BaseMock {
|
||||
get200GetSecurityMark(securityGroupId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 1,
|
||||
hasMoreItems: false,
|
||||
totalItems: 1,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
groupId: securityGroupId,
|
||||
name: 'SecurityMarkTest',
|
||||
id: 'Sh1G8vTQ'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
createSecurityMark200Response(securityGroupId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks')
|
||||
.reply(200, {
|
||||
entry: {
|
||||
groupId: securityGroupId,
|
||||
name: 'SecurityMarkTest',
|
||||
id: 'Sh1G8vTQ'
|
||||
}
|
||||
});
|
||||
}
|
||||
createSecurityMarks200Response(securityGroupId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks')
|
||||
.reply(200, {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 2,
|
||||
hasMoreItems: false,
|
||||
totalItems: 2,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [
|
||||
{
|
||||
entry: {
|
||||
groupId: securityGroupId,
|
||||
name: 'SecurityMark3',
|
||||
id: 'KsnOlXVM'
|
||||
}
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
groupId: securityGroupId,
|
||||
name: 'SecurityMark4',
|
||||
id: 'wFYkG8CV'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
get200GetSingleSecurityMark(securityGroupId: string, securityMarkId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks/' + securityMarkId)
|
||||
.reply(200, {
|
||||
entry: {
|
||||
groupId: securityGroupId,
|
||||
name: 'SecurityMarkTest',
|
||||
id: securityMarkId
|
||||
}
|
||||
});
|
||||
}
|
||||
put200UpdateSecurityMarkResponse(securityGroupId: string, securityMarkId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks/' + securityMarkId)
|
||||
.reply(200, {
|
||||
entry: {
|
||||
groupId: securityGroupId,
|
||||
name: 'AlfrescoSecurityMark',
|
||||
id: securityMarkId
|
||||
}
|
||||
});
|
||||
}
|
||||
getDeleteSecurityMarkSuccessfulResponse(securityGroupId: string, securityMarkId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete('/alfresco/api/-default-/public/gs/versions/1/security-groups/' + securityGroupId + '/security-marks/' + securityMarkId)
|
||||
.reply(200);
|
||||
}
|
||||
get401Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/alfresco/api/-default-/public/gs/versions/1/security-groups/')
|
||||
.reply(401, {
|
||||
error: {
|
||||
errorKey: 'framework.exception.ApiDefault',
|
||||
statusCode: 401,
|
||||
briefSummary: '05210059 Authentication failed for Web Script org/alfresco/api/ResourceWebScript.get',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
51
lib/js-api/test/mockObjects/index.ts
Normal file
51
lib/js-api/test/mockObjects/index.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './content-services/categories.mock';
|
||||
export * from './content-services/comment.mock';
|
||||
export * from './content-services/ecm-auth.mock';
|
||||
export * from './content-services/custom-model.mock';
|
||||
export * from './content-services/discovery.mock';
|
||||
export * from './content-services/node.mock';
|
||||
export * from './content-services/people.mock';
|
||||
export * from './content-services/groups.mock';
|
||||
export * from './content-services/find-nodes.mock';
|
||||
export * from './content-services/rendition.mock';
|
||||
export * from './content-services/search.mock';
|
||||
export * from './content-services/tag.mock';
|
||||
export * from './content-services/upload.mock';
|
||||
export * from './content-services/version.mock';
|
||||
export * from './content-services/webscript.mock';
|
||||
|
||||
export * from './goverance-services/authority-clearance.mock';
|
||||
export * from './goverance-services/gs-sites.mock';
|
||||
export * from './goverance-services/node-security-marks.mock';
|
||||
export * from './goverance-services/security-groups.mock';
|
||||
export * from './goverance-services/security-marks.mock';
|
||||
|
||||
export * from './process-services/bpm-auth.mock';
|
||||
export * from './process-services/process.mock';
|
||||
export * from './process-services/process-instance-variables.mock';
|
||||
export * from './process-services/models.mock';
|
||||
export * from './process-services/model-json.mock';
|
||||
export * from './process-services/profile.mock';
|
||||
export * from './process-services/reports.mock';
|
||||
export * from './process-services/task-form.mock';
|
||||
export * from './process-services/tasks.mock';
|
||||
export * from './process-services/user-filters.mock';
|
||||
|
||||
export * from './oauth2/oauth.mock';
|
46
lib/js-api/test/mockObjects/oauth2/oauth.mock.ts
Normal file
46
lib/js-api/test/mockObjects/oauth2/oauth.mock.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class OAuthMock extends BaseMock {
|
||||
username: string;
|
||||
password: string;
|
||||
|
||||
constructor(host?: string, username?: string, password?: string) {
|
||||
super(host);
|
||||
this.username = username || 'admin';
|
||||
this.password = password || 'admin';
|
||||
}
|
||||
|
||||
get200Response(mockToken?: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/auth/realms/springboot/protocol/openid-connect/token')
|
||||
.reply(200, {
|
||||
access_token: mockToken || 'test-token',
|
||||
expires_in: 300,
|
||||
refresh_expires_in: 1800,
|
||||
refresh_token:
|
||||
// eslint-disable-next-line max-len
|
||||
'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI0cHczOUltNE54dXZEN0ZqZ3JOQ3Q2ZkpaVDctQ3JWTzRkX3BLaXJlSTF3In0.eyJqdGkiOiI2MzQxMDc1ZC1lOTY4LTRmZTctOTkwZS05MTQ3NTUwOGEzZWIiLCJleHAiOjE1Mjk2MDkxMDYsIm5iZiI6MCwiaWF0IjoxNTI5NjA3MzA2LCJpc3MiOiJodHRwOi8vYTVlMmY5M2RlMTBhZjExZThhMDU2MGExYmVhNWI3YzgtMjM2NzA5NDMzLnVzLWVhc3QtMS5lbGIuYW1hem9uYXdzLmNvbTozMDA4MS9hdXRoL3JlYWxtcy9zcHJpbmdib290IiwiYXVkIjoiYWN0aXZpdGkiLCJzdWIiOiJlMjRjZjM0Mi1mYzUwLTRjYjEtYTBjMC01N2RhZWRiODI3NDkiLCJ0eXAiOiJSZWZyZXNoIiwiYXpwIjoiYWN0aXZpdGkiLCJhdXRoX3RpbWUiOjAsInNlc3Npb25fc3RhdGUiOiI5NDMzZTIwNi1kZjFhLTQ2YTMtYmU3ZS02NWIwNDVhMWMzNmIiLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsiYWRtaW4iLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7InJlYWxtLW1hbmFnZW1lbnQiOnsicm9sZXMiOlsidmlldy1pZGVudGl0eS1wcm92aWRlcnMiLCJ2aWV3LXJlYWxtIiwibWFuYWdlLWlkZW50aXR5LXByb3ZpZGVycyIsImltcGVyc29uYXRpb24iLCJyZWFsbS1hZG1pbiIsImNyZWF0ZS1jbGllbnQiLCJtYW5hZ2UtdXNlcnMiLCJxdWVyeS1yZWFsbXMiLCJ2aWV3LWF1dGhvcml6YXRpb24iLCJxdWVyeS1jbGllbnRzIiwicXVlcnktdXNlcnMiLCJtYW5hZ2UtZXZlbnRzIiwibWFuYWdlLXJlYWxtIiwidmlldy1ldmVudHMiLCJ2aWV3LXVzZXJzIiwidmlldy1jbGllbnRzIiwibWFuYWdlLWF1dGhvcml6YXRpb24iLCJtYW5hZ2UtY2xpZW50cyIsInF1ZXJ5LWdyb3VwcyJdfSwiYnJva2VyIjp7InJvbGVzIjpbInJlYWQtdG9rZW4iXX0sImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX19.mQ4Vi1yLG9KvcmmhHlgOowy8D30iaUsiO7--JTPY7Ol-R1eY4wvRn1cH5FllieXk8yltYGP23xXNtTC4M54guXGVtgRgo8AlRklFHL1BMlxpa0OPwcNmwthx1-P2n7c9XL1e8pt2uRhQJLxunr2TpLaQi0UpEmEyouXHfR7sxM1AzKAf3b9Nk7f7lrk__2BYlFsL3YcGlFDqDMgPfhNlDbR-rQGoxlOjt0YqS8ktYq4bneL5etpXnPh0oEt4B7FFK-WKKuOWR6rQ9791ACnn6puz6C_Ki261IkZ0a_Uu7tOA4Xi9xzoQKLgSTAlBeg4u86Wb5kjL5r2-3zTg-Dikew',
|
||||
token_type: 'bearer',
|
||||
'not-before-policy': 0,
|
||||
session_state: '9433e206-df1a-46a3-be7e-65b045a1c36b'
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class BpmAuthMock extends BaseMock {
|
||||
username: string;
|
||||
password: string;
|
||||
|
||||
constructor(host?: string, username?: string, password?: string) {
|
||||
super(host);
|
||||
this.username = username || 'admin';
|
||||
this.password = password || 'admin';
|
||||
}
|
||||
|
||||
get200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post(
|
||||
'/activiti-app/app/authentication',
|
||||
'j_username=' + this.username + '&j_password=' + this.password + '&_spring_security_remember_me=true&submit=Login'
|
||||
)
|
||||
.reply(200);
|
||||
}
|
||||
|
||||
get200ResponseLogout(): void {
|
||||
nock(this.host, { encodedQueryParams: true }).get('/activiti-app/app/logout', {}).reply(200);
|
||||
}
|
||||
|
||||
get401Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/activiti-app/app/authentication', 'j_username=wrong&j_password=name&_spring_security_remember_me=true&submit=Login')
|
||||
.reply(401, {
|
||||
error: {
|
||||
message: 'This request requires HTTP authentication.',
|
||||
statusCode: 401
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get403Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/activiti-app/app/authentication', 'j_username=wrong&j_password=name&_spring_security_remember_me=true&submit=Login')
|
||||
.reply(403, {
|
||||
error: {
|
||||
errorKey: 'Login failed',
|
||||
statusCode: 403,
|
||||
briefSummary: '05150009 Login failed',
|
||||
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
155
lib/js-api/test/mockObjects/process-services/model-json.mock.ts
Normal file
155
lib/js-api/test/mockObjects/process-services/model-json.mock.ts
Normal file
@@ -0,0 +1,155 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class ModelJsonBpmMock extends BaseMock {
|
||||
get200EditorDisplayJsonClient(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/app/rest/models/1/model-json')
|
||||
.reply(200, {
|
||||
elements: [
|
||||
{
|
||||
id: 'startEvent1',
|
||||
name: null,
|
||||
x: 100,
|
||||
y: 163,
|
||||
width: 30,
|
||||
height: 30,
|
||||
type: 'StartEvent',
|
||||
properties: []
|
||||
},
|
||||
{
|
||||
id: 'sid-8B04E151-6B46-4F48-B49E-F719057353AD',
|
||||
name: null,
|
||||
x: 175,
|
||||
y: 138,
|
||||
width: 100,
|
||||
height: 80,
|
||||
type: 'UserTask',
|
||||
properties: [{ name: 'Assignee', value: '$INITIATOR' }]
|
||||
},
|
||||
{
|
||||
id: 'sid-8F6A225D-91AC-4FE3-8DDF-7DF034A37C44',
|
||||
name: null,
|
||||
x: 320,
|
||||
y: 164,
|
||||
width: 28,
|
||||
height: 28,
|
||||
type: 'EndEvent',
|
||||
properties: []
|
||||
}
|
||||
],
|
||||
flows: [
|
||||
{
|
||||
id: 'sid-BC321EAF-BF83-4343-91C4-C0E7C4E10133',
|
||||
type: 'sequenceFlow',
|
||||
sourceRef: 'startEvent1',
|
||||
targetRef: 'sid-8B04E151-6B46-4F48-B49E-F719057353AD',
|
||||
waypoints: [
|
||||
{ x: 130, y: 178 },
|
||||
{ x: 175, y: 178 }
|
||||
],
|
||||
properties: []
|
||||
},
|
||||
{
|
||||
id: 'sid-CA38A1B7-1BFC-44C1-B20D-86748AE7AAA0',
|
||||
type: 'sequenceFlow',
|
||||
sourceRef: 'sid-8B04E151-6B46-4F48-B49E-F719057353AD',
|
||||
targetRef: 'sid-8F6A225D-91AC-4FE3-8DDF-7DF034A37C44',
|
||||
waypoints: [
|
||||
{ x: 275, y: 178 },
|
||||
{ x: 320, y: 178 }
|
||||
],
|
||||
properties: []
|
||||
}
|
||||
],
|
||||
diagramBeginX: 115,
|
||||
diagramBeginY: 138,
|
||||
diagramWidth: 348,
|
||||
diagramHeight: 218
|
||||
});
|
||||
}
|
||||
|
||||
get200HistoricEditorDisplayJsonClient(): void {
|
||||
nock('https://127.0.0.1:9999', { encodedQueryParams: true })
|
||||
.get('/activiti-app/app/rest/models/1/history/1/model-json')
|
||||
.reply(200, {
|
||||
elements: [
|
||||
{
|
||||
id: 'startEvent1',
|
||||
name: null,
|
||||
x: 100,
|
||||
y: 163,
|
||||
width: 30,
|
||||
height: 30,
|
||||
type: 'StartEvent',
|
||||
properties: []
|
||||
},
|
||||
{
|
||||
id: 'sid-8B04E151-6B46-4F48-B49E-F719057353AD',
|
||||
name: null,
|
||||
x: 175,
|
||||
y: 138,
|
||||
width: 100,
|
||||
height: 80,
|
||||
type: 'UserTask',
|
||||
properties: [{ name: 'Assignee', value: '$INITIATOR' }]
|
||||
},
|
||||
{
|
||||
id: 'sid-8F6A225D-91AC-4FE3-8DDF-7DF034A37C44',
|
||||
name: null,
|
||||
x: 320,
|
||||
y: 164,
|
||||
width: 28,
|
||||
height: 28,
|
||||
type: 'EndEvent',
|
||||
properties: []
|
||||
}
|
||||
],
|
||||
flows: [
|
||||
{
|
||||
id: 'sid-BC321EAF-BF83-4343-91C4-C0E7C4E10133',
|
||||
type: 'sequenceFlow',
|
||||
sourceRef: 'startEvent1',
|
||||
targetRef: 'sid-8B04E151-6B46-4F48-B49E-F719057353AD',
|
||||
waypoints: [
|
||||
{ x: 130, y: 178 },
|
||||
{ x: 175, y: 178 }
|
||||
],
|
||||
properties: []
|
||||
},
|
||||
{
|
||||
id: 'sid-CA38A1B7-1BFC-44C1-B20D-86748AE7AAA0',
|
||||
type: 'sequenceFlow',
|
||||
sourceRef: 'sid-8B04E151-6B46-4F48-B49E-F719057353AD',
|
||||
targetRef: 'sid-8F6A225D-91AC-4FE3-8DDF-7DF034A37C44',
|
||||
waypoints: [
|
||||
{ x: 275, y: 178 },
|
||||
{ x: 320, y: 178 }
|
||||
],
|
||||
properties: []
|
||||
}
|
||||
],
|
||||
diagramBeginX: 115,
|
||||
diagramBeginY: 138,
|
||||
diagramWidth: 348,
|
||||
diagramHeight: 218
|
||||
});
|
||||
}
|
||||
}
|
53
lib/js-api/test/mockObjects/process-services/models.mock.ts
Normal file
53
lib/js-api/test/mockObjects/process-services/models.mock.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class ModelsMock extends BaseMock {
|
||||
get200getModels(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/api/enterprise/models')
|
||||
.query({ filter: 'myReusableForms', modelType: '2' })
|
||||
.reply(200, {
|
||||
size: 1,
|
||||
total: 1,
|
||||
start: 0,
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Metadata',
|
||||
description: '',
|
||||
createdBy: 1,
|
||||
createdByFullName: ' Administrator',
|
||||
lastUpdatedBy: 1,
|
||||
lastUpdatedByFullName: ' Administrator',
|
||||
lastUpdated: '2016-08-05T17:39:22.750+0000',
|
||||
latestVersion: true,
|
||||
version: 2,
|
||||
comment: null,
|
||||
stencilSet: null,
|
||||
referenceId: null,
|
||||
modelType: 2,
|
||||
favorite: null,
|
||||
permission: 'write',
|
||||
tenantId: 1
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
const fakeVariable1 = {
|
||||
name: 'variable1',
|
||||
value: 'Value 123',
|
||||
scope: 'global'
|
||||
};
|
||||
|
||||
const fakeVariable2 = {
|
||||
name: 'variable2',
|
||||
value: 'Value 456',
|
||||
scope: 'local'
|
||||
};
|
||||
|
||||
const fakeVariablesList = [fakeVariable1, fakeVariable2];
|
||||
|
||||
export class ProcessInstanceVariablesMock extends BaseMock {
|
||||
addListProcessInstanceVariables200Response(processInstanceId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables')
|
||||
.reply(200, fakeVariablesList);
|
||||
}
|
||||
|
||||
addListProcessInstanceVariables500Response(processInstanceId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables')
|
||||
.reply(500, {
|
||||
messageKey: 'UNKNOWN',
|
||||
message: 'Unknown error'
|
||||
});
|
||||
}
|
||||
|
||||
addPutProcessInstanceVariables200Response(processInstanceId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables')
|
||||
.reply(200, fakeVariablesList);
|
||||
}
|
||||
|
||||
addPutProcessInstanceVariables500Response(processInstanceId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables')
|
||||
.reply(500, {
|
||||
messageKey: 'UNKNOWN',
|
||||
message: 'Unknown error'
|
||||
});
|
||||
}
|
||||
|
||||
addGetProcessInstanceVariable200Response(processInstanceId: string, variableName: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
|
||||
.reply(200, fakeVariable1);
|
||||
}
|
||||
|
||||
addGetProcessInstanceVariable500Response(processInstanceId: string, variableName: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
|
||||
.reply(500, {
|
||||
messageKey: 'UNKNOWN',
|
||||
message: 'Unknown error'
|
||||
});
|
||||
}
|
||||
|
||||
addUpdateProcessInstanceVariable200Response(processInstanceId: string, variableName: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
|
||||
.reply(200, fakeVariable1);
|
||||
}
|
||||
|
||||
addUpdateProcessInstanceVariable500Response(processInstanceId: string, variableName: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
|
||||
.reply(500, {
|
||||
messageKey: 'UNKNOWN',
|
||||
message: 'Unknown error'
|
||||
});
|
||||
}
|
||||
|
||||
addDeleteProcessInstanceVariable200Response(processInstanceId: string, variableName: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
|
||||
.reply(200);
|
||||
}
|
||||
|
||||
addDeleteProcessInstanceVariable500Response(processInstanceId: string, variableName: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
|
||||
.reply(500, {
|
||||
messageKey: 'UNKNOWN',
|
||||
message: 'Unknown error'
|
||||
});
|
||||
}
|
||||
}
|
160
lib/js-api/test/mockObjects/process-services/process.mock.ts
Normal file
160
lib/js-api/test/mockObjects/process-services/process.mock.ts
Normal file
@@ -0,0 +1,160 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class ProcessMock extends BaseMock {
|
||||
get200Response(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/activiti-app/api/enterprise/process-instances/query')
|
||||
.reply(200, {
|
||||
size: 2,
|
||||
total: 2,
|
||||
start: 0,
|
||||
data: [
|
||||
{
|
||||
id: '39',
|
||||
name: 'Process Test Api - July 26th 2016',
|
||||
businessKey: null,
|
||||
processDefinitionId: 'ProcessTestApi:1:32',
|
||||
tenantId: 'tenant_1',
|
||||
started: '2016-07-26T15:31:00.414+0000',
|
||||
ended: null,
|
||||
startedBy: {
|
||||
id: 1,
|
||||
firstName: null,
|
||||
lastName: 'Administrator',
|
||||
email: 'admin@app.activiti.com'
|
||||
},
|
||||
processDefinitionName: 'Process Test Api',
|
||||
processDefinitionDescription: null,
|
||||
processDefinitionKey: 'ProcessTestApi',
|
||||
processDefinitionCategory: 'https://www.activiti.org/processdef',
|
||||
processDefinitionVersion: 1,
|
||||
processDefinitionDeploymentId: '29',
|
||||
graphicalNotationDefined: true,
|
||||
startFormDefined: false,
|
||||
suspended: false,
|
||||
variables: []
|
||||
},
|
||||
{
|
||||
id: '33',
|
||||
name: 'Process Test Api - July 26th 2016',
|
||||
businessKey: null,
|
||||
processDefinitionId: 'ProcessTestApi:1:32',
|
||||
tenantId: 'tenant_1',
|
||||
started: '2016-07-26T15:30:58.367+0000',
|
||||
ended: null,
|
||||
startedBy: {
|
||||
id: 1,
|
||||
firstName: null,
|
||||
lastName: 'Administrator',
|
||||
email: 'admin@app.activiti.com'
|
||||
},
|
||||
processDefinitionName: 'Process Test Api',
|
||||
processDefinitionDescription: null,
|
||||
processDefinitionKey: 'ProcessTestApi',
|
||||
processDefinitionCategory: 'https://www.activiti.org/processdef',
|
||||
processDefinitionVersion: 1,
|
||||
processDefinitionDeploymentId: '29',
|
||||
graphicalNotationDefined: true,
|
||||
startFormDefined: false,
|
||||
suspended: false,
|
||||
variables: []
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
get200getProcessDefinitionStartForm(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/api/enterprise/process-definitions/testProcess%3A1%3A7504/start-form')
|
||||
.reply(200, {
|
||||
id: 2002,
|
||||
processDefinitionId: 'testProcess:1:7504',
|
||||
processDefinitionName: 'test process',
|
||||
processDefinitionKey: 'testProcess',
|
||||
tabs: [],
|
||||
fields: [
|
||||
{
|
||||
fieldType: 'DynamicTableRepresentation',
|
||||
id: 'label',
|
||||
name: 'Label',
|
||||
type: 'dynamic-table',
|
||||
value: null,
|
||||
required: false,
|
||||
readOnly: false,
|
||||
overrideId: false,
|
||||
colspan: 1,
|
||||
placeholder: null,
|
||||
minLength: 0,
|
||||
maxLength: 0,
|
||||
minValue: null,
|
||||
maxValue: null,
|
||||
regexPattern: null,
|
||||
optionType: null,
|
||||
hasEmptyValue: null,
|
||||
options: null,
|
||||
restUrl: null,
|
||||
restResponsePath: null,
|
||||
restIdProperty: null,
|
||||
restLabelProperty: null,
|
||||
tab: null,
|
||||
className: null,
|
||||
params: { existingColspan: 1, maxColspan: 1 },
|
||||
layout: { row: -1, column: -1, colspan: 2 },
|
||||
sizeX: 2,
|
||||
sizeY: 2,
|
||||
row: -1,
|
||||
col: -1,
|
||||
visibilityCondition: null,
|
||||
columnDefinitions: [
|
||||
{
|
||||
id: 'user',
|
||||
name: 'User',
|
||||
type: 'Dropdown',
|
||||
value: null,
|
||||
optionType: 'rest',
|
||||
options: [{ id: null, name: 'Option 1' }],
|
||||
restResponsePath: null,
|
||||
restUrl: 'https://jsonplaceholder.typicode.com/users',
|
||||
restIdProperty: 'id',
|
||||
restLabelProperty: 'name',
|
||||
amountCurrency: null,
|
||||
amountEnableFractions: false,
|
||||
required: true,
|
||||
editable: true,
|
||||
sortable: true,
|
||||
visible: true,
|
||||
endpoint: null,
|
||||
requestHeaders: null
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
outcomes: [],
|
||||
javascriptEvents: [],
|
||||
className: '',
|
||||
style: '',
|
||||
customFieldTemplates: {},
|
||||
metadata: {},
|
||||
variables: [],
|
||||
gridsterForm: false
|
||||
});
|
||||
}
|
||||
}
|
103
lib/js-api/test/mockObjects/process-services/profile.mock.ts
Normal file
103
lib/js-api/test/mockObjects/process-services/profile.mock.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class ProfileMock extends BaseMock {
|
||||
get200getProfile(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/api/enterprise/profile')
|
||||
.reply(200, {
|
||||
id: 1,
|
||||
firstName: null,
|
||||
lastName: 'Administrator',
|
||||
email: 'admin',
|
||||
externalId: null,
|
||||
company: null,
|
||||
pictureId: null,
|
||||
fullname: ' Administrator',
|
||||
password: null,
|
||||
type: 'enterprise',
|
||||
status: 'active',
|
||||
created: '2016-10-21T13:32:54.886+0000',
|
||||
lastUpdate: '2016-10-23T22:16:48.252+0000',
|
||||
tenantId: 1,
|
||||
latestSyncTimeStamp: null,
|
||||
groups: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'analytics-users',
|
||||
externalId: null,
|
||||
status: 'active',
|
||||
tenantId: 1,
|
||||
type: 0,
|
||||
parentGroupId: null,
|
||||
lastSyncTimeStamp: null,
|
||||
userCount: null,
|
||||
users: null,
|
||||
capabilities: null,
|
||||
groups: null,
|
||||
manager: null
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'kickstart-users',
|
||||
externalId: null,
|
||||
status: 'active',
|
||||
tenantId: 1,
|
||||
type: 0,
|
||||
parentGroupId: null,
|
||||
lastSyncTimeStamp: null,
|
||||
userCount: null,
|
||||
users: null,
|
||||
capabilities: null,
|
||||
groups: null,
|
||||
manager: null
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Superusers',
|
||||
externalId: null,
|
||||
status: 'active',
|
||||
tenantId: 1,
|
||||
type: 0,
|
||||
parentGroupId: null,
|
||||
lastSyncTimeStamp: null,
|
||||
userCount: null,
|
||||
users: null,
|
||||
capabilities: null,
|
||||
groups: null,
|
||||
manager: null
|
||||
}
|
||||
],
|
||||
capabilities: null,
|
||||
apps: [],
|
||||
primaryGroup: null,
|
||||
tenantPictureId: null,
|
||||
tenantName: 'test'
|
||||
});
|
||||
}
|
||||
|
||||
get401getProfile(): void {
|
||||
nock(this.host, { encodedQueryParams: true }).get('/activiti-app/api/enterprise/profile').reply(401);
|
||||
}
|
||||
|
||||
get200getProfilePicture(): void {
|
||||
nock(this.host, { encodedQueryParams: true }).get('/activiti-app/api/enterprise/profile-picture').reply(200, 'BUFFERSIZE');
|
||||
}
|
||||
}
|
212
lib/js-api/test/mockObjects/process-services/reports.mock.ts
Normal file
212
lib/js-api/test/mockObjects/process-services/reports.mock.ts
Normal file
@@ -0,0 +1,212 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
const fakeReportList = [
|
||||
{ id: 11011, name: 'Process definition heat map' },
|
||||
{ id: 11012, name: 'Process definition overview' },
|
||||
{ id: 11013, name: 'Process instances overview' },
|
||||
{ id: 11014, name: 'Task overview' },
|
||||
{ id: 11015, name: 'Task service level agreement' }
|
||||
];
|
||||
|
||||
const fakeReportParams = {
|
||||
id: 11013,
|
||||
name: 'Process instances overview',
|
||||
created: '2016-12-07T13:26:40.095+0000',
|
||||
definition:
|
||||
'{"parameters":[{"id":"processDefinitionId","name":null,"nameKey":"REPORTING.DEFAULT-REPORTS.PROCESS-INSTANCES-OVERVIEW.PROCESS-DEFINITION","type":"processDefinition","value":null,"dependsOn":null},' +
|
||||
'{"id":"dateRange","name":null,"nameKey":"REPORTING.DEFAULT-REPORTS.PROCESS-INSTANCES-OVERVIEW.DATE-RANGE","type":"dateRange","value":null,"dependsOn":null},' +
|
||||
'{"id":"slowProcessInstanceInteger","name":null,"nameKey":"REPORTING.DEFAULT-REPORTS.PROCESS-INSTANCES-OVERVIEW.SLOW-PROC-INST-NUMBER","type":"integer","value":10,"dependsOn":null},' +
|
||||
'{"id":"status","name":null,"nameKey":"REPORTING.PROCESS-STATUS","type":"status","value":null,"dependsOn":null}' +
|
||||
']}'
|
||||
};
|
||||
|
||||
const fakeChartReports = {
|
||||
elements: [
|
||||
{
|
||||
id: 'id10889073739455',
|
||||
type: 'table',
|
||||
rows: [
|
||||
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-DEFINITIONS', '10'],
|
||||
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-TOTAL-PROCESS-INSTANCES', '63'],
|
||||
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-ACTIVE-PROCESS-INSTANCES', '5'],
|
||||
['__KEY_REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.GENERAL-TABLE-COMPLETED-PROCESS-INSTANCES', '52']
|
||||
],
|
||||
collapseable: false,
|
||||
collapsed: false,
|
||||
showRowIndex: false
|
||||
},
|
||||
{
|
||||
id: 'id10889073934509',
|
||||
type: 'pieChart',
|
||||
title: 'Total process instances overview',
|
||||
titleKey: 'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.PROC-INST-CHART-TITLE',
|
||||
values: [
|
||||
{ key: 'Activiti', y: 13, keyAndValue: ['Activiti', '13'] },
|
||||
{
|
||||
key: 'Second Process',
|
||||
y: 5,
|
||||
keyAndValue: ['Second Process', '5']
|
||||
},
|
||||
{ key: 'Process Custom Name', y: 3, keyAndValue: ['Process Custom Name', '3'] },
|
||||
{
|
||||
key: 'Simple process',
|
||||
y: 29,
|
||||
keyAndValue: ['Simple process', '29']
|
||||
},
|
||||
{ key: 'Third Process', y: 7, keyAndValue: ['Third Process', '7'] }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'id10889074082883',
|
||||
type: 'table',
|
||||
title: 'Process definition details',
|
||||
titleKey: 'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE',
|
||||
columnNames: ['Process definition', 'Total', 'Active', 'Completed'],
|
||||
columnNameKeys: [
|
||||
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-PROCESS',
|
||||
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-TOTAL',
|
||||
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-ACTIVE',
|
||||
'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE-COMPLETED'
|
||||
],
|
||||
columnsCentered: [false, false, false, false],
|
||||
rows: [
|
||||
['Activiti', '13', '3', '10'],
|
||||
['Process Custom Name', '3', '0', '3'],
|
||||
['Second Process', '5', '1', '4'],
|
||||
['Simple process', '29', '1', '28'],
|
||||
['Third Process', '7', '0', '7']
|
||||
],
|
||||
collapseable: false,
|
||||
collapsed: false,
|
||||
showRowIndex: true
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const fakeProcessDefinitionsNoApp: any[] = [
|
||||
{
|
||||
id: 'Process_sid-0FF10DA3-E2BD-4E6A-9013-6D66FC8A4716:1:30004',
|
||||
name: 'Fake Process Name 1',
|
||||
description: null,
|
||||
key: 'Process_sid-0FF10DA3-E2BD-4E6A-9013-6D66FC8A4716',
|
||||
category: 'https://www.activiti.org/processdef',
|
||||
version: 1,
|
||||
deploymentId: '30001',
|
||||
tenantId: 'tenant_1',
|
||||
metaDataValues: [],
|
||||
hasStartForm: false
|
||||
},
|
||||
{
|
||||
id: 'SecondProcess:1:15027',
|
||||
name: 'Fake Process Name 2',
|
||||
description: 'fdsdf',
|
||||
key: 'SecondProcess',
|
||||
category: 'https://www.activiti.org/processdef',
|
||||
version: 1,
|
||||
deploymentId: '15024',
|
||||
tenantId: 'tenant_1',
|
||||
metaDataValues: [],
|
||||
hasStartForm: false
|
||||
},
|
||||
{
|
||||
id: 'Simpleprocess:15:10004',
|
||||
name: 'Fake Process Name 3',
|
||||
description: null,
|
||||
key: 'Simpleprocess',
|
||||
category: 'https://www.activiti.org/processdef',
|
||||
version: 15,
|
||||
deploymentId: '10001',
|
||||
tenantId: 'tenant_1',
|
||||
metaDataValues: [],
|
||||
hasStartForm: false
|
||||
},
|
||||
{
|
||||
id: 'fruitorderprocess:5:42530',
|
||||
name: 'Fake Process Name 4',
|
||||
description: null,
|
||||
key: 'fruitorderprocess',
|
||||
category: 'https://www.activiti.org/processdef',
|
||||
version: 5,
|
||||
deploymentId: '42527',
|
||||
tenantId: 'tenant_1',
|
||||
metaDataValues: [],
|
||||
hasStartForm: false
|
||||
}
|
||||
];
|
||||
|
||||
export class ReportsMock extends BaseMock {
|
||||
get200ResponseCreateDefaultReport(): void {
|
||||
nock(this.host, { encodedQueryParams: true }).post('/activiti-app/app/rest/reporting/default-reports').reply(200);
|
||||
}
|
||||
|
||||
get200ResponseTasksByProcessDefinitionId(reportId: string, processDefinitionId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/app/rest/reporting/report-params/' + reportId + '/tasks')
|
||||
.query({ processDefinitionId })
|
||||
.reply(200, ['Fake Task 1', 'Fake Task 2', 'Fake Task 3']);
|
||||
}
|
||||
|
||||
get200ResponseReportList(): void {
|
||||
nock(this.host, { encodedQueryParams: true }).get('/activiti-app/app/rest/reporting/reports').reply(200, fakeReportList);
|
||||
}
|
||||
|
||||
get200ResponseReportParams(reportId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/app/rest/reporting/report-params/' + reportId)
|
||||
.reply(200, fakeReportParams);
|
||||
}
|
||||
|
||||
get200ResponseReportsByParams(reportId: string, paramsQuery: { status: string }): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/activiti-app/app/rest/reporting/report-params/' + reportId, paramsQuery)
|
||||
.reply(200, fakeChartReports);
|
||||
}
|
||||
|
||||
get200ResponseProcessDefinitions(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/app/rest/reporting/process-definitions')
|
||||
.reply(200, fakeProcessDefinitionsNoApp);
|
||||
}
|
||||
|
||||
get200ResponseUpdateReport(reportId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.put('/activiti-app/app/rest/reporting/reports/' + reportId)
|
||||
.reply(200);
|
||||
}
|
||||
|
||||
get200ResponseExportReport(reportId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/activiti-app/app/rest/reporting/reports/' + reportId + '/export-to-csv')
|
||||
.reply(200, 'CSV');
|
||||
}
|
||||
|
||||
get200ResponseSaveReport(reportId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.post('/activiti-app/app/rest/reporting/reports/' + reportId)
|
||||
.reply(200);
|
||||
}
|
||||
|
||||
get200ResponseDeleteReport(reportId: string): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.delete('/activiti-app/app/rest/reporting/reports/' + reportId)
|
||||
.reply(200);
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class TaskFormMock extends BaseMock {
|
||||
get200getTaskFormVariables(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/api/enterprise/task-forms/5028/variables')
|
||||
.reply(
|
||||
200,
|
||||
[{ id: 'initiator', type: 'string', value: '1001' }],
|
||||
[
|
||||
'Server',
|
||||
'Apache-Coyote/1.1',
|
||||
'set-cookie',
|
||||
'ACTIVITI_REMEMBER_ME=NjdOdGwvcUtFTkVEczQyMGh4WFp5QT09OmpUL1UwdFVBTC94QTJMTFFUVFgvdFE9PQ',
|
||||
'X-Content-Type-Options',
|
||||
'nosniff',
|
||||
'X-XSS-Protection',
|
||||
'1; mode=block',
|
||||
'Cache-Control',
|
||||
'no-cache, no-store, max-age=0, must-revalidate',
|
||||
'Pragma',
|
||||
'no-cache',
|
||||
'Expires',
|
||||
'0',
|
||||
'X-Frame-Options',
|
||||
'SAMEORIGIN',
|
||||
'Content-Type',
|
||||
'application/json',
|
||||
'Transfer-Encoding',
|
||||
'chunked',
|
||||
'Date',
|
||||
'Tue, 01 Nov 2016 19:43:36 GMT',
|
||||
'Connection',
|
||||
'close'
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
1046
lib/js-api/test/mockObjects/process-services/tasks.mock.ts
Normal file
1046
lib/js-api/test/mockObjects/process-services/tasks.mock.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,66 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import nock from 'nock';
|
||||
import { BaseMock } from '../base.mock';
|
||||
|
||||
export class UserFiltersMock extends BaseMock {
|
||||
get200getUserTaskFilters(): void {
|
||||
nock(this.host, { encodedQueryParams: true })
|
||||
.get('/activiti-app/api/enterprise/filters/tasks')
|
||||
.query({ appId: '1' })
|
||||
.reply(200, {
|
||||
size: 4,
|
||||
total: 4,
|
||||
start: 0,
|
||||
data: [
|
||||
{
|
||||
id: 2,
|
||||
name: 'Involved Tasks',
|
||||
appId: 1,
|
||||
recent: true,
|
||||
icon: 'glyphicon-align-left',
|
||||
filter: { sort: 'created-desc', name: '', state: 'open', assignment: 'involved' }
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'My Tasks',
|
||||
appId: 1,
|
||||
recent: false,
|
||||
icon: 'glyphicon-inbox',
|
||||
filter: { sort: 'created-desc', name: '', state: 'open', assignment: 'assignee' }
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
name: 'Queued Tasks',
|
||||
appId: 1,
|
||||
recent: false,
|
||||
icon: 'glyphicon-record',
|
||||
filter: { sort: 'created-desc', name: '', state: 'open', assignment: 'candidate' }
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Completed Tasks',
|
||||
appId: 1,
|
||||
recent: false,
|
||||
icon: 'glyphicon-ok-sign',
|
||||
filter: { sort: 'created-desc', name: '', state: 'completed', assignment: 'involved' }
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
636
lib/js-api/test/oauth2Auth.spec.ts
Normal file
636
lib/js-api/test/oauth2Auth.spec.ts
Normal file
@@ -0,0 +1,636 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, ContentApi, Oauth2Auth } from '../src';
|
||||
import { EcmAuthMock, OAuthMock } from './mockObjects';
|
||||
import jsdom from 'jsdom';
|
||||
|
||||
const { JSDOM } = jsdom;
|
||||
const globalAny: any = global;
|
||||
|
||||
describe('Oauth2 test', () => {
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
let oauth2Mock: OAuthMock;
|
||||
let authResponseMock: EcmAuthMock;
|
||||
|
||||
beforeEach(() => {
|
||||
const hostOauth2 = 'https://myOauthUrl:30081';
|
||||
const mockStorage = {
|
||||
getItem: () => {},
|
||||
setItem: () => {}
|
||||
};
|
||||
|
||||
oauth2Mock = new OAuthMock(hostOauth2);
|
||||
authResponseMock = new EcmAuthMock(hostOauth2);
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm: 'myecm'
|
||||
});
|
||||
|
||||
alfrescoJsApi.storage.setStorage(mockStorage);
|
||||
});
|
||||
|
||||
describe('Discovery urls', () => {
|
||||
const authType = 'OAUTH';
|
||||
const host = 'https://dummy/auth';
|
||||
const clientId = 'dummy';
|
||||
const scope = 'openid';
|
||||
const redirectUri = '/';
|
||||
|
||||
it('should have default urls', async () => {
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host,
|
||||
clientId,
|
||||
scope,
|
||||
redirectUri
|
||||
},
|
||||
authType
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
assert.equal(oauth2Auth.discovery.loginUrl, host + Oauth2Auth.DEFAULT_AUTHORIZATION_URL);
|
||||
assert.equal(oauth2Auth.discovery.tokenEndpoint, host + Oauth2Auth.DEFAULT_TOKEN_URL);
|
||||
assert.equal(oauth2Auth.discovery.logoutUrl, host + Oauth2Auth.DEFAULT_LOGOUT_URL);
|
||||
});
|
||||
|
||||
it('should be possible to override the default urls', async () => {
|
||||
const authorizationUrl = '/custom-login';
|
||||
const logoutUrl = '/custom-logout';
|
||||
const tokenUrl = '/custom-token';
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host,
|
||||
authorizationUrl,
|
||||
logoutUrl,
|
||||
tokenUrl,
|
||||
clientId,
|
||||
scope,
|
||||
redirectUri
|
||||
},
|
||||
authType
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
assert.equal(oauth2Auth.discovery.loginUrl, authorizationUrl);
|
||||
assert.equal(oauth2Auth.discovery.tokenEndpoint, tokenUrl);
|
||||
assert.equal(oauth2Auth.discovery.logoutUrl, logoutUrl);
|
||||
});
|
||||
});
|
||||
|
||||
describe('With Authentication', () => {
|
||||
it('should be possible have different user login in different instance of the oauth2Auth class', async () => {
|
||||
const oauth2AuthInstanceOne = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
const oauth2AuthInstanceTwo = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
const mock = new OAuthMock('https://myOauthUrl:30081');
|
||||
mock.get200Response('superman-token');
|
||||
const loginInstanceOne = await oauth2AuthInstanceOne.login('superman', 'crypto');
|
||||
|
||||
mock.get200Response('barman-token');
|
||||
const loginInstanceTwo = await oauth2AuthInstanceTwo.login('barman', 'IamBarman');
|
||||
|
||||
assert.equal(loginInstanceOne.access_token, 'superman-token');
|
||||
assert.equal(loginInstanceTwo.access_token, 'barman-token');
|
||||
|
||||
oauth2AuthInstanceOne.logOut();
|
||||
oauth2AuthInstanceTwo.logOut();
|
||||
});
|
||||
|
||||
it('login should return the Token if is ok', (done) => {
|
||||
oauth2Mock.get200Response();
|
||||
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
oauth2Auth.login('admin', 'admin').then((data) => {
|
||||
assert.equal(data.access_token, 'test-token');
|
||||
oauth2Auth.logOut();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should refresh token when the login not use the implicitFlow ', function (done) {
|
||||
this.timeout(3000);
|
||||
oauth2Mock.get200Response();
|
||||
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout',
|
||||
implicitFlow: false,
|
||||
refreshTokenTimeout: 100
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
let calls = 0;
|
||||
oauth2Auth.refreshToken = () => {
|
||||
calls++;
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
setTimeout(() => {
|
||||
assert.equal(calls > 2, true);
|
||||
oauth2Auth.logOut();
|
||||
done();
|
||||
}, 600);
|
||||
|
||||
oauth2Auth.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('should not hang the app also if teh logout is missing', function (done) {
|
||||
this.timeout(3000);
|
||||
oauth2Mock.get200Response();
|
||||
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout',
|
||||
implicitFlow: false,
|
||||
refreshTokenTimeout: 100
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
let calls = 0;
|
||||
oauth2Auth.refreshToken = () => {
|
||||
calls++;
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
setTimeout(() => {
|
||||
assert.equal(calls > 2, true);
|
||||
done();
|
||||
}, 600);
|
||||
|
||||
oauth2Auth.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('should emit a token_issued event if login is ok ', (done) => {
|
||||
oauth2Mock.get200Response();
|
||||
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
oauth2Auth.once('token_issued', () => {
|
||||
oauth2Auth.logOut();
|
||||
done();
|
||||
});
|
||||
|
||||
oauth2Auth.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('should not emit a token_issued event if setToken is null ', (done) => {
|
||||
oauth2Mock.get200Response();
|
||||
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
let counterCallEvent = 0;
|
||||
oauth2Auth.once('token_issued', () => {
|
||||
counterCallEvent++;
|
||||
});
|
||||
|
||||
oauth2Auth.setToken(null, null);
|
||||
oauth2Auth.setToken('200', null);
|
||||
oauth2Auth.setToken(null, null);
|
||||
|
||||
assert.equal(counterCallEvent, 1);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should emit a token_issued if provider is ECM', (done) => {
|
||||
oauth2Mock.get200Response();
|
||||
authResponseMock.get200ValidTicket();
|
||||
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
provider: 'ECM',
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
oauth2Auth.once('token_issued', () => {
|
||||
oauth2Auth.logOut();
|
||||
done();
|
||||
});
|
||||
|
||||
oauth2Auth.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('should emit a token_issued if provider is ALL', (done) => {
|
||||
oauth2Mock.get200Response();
|
||||
authResponseMock.get200ValidTicket();
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
provider: 'ALL',
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
oauth2Auth.once('token_issued', () => {
|
||||
oauth2Auth.logOut();
|
||||
done();
|
||||
});
|
||||
|
||||
oauth2Auth.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('should after token_issued event exchange the access_token for the alf_ticket', (done) => {
|
||||
oauth2Mock.get200Response();
|
||||
authResponseMock.get200ValidTicket();
|
||||
|
||||
const alfrescoApi = new AlfrescoApi({
|
||||
hostEcm: 'https://myOauthUrl:30081',
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
});
|
||||
|
||||
alfrescoApi.oauth2Auth.on('ticket_exchanged', () => {
|
||||
assert.equal(alfrescoApi.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
assert.equal(alfrescoApi.contentClient.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
|
||||
const content = new ContentApi(alfrescoApi);
|
||||
const URL = content.getContentUrl('FAKE-NODE-ID');
|
||||
assert.equal(
|
||||
URL,
|
||||
'https://myOauthUrl:30081/alfresco/api/-default-/public/alfresco/versions/1/nodes/FAKE-NODE-ID/content?attachment=false&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
|
||||
alfrescoApi.oauth2Auth.logOut();
|
||||
done();
|
||||
});
|
||||
|
||||
alfrescoApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('should after token_issued event exchange the access_token for the alf_ticket with the compatibility layer', (done) => {
|
||||
oauth2Mock.get200Response();
|
||||
authResponseMock.get200ValidTicket();
|
||||
|
||||
const alfrescoApi = new AlfrescoApi({
|
||||
hostEcm: 'https://myOauthUrl:30081',
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
});
|
||||
|
||||
const contentApi = new ContentApi(alfrescoApi);
|
||||
|
||||
alfrescoApi.oauth2Auth.on('ticket_exchanged', () => {
|
||||
assert.equal(alfrescoApi.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
assert.equal(alfrescoApi.contentClient.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
|
||||
const URL = contentApi.getContentUrl('FAKE-NODE-ID');
|
||||
assert.equal(
|
||||
URL,
|
||||
'https://myOauthUrl:30081/alfresco/api/-default-/public/alfresco/versions/1/nodes/FAKE-NODE-ID/content?attachment=false&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
alfrescoApi.oauth2Auth.logOut();
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
alfrescoApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
// TODO: very flaky test, fails on different machines if running slow, might relate to `this.timeout`
|
||||
// eslint-disable-next-line ban/ban
|
||||
xit('should extend content session after oauth token refresh', function (done) {
|
||||
this.timeout(3000);
|
||||
|
||||
oauth2Mock.get200Response();
|
||||
authResponseMock.get200ValidTicket();
|
||||
|
||||
const alfrescoApi = new AlfrescoApi({
|
||||
hostEcm: 'https://myOauthUrl:30081',
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
});
|
||||
|
||||
let counterCallEvent = 0;
|
||||
alfrescoApi.oauth2Auth.on('ticket_exchanged', () => {
|
||||
assert.equal(alfrescoApi.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
assert.equal(alfrescoApi.contentClient.config.ticketEcm, 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
|
||||
|
||||
const content = new ContentApi(alfrescoApi);
|
||||
const URL = content.getContentUrl('FAKE-NODE-ID');
|
||||
assert.equal(
|
||||
URL,
|
||||
'https://myOauthUrl:30081/alfresco/api/-default-/public/alfresco/versions/1/nodes/FAKE-NODE-ID/content?attachment=false&alf_ticket=TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'
|
||||
);
|
||||
|
||||
counterCallEvent++;
|
||||
|
||||
if (counterCallEvent === 2) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
alfrescoApi.login('admin', 'admin');
|
||||
this.timeout(3000);
|
||||
alfrescoApi.refreshToken();
|
||||
});
|
||||
|
||||
it('isLoggedIn should return true if the api is logged in', (done) => {
|
||||
oauth2Mock.get200Response();
|
||||
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
oauth2Auth.login('admin', 'admin').then(() => {
|
||||
assert.equal(oauth2Auth.isLoggedIn(), true);
|
||||
oauth2Auth.logOut();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('login password should be removed after login', (done) => {
|
||||
oauth2Mock.get200Response();
|
||||
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
oauth2Auth.login('admin', 'admin').then(() => {
|
||||
assert.notEqual(oauth2Auth.authentications.basicAuth.password, 'admin');
|
||||
oauth2Auth.logOut();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('With mocked DOM', () => {
|
||||
beforeEach(() => {
|
||||
const dom = new JSDOM('', { url: 'https://localhost' });
|
||||
globalAny.window = dom.window;
|
||||
globalAny.document = dom.window.document;
|
||||
});
|
||||
|
||||
it('a failed hash check calls the logout', () => {
|
||||
const oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
oauth2Auth.createIframe();
|
||||
|
||||
const iframe = <HTMLIFrameElement>document.getElementById('silent_refresh_token_iframe');
|
||||
iframe.contentWindow.location.hash = 'invalid';
|
||||
|
||||
let logoutCalled = false;
|
||||
oauth2Auth.logOut = () => {
|
||||
logoutCalled = true;
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
// invalid hash location leads to a reject which leads to a logout
|
||||
oauth2Auth.iFrameHashListener();
|
||||
setTimeout(() => {
|
||||
assert.equal(logoutCalled, true);
|
||||
}, 500);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
globalAny.window = undefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe('public urls', () => {
|
||||
let oauth2Auth: Oauth2Auth;
|
||||
|
||||
beforeEach(() => {
|
||||
oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
scope: 'openid',
|
||||
secret: '',
|
||||
redirectUri: '/',
|
||||
redirectUriLogout: '/logout'
|
||||
},
|
||||
authType: 'OAUTH'
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
});
|
||||
|
||||
it('should return true if PathMatcher.match returns true for matching url', () => {
|
||||
globalAny.window = { location: { href: 'public-url' } };
|
||||
oauth2Auth.config.oauth2.publicUrls = ['public-url'];
|
||||
oauth2Auth.pathMatcher = {
|
||||
match: () => true
|
||||
};
|
||||
|
||||
assert.equal(oauth2Auth.isPublicUrl(), true);
|
||||
});
|
||||
|
||||
it('should return false if PathMatcher.match returns false for matching url', () => {
|
||||
globalAny.window = { location: { href: 'some-public-url' } };
|
||||
oauth2Auth.config.oauth2.publicUrls = ['public-url'];
|
||||
oauth2Auth.pathMatcher = {
|
||||
match: () => false
|
||||
};
|
||||
|
||||
assert.equal(oauth2Auth.isPublicUrl(), false);
|
||||
});
|
||||
|
||||
it('should return false if publicUrls property is not defined', () => {
|
||||
assert.equal(oauth2Auth.isPublicUrl(), false);
|
||||
});
|
||||
|
||||
it('should return false if public urls is not set as an array list', () => {
|
||||
globalAny.window = { location: { href: 'public-url-string' } };
|
||||
oauth2Auth.config.oauth2.publicUrls = null;
|
||||
assert.equal(oauth2Auth.isPublicUrl(), false);
|
||||
});
|
||||
|
||||
it('should not call `implicitLogin`', async () => {
|
||||
globalAny.window = { location: { href: 'public-url' } };
|
||||
oauth2Auth.config.oauth2.silentLogin = true;
|
||||
oauth2Auth.config.oauth2.publicUrls = ['public-url'];
|
||||
|
||||
oauth2Auth.pathMatcher = {
|
||||
match: () => true
|
||||
};
|
||||
|
||||
let implicitLoginCalled = false;
|
||||
oauth2Auth.implicitLogin = () => {
|
||||
implicitLoginCalled = true;
|
||||
};
|
||||
|
||||
await oauth2Auth.checkFragment();
|
||||
assert.equal(implicitLoginCalled, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
188
lib/js-api/test/oauth2AuthImplicitFlow.spec.ts
Normal file
188
lib/js-api/test/oauth2AuthImplicitFlow.spec.ts
Normal file
@@ -0,0 +1,188 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, Oauth2Auth } from '../src';
|
||||
|
||||
declare let window: any;
|
||||
const globalAny: any = global;
|
||||
|
||||
describe('Oauth2 Implicit flow test', () => {
|
||||
let oauth2Auth: Oauth2Auth;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
|
||||
beforeEach(() => {
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm: ''
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error if redirectUri is not present', (done) => {
|
||||
try {
|
||||
oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
secret: '',
|
||||
scope: 'openid',
|
||||
implicitFlow: true,
|
||||
redirectUri: undefined
|
||||
}
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
} catch (error) {
|
||||
assert.equal(error.message, 'Missing redirectUri required parameter');
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('should redirect to login if access token is not valid', (done) => {
|
||||
window = globalAny.window = { location: {} };
|
||||
globalAny.document = {
|
||||
getElementById: () => ''
|
||||
};
|
||||
|
||||
oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
secret: '',
|
||||
scope: 'openid',
|
||||
implicitFlow: true,
|
||||
redirectUri: 'redirectUri'
|
||||
}
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
oauth2Auth.on('implicit_redirect', () => {
|
||||
assert.equal(window.location.href.includes('https://myOauthUrl:30081/auth/realms/springboot/protocol/openid-connect/auth?'), true);
|
||||
done();
|
||||
});
|
||||
|
||||
oauth2Auth.implicitLogin();
|
||||
});
|
||||
|
||||
it('should not loop over redirection when redirectUri contains hash and token is not valid ', (done) => {
|
||||
window = globalAny.window = { location: {} };
|
||||
globalAny.document = {
|
||||
getElementById: () => ''
|
||||
};
|
||||
oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
secret: '',
|
||||
scope: 'openid',
|
||||
implicitFlow: true,
|
||||
redirectUri: '#/redirectUri'
|
||||
}
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
let setItemCalled = false;
|
||||
alfrescoJsApi.storage.setItem = () => (setItemCalled = true);
|
||||
|
||||
oauth2Auth.on('implicit_redirect', () => {
|
||||
assert.equal(window.location.href.includes('https://myOauthUrl:30081/auth/realms/springboot/protocol/openid-connect/auth?'), true);
|
||||
assert.equal(setItemCalled, true);
|
||||
done();
|
||||
});
|
||||
|
||||
oauth2Auth.implicitLogin();
|
||||
});
|
||||
|
||||
it('should not redirect to login if access token is valid', (done) => {
|
||||
window = globalAny.window = { location: {} };
|
||||
globalAny.document = {
|
||||
getElementById: () => ''
|
||||
};
|
||||
oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
secret: '',
|
||||
scope: 'openid',
|
||||
implicitFlow: true,
|
||||
redirectUri: 'redirectUri'
|
||||
}
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
oauth2Auth.isValidAccessToken = () => true;
|
||||
oauth2Auth.isValidToken = () => true;
|
||||
|
||||
oauth2Auth.on('token_issued', () => {
|
||||
assert.equal(window.location.url, undefined);
|
||||
done();
|
||||
});
|
||||
|
||||
oauth2Auth.setToken('new_token', 'new_refresh_token');
|
||||
|
||||
oauth2Auth.implicitLogin();
|
||||
});
|
||||
|
||||
it('should set the loginFragment to redirect after the login if it is present', (done) => {
|
||||
window = globalAny.window = {};
|
||||
globalAny.document = {
|
||||
getElementById: () => ''
|
||||
};
|
||||
window.location = <Location>{ hash: 'asfasfasfa' };
|
||||
|
||||
Object.defineProperty(window.location, 'hash', {
|
||||
writable: true,
|
||||
value: '#/redirect-path&session_state=eqfqwfqwf'
|
||||
});
|
||||
|
||||
Object.defineProperty(window.location, 'href', {
|
||||
writable: true,
|
||||
value: 'https://stoca/#/redirect-path&session_state=eqfqwfqwf'
|
||||
});
|
||||
|
||||
oauth2Auth = new Oauth2Auth(
|
||||
{
|
||||
oauth2: {
|
||||
host: 'https://myOauthUrl:30081/auth/realms/springboot',
|
||||
clientId: 'activiti',
|
||||
secret: '',
|
||||
scope: 'openid',
|
||||
implicitFlow: true,
|
||||
redirectUri: 'redirectUri'
|
||||
}
|
||||
},
|
||||
alfrescoJsApi
|
||||
);
|
||||
|
||||
let lastValues: [string, any];
|
||||
alfrescoJsApi.storage.setItem = (key, value) => (lastValues = [key, value]);
|
||||
|
||||
oauth2Auth.on('implicit_redirect', () => {
|
||||
assert.equal(window.location.href.includes('https://myOauthUrl:30081/auth/realms/springboot/protocol/openid-connect/auth?'), true);
|
||||
assert.deepEqual(lastValues, ['loginFragment', '/redirect-path&session_state=eqfqwfqwf']);
|
||||
done();
|
||||
});
|
||||
|
||||
oauth2Auth.implicitLogin();
|
||||
});
|
||||
});
|
101
lib/js-api/test/path-matcher.spec.ts
Normal file
101
lib/js-api/test/path-matcher.spec.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { PathMatcher } from '../src/utils/path-matcher';
|
||||
|
||||
describe('PathMatcher', () => {
|
||||
const pathPatcher = new PathMatcher();
|
||||
|
||||
describe('match', () => {
|
||||
it('should return true if path is exactly the same like pattern', () => {
|
||||
assert.equal(pathPatcher.match('public-url', 'public-url'), true);
|
||||
});
|
||||
|
||||
it('should return false if path is not equal to pattern', () => {
|
||||
assert.equal(pathPatcher.match('some-public-url', 'public-url'), false);
|
||||
});
|
||||
|
||||
it('should return true if absolute path is equal to absolute path', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url', 'https://some-public-url'), true);
|
||||
});
|
||||
|
||||
it('should return true if path matches pattern containing double and single *', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/123/path', '**/some-public-url/*/path'), true);
|
||||
});
|
||||
|
||||
it('should return true if path matches to pattern after replacing ** with multiple parts at the beginning', () => {
|
||||
assert.equal(pathPatcher.match('https://test/other-test/some-public-url/path', '**/some-public-url/path'), true);
|
||||
});
|
||||
|
||||
it('should return true if path matches to pattern after replacing ** with multiple parts at the beginning', () => {
|
||||
assert.equal(pathPatcher.match('https://test/other-test/some-public-url/path', '**/some-public-url/path'), true);
|
||||
});
|
||||
|
||||
it('should return true if path matches to pattern after replacing ** with multiple parts at the end', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/path/test/other-test', 'https://some-public-url/path/**'), true);
|
||||
});
|
||||
|
||||
it('should return true if path matches to pattern after replacing ** with none parts at the end', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/path/', 'https://some-public-url/path/**'), true);
|
||||
});
|
||||
|
||||
it('should return false if path does not match to pattern after replacing ** with none parts at the end and cuts last /', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/path', 'https://some-public-url/path/**'), false);
|
||||
});
|
||||
|
||||
it('should return true if path matches to pattern after replacing ** with multiple parts in the middle', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/test/other-test/path', 'https://some-public-url/**/path'), true);
|
||||
});
|
||||
|
||||
it('should return true if path matches to pattern after replacing ** with none parts in the middle', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/path', 'https://some-public-url/**/path'), true);
|
||||
});
|
||||
|
||||
it('should return false if path does not match to pattern with **', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/', 'https://some-public-url/**/path'), false);
|
||||
});
|
||||
|
||||
it('should return false if path has more than one part as replacement for * in the middle of pattern', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/123/test/path', 'https://some-public-url/*/path'), false);
|
||||
});
|
||||
|
||||
it('should return false if path has zero parts as replacement for * in the middle of pattern', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/path', 'https://some-public-url/*/path'), false);
|
||||
});
|
||||
|
||||
it('should return true if path matches to pattern containing * at the end', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/path/test', 'https://some-public-url/path/*'), true);
|
||||
});
|
||||
|
||||
it('should return false if path matches to pattern containing * at the end and cuts last /', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/path', 'https://some-public-url/path/*'), false);
|
||||
});
|
||||
|
||||
it('should return false if path has more than one part as replacement for * at the end of pattern', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/path/test/other-test', 'https://some-public-url/path/*'), false);
|
||||
});
|
||||
|
||||
it('should return false if path has zero parts as replacement for * at the end of pattern', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/path/test/other-test', 'https://some-public-url/path/*'), false);
|
||||
});
|
||||
|
||||
it('should return false if path starts with https:// and * is at the beginning of pattern', () => {
|
||||
assert.equal(pathPatcher.match('https://some-public-url/path/test', '*/some-public-url/path'), false);
|
||||
});
|
||||
});
|
||||
});
|
51
lib/js-api/test/peopleApi.spec.ts
Normal file
51
lib/js-api/test/peopleApi.spec.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AlfrescoApi, PeopleApi, PersonBodyCreate } from '../src';
|
||||
import { PeopleMock } from './mockObjects';
|
||||
|
||||
describe('PeopleApi', () => {
|
||||
let peopleMock: PeopleMock;
|
||||
let peopleApi: PeopleApi;
|
||||
|
||||
beforeEach(() => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
const alfrescoApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
peopleMock = new PeopleMock(hostEcm);
|
||||
peopleApi = new PeopleApi(alfrescoApi);
|
||||
});
|
||||
|
||||
it('should add a person', (done) => {
|
||||
peopleMock.get201Response();
|
||||
|
||||
const personBodyCreate: PersonBodyCreate = {
|
||||
id: 'chewbe',
|
||||
email: 'chewbe@millenniumfalcon.com',
|
||||
lastName: 'Chewbe',
|
||||
firstName: 'chewbacca',
|
||||
password: 'Rrrrrrrghghghghgh'
|
||||
};
|
||||
|
||||
peopleApi.createPerson(personBodyCreate).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
56
lib/js-api/test/process-services/modelApi.spec.ts
Normal file
56
lib/js-api/test/process-services/modelApi.spec.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, ModelsApi } from '../../src';
|
||||
import { BpmAuthMock, ModelsMock } from '../mockObjects';
|
||||
|
||||
describe('Activiti Models Api', () => {
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let modelsMock: ModelsMock;
|
||||
let modelsApi: ModelsApi;
|
||||
|
||||
beforeEach(async () => {
|
||||
const hostBpm = 'https://127.0.0.1:9999';
|
||||
|
||||
authResponseBpmMock = new BpmAuthMock(hostBpm);
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
modelsMock = new ModelsMock(hostBpm);
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm,
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
modelsApi = new ModelsApi(alfrescoJsApi);
|
||||
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('get activiti model', async () => {
|
||||
modelsMock.get200getModels();
|
||||
|
||||
const opts = {
|
||||
filter: 'myReusableForms',
|
||||
modelType: 2
|
||||
};
|
||||
|
||||
const data = await modelsApi.getModels(opts);
|
||||
assert.equal(data.data[0].name, 'Metadata');
|
||||
});
|
||||
});
|
56
lib/js-api/test/process-services/modelJsonBpmnApi.spec.ts
Normal file
56
lib/js-api/test/process-services/modelJsonBpmnApi.spec.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, ModelJsonBpmnApi } from '../../src';
|
||||
import { BpmAuthMock, ModelJsonBpmMock } from '../mockObjects';
|
||||
|
||||
describe('Activiti Model JsonBpmn Api', () => {
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let modelJsonBpmMock: ModelJsonBpmMock;
|
||||
let modelJsonBpmnApi: ModelJsonBpmnApi;
|
||||
|
||||
beforeEach(async () => {
|
||||
const hostBpm = 'https://127.0.0.1:9999';
|
||||
|
||||
authResponseBpmMock = new BpmAuthMock(hostBpm);
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
modelJsonBpmMock = new ModelJsonBpmMock(hostBpm);
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm,
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
modelJsonBpmnApi = new ModelJsonBpmnApi(alfrescoJsApi);
|
||||
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('get Model JsonBpmn', async () => {
|
||||
modelJsonBpmMock.get200EditorDisplayJsonClient();
|
||||
const data = await modelJsonBpmnApi.getEditorDisplayJsonClient(1);
|
||||
assert.notEqual(data, null);
|
||||
});
|
||||
|
||||
it('get Model JsonBpmn history', async () => {
|
||||
modelJsonBpmMock.get200HistoricEditorDisplayJsonClient();
|
||||
const data = await modelJsonBpmnApi.getHistoricEditorDisplayJsonClient(1, 1);
|
||||
assert.notEqual(data, null);
|
||||
});
|
||||
});
|
84
lib/js-api/test/process-services/processApi.spec.ts
Normal file
84
lib/js-api/test/process-services/processApi.spec.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { BpmAuthMock, ProcessMock } from '../mockObjects';
|
||||
import { AlfrescoApi, ProcessDefinitionsApi, ProcessInstanceQueryRepresentation, ProcessInstancesApi } from '../../src';
|
||||
|
||||
describe('Activiti Process Api', () => {
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let processMock: ProcessMock;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
let processInstancesApi: ProcessInstancesApi;
|
||||
let processDefinitionsApi: ProcessDefinitionsApi;
|
||||
|
||||
beforeEach(async () => {
|
||||
const BPM_HOST = 'https://127.0.0.1:9999';
|
||||
|
||||
authResponseBpmMock = new BpmAuthMock(BPM_HOST);
|
||||
processMock = new ProcessMock(BPM_HOST);
|
||||
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm: BPM_HOST,
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
processInstancesApi = new ProcessInstancesApi(alfrescoJsApi);
|
||||
processDefinitionsApi = new ProcessDefinitionsApi(alfrescoJsApi);
|
||||
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('get activiti Process list filtered', (done) => {
|
||||
processMock.get200Response();
|
||||
|
||||
const requestNode: ProcessInstanceQueryRepresentation = {
|
||||
page: 0,
|
||||
sort: 'created-desc',
|
||||
state: 'completed'
|
||||
};
|
||||
|
||||
processInstancesApi.getProcessInstances(requestNode).then((data) => {
|
||||
assert.equal(data.data[0].name, 'Process Test Api - July 26th 2016');
|
||||
assert.equal(data.data[1].name, 'Process Test Api - July 26th 2016');
|
||||
assert.equal(data.size, 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get activiti Process list', (done) => {
|
||||
processMock.get200Response();
|
||||
|
||||
processInstancesApi.getProcessInstances({}).then((data) => {
|
||||
assert.equal(data.data[0].name, 'Process Test Api - July 26th 2016');
|
||||
assert.equal(data.data[1].name, 'Process Test Api - July 26th 2016');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get process definition startForm', (done) => {
|
||||
processMock.get200getProcessDefinitionStartForm();
|
||||
const processDefinitionId = 'testProcess:1:7504';
|
||||
|
||||
processDefinitionsApi.getProcessDefinitionStartForm(processDefinitionId).then((data) => {
|
||||
assert.equal(data.processDefinitionId, 'testProcess:1:7504');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,174 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { BpmAuthMock, ProcessInstanceVariablesMock } from '../mockObjects';
|
||||
import { ProcessInstanceVariablesApi, AlfrescoApi } from '../../src';
|
||||
|
||||
describe('Activiti Process Instance Variables Api', () => {
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let variablesMock: ProcessInstanceVariablesMock;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
let processInstanceVariablesApi: ProcessInstanceVariablesApi;
|
||||
|
||||
const NOOP = () => {
|
||||
/* empty */
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const BPM_HOST = 'https://127.0.0.1:9999';
|
||||
|
||||
authResponseBpmMock = new BpmAuthMock(BPM_HOST);
|
||||
variablesMock = new ProcessInstanceVariablesMock(BPM_HOST);
|
||||
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm: BPM_HOST,
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
processInstanceVariablesApi = new ProcessInstanceVariablesApi(alfrescoJsApi);
|
||||
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
describe('get variables', () => {
|
||||
it('should return all variables for a process instance', (done) => {
|
||||
const processInstanceId = '111';
|
||||
variablesMock.addListProcessInstanceVariables200Response(processInstanceId);
|
||||
|
||||
processInstanceVariablesApi.getProcessInstanceVariables(processInstanceId).then((data) => {
|
||||
assert.equal(data.length, 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit an error when API returns an error response', (done) => {
|
||||
const processInstanceId = '111';
|
||||
variablesMock.addListProcessInstanceVariables500Response(processInstanceId);
|
||||
|
||||
processInstanceVariablesApi.getProcessInstanceVariables(processInstanceId).then(NOOP, (error) => {
|
||||
assert.equal(error.status, 500);
|
||||
assert.equal(error.message, '{"messageKey":"UNKNOWN","message":"Unknown error"}');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('create or update variables', () => {
|
||||
it('should return all variables for a process instance', (done) => {
|
||||
const processInstanceId = '111';
|
||||
variablesMock.addPutProcessInstanceVariables200Response(processInstanceId);
|
||||
|
||||
processInstanceVariablesApi.createOrUpdateProcessInstanceVariables(processInstanceId, []).then((data) => {
|
||||
assert.equal(data.length, 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit an error when API returns an error response', (done) => {
|
||||
const processInstanceId = '111';
|
||||
variablesMock.addPutProcessInstanceVariables500Response(processInstanceId);
|
||||
|
||||
processInstanceVariablesApi.createOrUpdateProcessInstanceVariables(processInstanceId, []).then(NOOP, (error) => {
|
||||
assert.equal(error.status, 500);
|
||||
assert.equal(error.message, '{"messageKey":"UNKNOWN","message":"Unknown error"}');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get variable', () => {
|
||||
it('should call API to get variable', (done) => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addGetProcessInstanceVariable200Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.getProcessInstanceVariable(processInstanceId, variableName).then(
|
||||
(data) => {
|
||||
assert.equal(data.name, 'variable1');
|
||||
assert.equal(data.value, 'Value 123');
|
||||
done();
|
||||
},
|
||||
() => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should emit an error when API returns an error response', (done) => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addGetProcessInstanceVariable500Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.getProcessInstanceVariable(processInstanceId, variableName).then(NOOP, (error) => {
|
||||
assert.equal(error.status, 500);
|
||||
assert.equal(error.message, '{"messageKey":"UNKNOWN","message":"Unknown error"}');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('update variable', () => {
|
||||
it('should call API to update variable', (done) => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addUpdateProcessInstanceVariable200Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.updateProcessInstanceVariable(processInstanceId, variableName, {}).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit an error when API returns an error response', (done) => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addUpdateProcessInstanceVariable500Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.updateProcessInstanceVariable(processInstanceId, variableName, {}).then(NOOP, (error) => {
|
||||
assert.equal(error.status, 500);
|
||||
assert.equal(error.message, '{"messageKey":"UNKNOWN","message":"Unknown error"}');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('delete variable', () => {
|
||||
it('should call API to delete variables', (done) => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addDeleteProcessInstanceVariable200Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.deleteProcessInstanceVariable(processInstanceId, variableName).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit an error when API returns an error response', (done) => {
|
||||
const processInstanceId = '111';
|
||||
const variableName = 'var1';
|
||||
variablesMock.addDeleteProcessInstanceVariable500Response(processInstanceId, variableName);
|
||||
|
||||
processInstanceVariablesApi.deleteProcessInstanceVariable(processInstanceId, variableName).then(NOOP, (error) => {
|
||||
assert.equal(error.status, 500);
|
||||
assert.equal(error.message, '{"messageKey":"UNKNOWN","message":"Unknown error"}');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
62
lib/js-api/test/process-services/profileApi.spec.ts
Normal file
62
lib/js-api/test/process-services/profileApi.spec.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, UserProfileApi } from '../../src';
|
||||
import { BpmAuthMock, ProfileMock } from '../mockObjects';
|
||||
|
||||
describe('Activiti Profile Api', () => {
|
||||
let profileApi: UserProfileApi;
|
||||
|
||||
let profileMock: ProfileMock;
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
|
||||
beforeEach(async () => {
|
||||
const BPM_HOST = 'https://127.0.0.1:9999';
|
||||
|
||||
authResponseBpmMock = new BpmAuthMock(BPM_HOST);
|
||||
profileMock = new ProfileMock(BPM_HOST);
|
||||
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
const alfrescoApi = new AlfrescoApi({
|
||||
hostBpm: BPM_HOST,
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
profileApi = new UserProfileApi(alfrescoApi);
|
||||
|
||||
await alfrescoApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('get Profile Picture', async () => {
|
||||
profileMock.get200getProfilePicture();
|
||||
await profileApi.getProfilePicture();
|
||||
});
|
||||
|
||||
it('get Profile url Picture', () => {
|
||||
assert.equal(profileApi.getProfilePictureUrl(), 'https://127.0.0.1:9999/activiti-app/app/rest/admin/profile-picture');
|
||||
});
|
||||
|
||||
it('get Profile', async () => {
|
||||
profileMock.get200getProfile();
|
||||
const data = await profileApi.getProfile();
|
||||
assert.equal(data.lastName, 'Administrator');
|
||||
assert.equal(data.groups[0].name, 'analytics-users');
|
||||
assert.equal(data.tenantName, 'test');
|
||||
});
|
||||
});
|
203
lib/js-api/test/process-services/reportApi.spec.ts
Normal file
203
lib/js-api/test/process-services/reportApi.spec.ts
Normal file
@@ -0,0 +1,203 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { BpmAuthMock, ReportsMock } from '../mockObjects';
|
||||
import { ReportApi, AlfrescoApi } from '../../src';
|
||||
|
||||
describe('Activiti Report Api', () => {
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let reportsMock: ReportsMock;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
let reportApi: ReportApi;
|
||||
|
||||
beforeEach(async () => {
|
||||
const BPM_HOST = 'https://127.0.0.1:9999';
|
||||
|
||||
authResponseBpmMock = new BpmAuthMock(BPM_HOST);
|
||||
reportsMock = new ReportsMock(BPM_HOST);
|
||||
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm: BPM_HOST,
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
reportApi = new ReportApi(alfrescoJsApi);
|
||||
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('should create the default reports', async () => {
|
||||
reportsMock.get200ResponseCreateDefaultReport();
|
||||
await reportApi.createDefaultReports();
|
||||
});
|
||||
|
||||
it('should return the tasks referring to the process id', async () => {
|
||||
const reportId = '11015';
|
||||
const processDefinitionId = 'Process_sid-0FF10DA3-E2BD-4E6A-9013-6D66FC8A4716:1:30004';
|
||||
|
||||
reportsMock.get200ResponseTasksByProcessDefinitionId(reportId, processDefinitionId);
|
||||
|
||||
const data = await reportApi.getTasksByProcessDefinitionId(reportId, processDefinitionId);
|
||||
assert.equal(data.length, 3);
|
||||
assert.equal(data[0], 'Fake Task 1');
|
||||
assert.equal(data[1], 'Fake Task 2');
|
||||
assert.equal(data[2], 'Fake Task 3');
|
||||
});
|
||||
|
||||
it('should return the chart reports', async () => {
|
||||
const reportId = '11015';
|
||||
const paramsQuery = { status: 'All' };
|
||||
|
||||
reportsMock.get200ResponseReportsByParams(reportId, paramsQuery);
|
||||
|
||||
const data = await reportApi.getReportsByParams(reportId, paramsQuery);
|
||||
assert.equal(data.elements.length, 3);
|
||||
assert.equal(data.elements[0].type, 'table');
|
||||
|
||||
assert.equal(data.elements[1].type, 'pieChart');
|
||||
assert.equal(data.elements[1].titleKey, 'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.PROC-INST-CHART-TITLE');
|
||||
|
||||
assert.equal(data.elements[2].type, 'table');
|
||||
assert.equal(data.elements[2].titleKey, 'REPORTING.DEFAULT-REPORTS.PROCESS-DEFINITION-OVERVIEW.DETAIL-TABLE');
|
||||
});
|
||||
|
||||
it('should return the process definitions when the appId is not provided', async () => {
|
||||
reportsMock.get200ResponseProcessDefinitions();
|
||||
|
||||
const res = await reportApi.getProcessDefinitions();
|
||||
|
||||
assert.equal(res.length, 4);
|
||||
assert.equal(res[0].id, 'Process_sid-0FF10DA3-E2BD-4E6A-9013-6D66FC8A4716:1:30004');
|
||||
assert.equal(res[0].name, 'Fake Process Name 1');
|
||||
|
||||
assert.equal(res[1].id, 'SecondProcess:1:15027');
|
||||
assert.equal(res[1].name, 'Fake Process Name 2');
|
||||
|
||||
assert.equal(res[2].id, 'Simpleprocess:15:10004');
|
||||
assert.equal(res[2].name, 'Fake Process Name 3');
|
||||
|
||||
assert.equal(res[3].id, 'fruitorderprocess:5:42530');
|
||||
assert.equal(res[3].name, 'Fake Process Name 4');
|
||||
});
|
||||
|
||||
it('should return the report list', async () => {
|
||||
reportsMock.get200ResponseReportList();
|
||||
|
||||
const res = await reportApi.getReportList();
|
||||
|
||||
assert.equal(res.length, 5);
|
||||
|
||||
assert.equal(res[0].id, 11011);
|
||||
assert.equal(res[0].name, 'Process definition heat map');
|
||||
|
||||
assert.equal(res[1].id, 11012);
|
||||
assert.equal(res[1].name, 'Process definition overview');
|
||||
|
||||
assert.equal(res[2].id, 11013);
|
||||
assert.equal(res[2].name, 'Process instances overview');
|
||||
|
||||
assert.equal(res[3].id, 11014);
|
||||
assert.equal(res[3].name, 'Task overview');
|
||||
|
||||
assert.equal(res[4].id, 11015);
|
||||
assert.equal(res[4].name, 'Task service level agreement');
|
||||
});
|
||||
|
||||
it('should return the report parameters', async () => {
|
||||
const reportId = '11013'; // String | reportId
|
||||
reportsMock.get200ResponseReportParams(reportId);
|
||||
|
||||
const res = await reportApi.getReportParams(reportId);
|
||||
const paramsDefinition = JSON.parse(res.definition);
|
||||
|
||||
assert.equal(res.id, 11013);
|
||||
assert.equal(res.name, 'Process instances overview');
|
||||
assert.equal(paramsDefinition.parameters.length, 4);
|
||||
|
||||
assert.equal(paramsDefinition.parameters[0].id, 'processDefinitionId');
|
||||
assert.equal(paramsDefinition.parameters[0].nameKey, 'REPORTING.DEFAULT-REPORTS.PROCESS-INSTANCES-OVERVIEW.PROCESS-DEFINITION');
|
||||
assert.equal(paramsDefinition.parameters[0].type, 'processDefinition');
|
||||
|
||||
assert.equal(paramsDefinition.parameters[1].id, 'dateRange');
|
||||
assert.equal(paramsDefinition.parameters[1].nameKey, 'REPORTING.DEFAULT-REPORTS.PROCESS-INSTANCES-OVERVIEW.DATE-RANGE');
|
||||
assert.equal(paramsDefinition.parameters[1].type, 'dateRange');
|
||||
|
||||
assert.equal(paramsDefinition.parameters[2].id, 'slowProcessInstanceInteger');
|
||||
assert.equal(paramsDefinition.parameters[2].nameKey, 'REPORTING.DEFAULT-REPORTS.PROCESS-INSTANCES-OVERVIEW.SLOW-PROC-INST-NUMBER');
|
||||
assert.equal(paramsDefinition.parameters[2].type, 'integer');
|
||||
|
||||
assert.equal(paramsDefinition.parameters[3].id, 'status');
|
||||
assert.equal(paramsDefinition.parameters[3].nameKey, 'REPORTING.PROCESS-STATUS');
|
||||
assert.equal(paramsDefinition.parameters[3].type, 'status');
|
||||
});
|
||||
|
||||
it('should update the report', async () => {
|
||||
const reportId = '11015';
|
||||
const name = 'New Fake Name';
|
||||
reportsMock.get200ResponseUpdateReport(reportId);
|
||||
|
||||
await reportApi.updateReport(reportId, name);
|
||||
});
|
||||
|
||||
it('should export the report', async () => {
|
||||
const reportId = '11015'; // String | reportId
|
||||
const queryParams = {
|
||||
processDefinitionId: 'TEST:99:999',
|
||||
dateRange: {
|
||||
startDate: '2017-01-01T00:00:00.000Z',
|
||||
endDate: '2017-01-24T23:59:59.999Z',
|
||||
rangeId: 'currentYear'
|
||||
},
|
||||
slowProcessInstanceInteger: 10,
|
||||
status: 'All',
|
||||
reportName: 'FAKE_REPORT_NAME'
|
||||
};
|
||||
reportsMock.get200ResponseExportReport(reportId);
|
||||
|
||||
const response = await reportApi.exportToCsv(reportId, queryParams);
|
||||
assert.notEqual(response, null);
|
||||
assert.notEqual(response, undefined);
|
||||
});
|
||||
|
||||
it('should save the report', async () => {
|
||||
const reportId = '11015'; // String | reportId
|
||||
const queryParams = {
|
||||
processDefinitionId: 'TEST:99:999',
|
||||
dateRange: {
|
||||
startDate: '2017-01-01T00:00:00.000Z',
|
||||
endDate: '2017-01-24T23:59:59.999Z',
|
||||
rangeId: 'currentYear'
|
||||
},
|
||||
slowProcessInstanceInteger: 10,
|
||||
status: 'All',
|
||||
reportName: 'FAKE_REPORT_NAME'
|
||||
};
|
||||
reportsMock.get200ResponseSaveReport(reportId);
|
||||
|
||||
await reportApi.saveReport(reportId, queryParams);
|
||||
});
|
||||
|
||||
it('should delete a report', async () => {
|
||||
const reportId = '11015';
|
||||
reportsMock.get200ResponseDeleteReport(reportId);
|
||||
|
||||
await reportApi.deleteReport(reportId);
|
||||
});
|
||||
});
|
169
lib/js-api/test/process-services/taskApi.spec.ts
Normal file
169
lib/js-api/test/process-services/taskApi.spec.ts
Normal file
@@ -0,0 +1,169 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import {
|
||||
AlfrescoApi,
|
||||
TaskFilterRequestRepresentation,
|
||||
TaskRepresentation,
|
||||
TaskFormsApi,
|
||||
TaskActionsApi,
|
||||
TasksApi,
|
||||
TaskQueryRepresentation
|
||||
} from '../../src';
|
||||
import { BpmAuthMock, TasksMock } from '../mockObjects';
|
||||
|
||||
describe('Activiti Task Api', () => {
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let tasksMock: TasksMock;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
let tasksApi: TasksApi;
|
||||
let taskFormsApi: TaskFormsApi;
|
||||
let taskActionsApi: TaskActionsApi;
|
||||
|
||||
const NOOP = () => {
|
||||
/* empty */
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
const BPM_HOST = 'https://127.0.0.1:9999';
|
||||
|
||||
authResponseBpmMock = new BpmAuthMock(BPM_HOST);
|
||||
tasksMock = new TasksMock(BPM_HOST);
|
||||
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm: BPM_HOST,
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
tasksApi = new TasksApi(alfrescoJsApi);
|
||||
taskFormsApi = new TaskFormsApi(alfrescoJsApi);
|
||||
taskActionsApi = new TaskActionsApi(alfrescoJsApi);
|
||||
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('get Task list', async () => {
|
||||
tasksMock.get200Response();
|
||||
|
||||
const requestNode = new TaskQueryRepresentation();
|
||||
const data = await tasksApi.listTasks(requestNode);
|
||||
|
||||
assert.equal(data.data[0].processDefinitionName, 'Process Test Api');
|
||||
assert.equal(data.data[1].processDefinitionName, 'Process Test Api');
|
||||
assert.equal(data.size, 2);
|
||||
});
|
||||
|
||||
it('get Task', async () => {
|
||||
tasksMock.get200ResponseGetTask('10');
|
||||
|
||||
const data = await tasksApi.getTask('10');
|
||||
assert.equal(data.name, 'Upload Document');
|
||||
});
|
||||
|
||||
it('bad filter Tasks', (done) => {
|
||||
tasksMock.get400TaskFilter();
|
||||
|
||||
const requestNode = new TaskFilterRequestRepresentation();
|
||||
|
||||
tasksApi.filterTasks(requestNode).then(NOOP, () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('filter Tasks', async () => {
|
||||
tasksMock.get200TaskFilter();
|
||||
|
||||
const requestNode = new TaskFilterRequestRepresentation();
|
||||
requestNode.appDefinitionId = 1;
|
||||
|
||||
const data = await tasksApi.filterTasks(requestNode);
|
||||
assert.equal(data.size, 2);
|
||||
assert.equal(data.data[0].id, '7506');
|
||||
});
|
||||
|
||||
it('complete Task not found', (done) => {
|
||||
const taskId = '200';
|
||||
tasksMock.get404CompleteTask(taskId);
|
||||
|
||||
taskActionsApi.completeTask(taskId).then(NOOP, () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('complete Task ', async () => {
|
||||
const taskId = '5006';
|
||||
|
||||
tasksMock.put200GenericResponse('/activiti-app/api/enterprise/tasks/5006/action/complete');
|
||||
|
||||
await taskActionsApi.completeTask(taskId);
|
||||
});
|
||||
|
||||
it('Create a Task', async () => {
|
||||
const taskName = 'test-name';
|
||||
|
||||
tasksMock.get200CreateTask(taskName);
|
||||
|
||||
const taskRepresentation = new TaskRepresentation();
|
||||
taskRepresentation.name = taskName;
|
||||
|
||||
await tasksApi.createNewTask(taskRepresentation);
|
||||
});
|
||||
|
||||
it('Get task form', async () => {
|
||||
tasksMock.get200getTaskForm();
|
||||
|
||||
const taskId = '2518';
|
||||
const data = await taskFormsApi.getTaskForm(taskId);
|
||||
|
||||
assert.equal(data.name, 'Metadata');
|
||||
assert.equal(data.fields[0].name, 'Label');
|
||||
assert.equal(data.fields[0].fieldType, 'ContainerRepresentation');
|
||||
});
|
||||
|
||||
it('Get getRestFieldValuesColumn ', async () => {
|
||||
tasksMock.get200getTaskForm();
|
||||
|
||||
const taskId = '2518';
|
||||
const data = await taskFormsApi.getTaskForm(taskId);
|
||||
|
||||
assert.equal(data.name, 'Metadata');
|
||||
assert.equal(data.fields[0].name, 'Label');
|
||||
assert.equal(data.fields[0].fieldType, 'ContainerRepresentation');
|
||||
});
|
||||
|
||||
it('get form field values that are populated through a REST backend', async () => {
|
||||
tasksMock.get200getRestFieldValuesColumn();
|
||||
|
||||
const taskId = '1';
|
||||
const field = 'label';
|
||||
const column = 'user';
|
||||
|
||||
await taskFormsApi.getRestFieldColumnValues(taskId, field, column);
|
||||
});
|
||||
|
||||
it('get form field values that are populated through a REST backend Specific case to retrieve information on a specific column', async () => {
|
||||
tasksMock.get200getRestFieldValues();
|
||||
|
||||
const taskId = '2';
|
||||
const field = 'label';
|
||||
|
||||
await taskFormsApi.getRestFieldValues(taskId, field);
|
||||
});
|
||||
});
|
65
lib/js-api/test/process-services/taskFormApi.spec.ts
Normal file
65
lib/js-api/test/process-services/taskFormApi.spec.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { TaskFormsApi, AlfrescoApi } from '../../src';
|
||||
import { BpmAuthMock, TaskFormMock } from '../mockObjects';
|
||||
|
||||
describe('Activiti Task Api', () => {
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let taskFormMock: TaskFormMock;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
let taskFormsApi: TaskFormsApi;
|
||||
|
||||
beforeEach(async () => {
|
||||
const BPM_HOST = 'https://127.0.0.1:9999';
|
||||
|
||||
authResponseBpmMock = new BpmAuthMock(BPM_HOST);
|
||||
taskFormMock = new TaskFormMock(BPM_HOST);
|
||||
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm: BPM_HOST,
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
taskFormsApi = new TaskFormsApi(alfrescoJsApi);
|
||||
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('get Task Form variables list', async () => {
|
||||
taskFormMock.get200getTaskFormVariables();
|
||||
|
||||
const taskId = '5028';
|
||||
const data = await taskFormsApi.getTaskFormVariables(taskId);
|
||||
|
||||
assert.equal(data[0].id, 'initiator');
|
||||
});
|
||||
|
||||
it('Check cookie settings', async () => {
|
||||
taskFormMock.get200getTaskFormVariables();
|
||||
|
||||
const taskId = '5028';
|
||||
await taskFormsApi.getTaskFormVariables(taskId);
|
||||
assert.equal(
|
||||
(taskFormsApi.apiClient as any).authentications.cookie,
|
||||
'ACTIVITI_REMEMBER_ME=NjdOdGwvcUtFTkVEczQyMGh4WFp5QT09OmpUL1UwdFVBTC94QTJMTFFUVFgvdFE9PQ'
|
||||
);
|
||||
});
|
||||
});
|
54
lib/js-api/test/process-services/userFiltersApi.spec.ts
Normal file
54
lib/js-api/test/process-services/userFiltersApi.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, UserFiltersApi } from '../../src';
|
||||
import { BpmAuthMock, UserFiltersMock } from '../mockObjects';
|
||||
|
||||
describe('Activiti User Filter Api', () => {
|
||||
const hostBpm = 'https://127.0.0.1:9999';
|
||||
let authResponseBpmMock: BpmAuthMock;
|
||||
let filtersMock: UserFiltersMock;
|
||||
let userFiltersApi: UserFiltersApi;
|
||||
|
||||
beforeEach(async () => {
|
||||
authResponseBpmMock = new BpmAuthMock(hostBpm);
|
||||
filtersMock = new UserFiltersMock(hostBpm);
|
||||
|
||||
authResponseBpmMock.get200Response();
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostBpm,
|
||||
provider: 'BPM'
|
||||
});
|
||||
|
||||
userFiltersApi = new UserFiltersApi(alfrescoJsApi);
|
||||
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
it('get filter user', async () => {
|
||||
filtersMock.get200getUserTaskFilters();
|
||||
|
||||
const opts = {
|
||||
appId: 1 // Integer | appId
|
||||
};
|
||||
|
||||
const data = await userFiltersApi.getUserTaskFilters(opts);
|
||||
assert.equal(data.data[0].name, 'Involved Tasks');
|
||||
});
|
||||
});
|
61
lib/js-api/test/searchApi.spec.spec.ts
Normal file
61
lib/js-api/test/searchApi.spec.spec.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { AlfrescoApi, SearchApi } from '../src';
|
||||
import { EcmAuthMock, SearchMock } from './mockObjects';
|
||||
|
||||
describe('Search', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let searchMock: SearchMock;
|
||||
let searchApi: SearchApi;
|
||||
|
||||
beforeEach((done) => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
authResponseMock.get201Response();
|
||||
|
||||
searchMock = new SearchMock(hostEcm);
|
||||
|
||||
const alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
alfrescoJsApi.login('admin', 'admin').then(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
searchApi = new SearchApi(alfrescoJsApi);
|
||||
});
|
||||
|
||||
it('should search works', (done) => {
|
||||
searchMock.get200Response();
|
||||
|
||||
searchApi
|
||||
.search({
|
||||
query: {
|
||||
query: 'select * from cmis:folder',
|
||||
language: 'cmis'
|
||||
}
|
||||
})
|
||||
.then((data) => {
|
||||
assert.equal(data.list.entries[0].entry.name, 'user');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
90
lib/js-api/test/superagentHttpClient.spec.ts
Normal file
90
lib/js-api/test/superagentHttpClient.spec.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { SuperagentHttpClient } from '../src/superagentHttpClient';
|
||||
import { Response } from 'superagent';
|
||||
|
||||
describe('SuperagentHttpClient', () => {
|
||||
describe('#buildRequest', () => {
|
||||
const client = new SuperagentHttpClient();
|
||||
|
||||
it('should create a request with response type blob', () => {
|
||||
const queryParams = {};
|
||||
const headerParams = {};
|
||||
const formParams = {};
|
||||
|
||||
const contentTypes = 'application/json';
|
||||
const accepts = 'application/json';
|
||||
const responseType = 'blob';
|
||||
const url = '/fake-api/enterprise/process-instances/';
|
||||
const httpMethod = 'GET';
|
||||
const securityOptions = {
|
||||
isBpmRequest: false,
|
||||
enableCsrf: false,
|
||||
withCredentials: false,
|
||||
authentications: {
|
||||
basicAuth: {
|
||||
ticket: ''
|
||||
},
|
||||
type: 'basic'
|
||||
},
|
||||
defaultHeaders: {}
|
||||
};
|
||||
|
||||
const response: any = client['buildRequest'](
|
||||
httpMethod,
|
||||
url,
|
||||
queryParams,
|
||||
headerParams,
|
||||
formParams,
|
||||
null,
|
||||
contentTypes,
|
||||
accepts,
|
||||
responseType,
|
||||
null,
|
||||
null,
|
||||
securityOptions
|
||||
);
|
||||
|
||||
assert.equal(response.url, '/fake-api/enterprise/process-instances/');
|
||||
assert.equal(response.header.Accept, 'application/json');
|
||||
assert.equal(response.header['Content-Type'], 'application/json');
|
||||
assert.equal(response._responseType, 'blob');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#deserialize', () => {
|
||||
it('should the deserializer return an array of object when the response is an array', () => {
|
||||
const data = {
|
||||
body: [
|
||||
{
|
||||
id: '1',
|
||||
name: 'test1'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
name: 'test2'
|
||||
}
|
||||
]
|
||||
} as Response;
|
||||
const result = SuperagentHttpClient['deserialize'](data);
|
||||
const isArray = Array.isArray(result);
|
||||
assert.equal(isArray, true);
|
||||
});
|
||||
});
|
||||
});
|
14
lib/js-api/test/tsconfig.json
Normal file
14
lib/js-api/test/tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "node",
|
||||
"target": "ES2015",
|
||||
"esModuleInterop": true,
|
||||
"isolatedModules": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"skipLibCheck": true,
|
||||
"skipDefaultLibCheck": true,
|
||||
"types": ["mocha"]
|
||||
}
|
||||
}
|
327
lib/js-api/test/upload.spec.ts
Normal file
327
lib/js-api/test/upload.spec.ts
Normal file
@@ -0,0 +1,327 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { EcmAuthMock, UploadMock } from './mockObjects';
|
||||
import fs from 'fs';
|
||||
import { UploadApi, AlfrescoApi, NodeEntry } from '../src';
|
||||
|
||||
// eslint-disable-next-line ban/ban
|
||||
xdescribe('Upload', () => {
|
||||
let authResponseMock: EcmAuthMock;
|
||||
let uploadMock: UploadMock;
|
||||
let alfrescoJsApi: AlfrescoApi;
|
||||
let uploadApi: UploadApi;
|
||||
|
||||
beforeEach(async () => {
|
||||
const hostEcm = 'https://127.0.0.1:8080';
|
||||
|
||||
authResponseMock = new EcmAuthMock(hostEcm);
|
||||
uploadMock = new UploadMock(hostEcm);
|
||||
|
||||
authResponseMock.get201Response();
|
||||
alfrescoJsApi = new AlfrescoApi({
|
||||
hostEcm
|
||||
});
|
||||
|
||||
uploadApi = new UploadApi(alfrescoJsApi);
|
||||
|
||||
await alfrescoJsApi.login('admin', 'admin');
|
||||
});
|
||||
|
||||
describe('Upload File', () => {
|
||||
it('upload file should return 200 if is all ok', (done) => {
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
|
||||
uploadApi.uploadFile(file).then((data: NodeEntry) => {
|
||||
assert.equal(data.entry.isFile, true);
|
||||
assert.equal(data.entry.name, 'testFile.txt');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('upload file should get 409 if new name clashes with an existing file in the current parent folder', (done) => {
|
||||
uploadMock.get409CreationFileNewNameClashes();
|
||||
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
|
||||
uploadApi.uploadFile(file).then(
|
||||
() => {},
|
||||
(error: any) => {
|
||||
assert.equal(error.status, 409);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('upload file should get 200 and rename if the new name clashes with an existing file in the current parent folder and autorename is true', (done) => {
|
||||
uploadMock.get201CreationFileAutoRename();
|
||||
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
|
||||
uploadApi.uploadFile(file, null, null, null, { autoRename: true }).then((data: NodeEntry) => {
|
||||
assert.equal(data.entry.isFile, true);
|
||||
assert.equal(data.entry.name, 'testFile-2.txt');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Abort should stop the file file upload', (done) => {
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
|
||||
const promise: any = uploadApi.uploadFile(file, null, null, null, { autoRename: true });
|
||||
promise.once('abort', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
promise.abort();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Events', () => {
|
||||
it('Upload should fire done event at the end of an upload', (done) => {
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
|
||||
const uploadPromise: any = uploadApi.uploadFile(file);
|
||||
|
||||
uploadPromise.catch(() => {});
|
||||
uploadPromise.on('success', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upload should fire error event if something go wrong', (done) => {
|
||||
uploadMock.get409CreationFileNewNameClashes();
|
||||
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
|
||||
const uploadPromise: any = uploadApi.uploadFile(file);
|
||||
uploadPromise.catch(() => {});
|
||||
uploadPromise.on('error', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upload should fire unauthorized event if get 401', (done) => {
|
||||
uploadMock.get401Response();
|
||||
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
|
||||
const uploadPromise: any = uploadApi.uploadFile(file);
|
||||
|
||||
uploadPromise.catch(() => {});
|
||||
uploadPromise.on('unauthorized', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Upload should fire progress event during the upload', (done) => {
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
const uploadPromise: any = uploadApi.uploadFile(file);
|
||||
|
||||
uploadPromise.once('progress', () => done());
|
||||
});
|
||||
|
||||
it('Multiple Upload should fire progress events on the right promise during the upload', (done) => {
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
const fileTwo = fs.createReadStream('./test/mockObjects/assets/testFile2.txt');
|
||||
|
||||
let progressOneOk = false;
|
||||
let progressTwoOk = false;
|
||||
|
||||
const promiseProgressOne = new Promise((resolve) => {
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const promise: any = uploadApi.uploadFile(file);
|
||||
promise.once('success', () => {
|
||||
progressOneOk = true;
|
||||
resolve('Resolving');
|
||||
});
|
||||
});
|
||||
|
||||
const promiseProgressTwo = new Promise((resolve) => {
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const promise: any = uploadApi.uploadFile(fileTwo);
|
||||
promise.once('success', () => {
|
||||
progressTwoOk = true;
|
||||
resolve('Resolving');
|
||||
});
|
||||
});
|
||||
|
||||
Promise.all([promiseProgressOne, promiseProgressTwo]).then(() => {
|
||||
assert.equal(progressOneOk, true);
|
||||
assert.equal(progressTwoOk, true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Multiple Upload should fire error events on the right promise during the upload', (done) => {
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
const fileTwo = fs.createReadStream('./test/mockObjects/assets/testFile2.txt');
|
||||
|
||||
let errorOneOk = false;
|
||||
let errorTwoOk = false;
|
||||
|
||||
const promiseErrorOne = new Promise((resolve) => {
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const uploadPromise: any = uploadApi.uploadFile(file);
|
||||
uploadPromise.catch(() => {});
|
||||
uploadPromise.once('success', () => {
|
||||
errorOneOk = true;
|
||||
resolve('Resolving');
|
||||
});
|
||||
});
|
||||
|
||||
const promiseErrorTwo = new Promise((resolve) => {
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const uploadPromise: any = uploadApi.uploadFile(fileTwo);
|
||||
uploadPromise.catch(() => {});
|
||||
uploadPromise.once('success', () => {
|
||||
errorTwoOk = true;
|
||||
resolve('Resolving');
|
||||
});
|
||||
});
|
||||
|
||||
Promise.all([promiseErrorOne, promiseErrorTwo]).then(() => {
|
||||
assert.equal(errorOneOk, true);
|
||||
assert.equal(errorTwoOk, true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Multiple Upload should fire success events on the right promise during the upload', (done) => {
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
const fileTwo = fs.createReadStream('./test/mockObjects/assets/testFile2.txt');
|
||||
|
||||
let successOneOk = false;
|
||||
let successTwoOk = false;
|
||||
|
||||
const promiseSuccessOne = new Promise((resolve) => {
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const uploadPromiseOne: any = uploadApi.uploadFile(file);
|
||||
uploadPromiseOne.catch(() => {});
|
||||
uploadPromiseOne.once('success', () => {
|
||||
successOneOk = true;
|
||||
resolve('Resolving');
|
||||
});
|
||||
});
|
||||
|
||||
const promiseSuccessTwo = new Promise((resolve) => {
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const uploadPromiseTwo: any = uploadApi.uploadFile(fileTwo);
|
||||
uploadPromiseTwo.catch(() => {});
|
||||
uploadPromiseTwo.once('success', () => {
|
||||
successTwoOk = true;
|
||||
resolve('Resolving');
|
||||
});
|
||||
});
|
||||
|
||||
Promise.all([promiseSuccessOne, promiseSuccessTwo]).then(() => {
|
||||
assert.equal(successOneOk, true);
|
||||
assert.equal(successTwoOk, true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Multiple Upload should resolve the correct promise', (done) => {
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
const fileTwo = fs.createReadStream('./test/mockObjects/assets/testFile2.txt');
|
||||
|
||||
let resolveOneOk = false;
|
||||
let resolveTwoOk = false;
|
||||
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const p1 = uploadApi.uploadFile(file).then(() => {
|
||||
resolveOneOk = true;
|
||||
});
|
||||
|
||||
uploadMock.get201CreationFile();
|
||||
|
||||
const p2 = uploadApi.uploadFile(fileTwo).then(() => {
|
||||
resolveTwoOk = true;
|
||||
});
|
||||
|
||||
Promise.all([p1, p2]).then(() => {
|
||||
assert.equal(resolveOneOk, true);
|
||||
assert.equal(resolveTwoOk, true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Multiple Upload should reject the correct promise', (done) => {
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
const fileTwo = fs.createReadStream('./test/mockObjects/assets/testFile2.txt');
|
||||
|
||||
let rejectOneOk = false;
|
||||
let rejectTwoOk = false;
|
||||
|
||||
uploadMock.get409CreationFileNewNameClashes();
|
||||
|
||||
const p1 = uploadApi.uploadFile(file).then(null, () => {
|
||||
rejectOneOk = true;
|
||||
});
|
||||
|
||||
uploadMock.get409CreationFileNewNameClashes();
|
||||
|
||||
const p2 = uploadApi.uploadFile(fileTwo).then(null, () => {
|
||||
rejectTwoOk = true;
|
||||
});
|
||||
|
||||
Promise.all([p1, p2]).then(() => {
|
||||
assert.equal(rejectOneOk, true);
|
||||
assert.equal(rejectTwoOk, true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Is possible use chain events', (done) => {
|
||||
const file = fs.createReadStream('./test/mockObjects/assets/testFile.txt');
|
||||
|
||||
uploadMock.get401Response();
|
||||
|
||||
let promiseProgressOne = {};
|
||||
let promiseProgressTwo = {};
|
||||
|
||||
const uploadPromise: any = uploadApi.uploadFile(file);
|
||||
uploadPromise.catch(() => {});
|
||||
|
||||
uploadPromise
|
||||
.once('error', () => {
|
||||
promiseProgressOne = Promise.resolve('Resolving');
|
||||
})
|
||||
.once('unauthorized', () => {
|
||||
promiseProgressTwo = Promise.resolve('Resolving');
|
||||
});
|
||||
|
||||
Promise.all([promiseProgressOne, promiseProgressTwo]).then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user