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:
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user