migrate js-api tests from Jest to Node.js native test runner (#12104)

This commit is contained in:
Denys Vuika
2026-07-28 20:04:31 +01:00
committed by GitHub
parent c316c6b594
commit 6c8b874704
58 changed files with 2355 additions and 4978 deletions
@@ -16,15 +16,17 @@
*/
import assert from 'assert';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { AlfrescoApi, CategoriesApi, CategoryPaging, CategoryEntry } from '../../src';
import { EcmAuthMock, CategoriesMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('Categories', () => {
let authResponseMock: EcmAuthMock;
let categoriesMock: CategoriesMock;
let categoriesApi: CategoriesApi;
beforeEach((done) => {
beforeEach(async () => {
const hostEcm = 'https://127.0.0.1:8080';
authResponseMock = new EcmAuthMock(hostEcm);
@@ -35,229 +37,211 @@ describe('Categories', () => {
hostEcm
});
alfrescoJsApi.login('admin', 'admin').then(() => done());
await alfrescoJsApi.login('admin', 'admin');
categoriesApi = new CategoriesApi(alfrescoJsApi);
});
it('should return 200 while getting subcategories for category with categoryId if all is ok', (done) => {
afterEach(() => {
resetGlobalMockAgent();
});
it('should return 200 while getting subcategories for category with categoryId if all is ok', async () => {
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();
});
const response: CategoryPaging = await categoriesApi.getSubcategories('-root-');
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');
});
it('should return 404 while getting subcategories for not existing category', (done) => {
it('should return 404 while getting subcategories for not existing category', async () => {
categoriesMock.get404SubcategoryNotExist('notExistingId');
categoriesApi.getSubcategories('notExistingId').then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 404);
done();
}
);
try {
await categoriesApi.getSubcategories('notExistingId');
assert.fail('Expected getSubcategories to reject with 404');
} catch (error: any) {
assert.equal(error.status, 404);
}
});
it('should return 200 while getting category with categoryId if category exists', (done) => {
it('should return 200 while getting category with categoryId if category exists', async () => {
categoriesMock.get200ResponseCategory('testId1');
categoriesApi.getCategory('testId1').then((response: CategoryEntry) => {
assert.equal(response.entry.parentId, '-root-');
assert.equal(response.entry.id, 'testId1');
done();
});
const response: CategoryEntry = await categoriesApi.getCategory('testId1');
assert.equal(response.entry.parentId, '-root-');
assert.equal(response.entry.id, 'testId1');
});
it('should return 404 while getting category with categoryId when category not exists', (done) => {
it('should return 404 while getting category with categoryId when category not exists', async () => {
categoriesMock.get404CategoryNotExist('notExistingId');
categoriesApi.getCategory('notExistingId').then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 404);
done();
}
);
try {
await categoriesApi.getCategory('notExistingId');
assert.fail('Expected getCategory to reject with 404');
} catch (error: any) {
assert.equal(error.status, 404);
}
});
it('should return 200 while getting categories linked to node with nodeId if node has some categories assigned', (done) => {
it('should return 200 while getting categories linked to node with nodeId if node has some categories assigned', async () => {
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();
});
const response: CategoryPaging = await categoriesApi.getCategoryLinksForNode('testNode');
assert.equal(response.list.entries[0].entry.parentId, 'testNode');
assert.equal(response.list.entries[0].entry.id, 'testId1');
});
it('should return 403 while getting categories linked to node with nodeId if user has no rights to get from node', (done) => {
it('should return 403 while getting categories linked to node with nodeId if user has no rights to get from node', async () => {
categoriesMock.get403NodeCategoryLinksPermissionDenied('testNode');
categoriesApi.getCategoryLinksForNode('testNode').then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 403);
done();
}
);
try {
await categoriesApi.getCategoryLinksForNode('testNode');
assert.fail('Expected getCategoryLinksForNode to reject with 403');
} catch (error: any) {
assert.equal(error.status, 403);
}
});
it('should return 404 while getting categories linked to node with nodeId if node does not exist', (done) => {
it('should return 404 while getting categories linked to node with nodeId if node does not exist', async () => {
categoriesMock.get404NodeNotExist('testNode');
categoriesApi.getCategoryLinksForNode('testNode').then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 404);
done();
}
);
try {
await categoriesApi.getCategoryLinksForNode('testNode');
assert.fail('Expected getCategoryLinksForNode to reject with 404');
} catch (error: any) {
assert.equal(error.status, 404);
}
});
it('should return 204 after unlinking category', (done) => {
it('should return 204 after unlinking category', async () => {
categoriesMock.get204CategoryUnlinked('testNode', 'testId1');
categoriesApi.unlinkNodeFromCategory('testNode', 'testId1').then(() => {
done();
});
let unlinkedSuccessfully = false;
try {
await categoriesApi.unlinkNodeFromCategory('testNode', 'testId1');
unlinkedSuccessfully = true;
} catch {
assert.fail('Expected unlinkNodeFromCategory to succeed');
}
assert.equal(unlinkedSuccessfully, true, 'Unlink operation should complete successfully');
});
it('should return 404 while unlinking category if category with categoryId or node with nodeId does not exist', (done) => {
it('should return 404 while unlinking category if category with categoryId or node with nodeId does not exist', async () => {
categoriesMock.get404CategoryUnlinkNotFound('testNode', 'testId1');
categoriesApi.unlinkNodeFromCategory('testNode', 'testId1').then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 404);
done();
}
);
try {
await categoriesApi.unlinkNodeFromCategory('testNode', 'testId1');
assert.fail('Expected unlinkNodeFromCategory to reject with 404');
} catch (error: any) {
assert.equal(error.status, 404);
}
});
it('should return 403 while unlinking category if user has no rights to unlink', (done) => {
it('should return 403 while unlinking category if user has no rights to unlink', async () => {
categoriesMock.get403CategoryUnlinkPermissionDenied('testNode', 'testId1');
categoriesApi.unlinkNodeFromCategory('testNode', 'testId1').then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 403);
done();
}
);
try {
await categoriesApi.unlinkNodeFromCategory('testNode', 'testId1');
assert.fail('Expected unlinkNodeFromCategory to reject with 403');
} catch (error: any) {
assert.equal(error.status, 403);
}
});
it('should return 200 while updating category if all is ok', (done) => {
it('should return 200 while updating category if all is ok', async () => {
categoriesMock.get200ResponseCategoryUpdated('testId1');
categoriesApi.updateCategory('testId1', { name: 'testName1' }).then((response) => {
const response = await categoriesApi.updateCategory('testId1', { name: 'testName1' });
assert.equal(response.entry.id, 'testId1');
assert.equal(response.entry.name, 'testName1');
});
it('should return 404 while updating category if category with categoryId does not exist', async () => {
categoriesMock.get404CategoryUpdateNotFound('testId1');
try {
await categoriesApi.updateCategory('testId1', { name: 'testName1' });
assert.fail('Expected updateCategory to reject with 404');
} catch (error: any) {
assert.equal(error.status, 404);
}
});
it('should return 403 while updating category if user has no rights to update', async () => {
categoriesMock.get403CategoryUpdatePermissionDenied('testId1');
try {
await categoriesApi.updateCategory('testId1', { name: 'testName1' });
assert.fail('Expected updateCategory to reject with 403');
} catch (error: any) {
assert.equal(error.status, 403);
}
});
it('should return 201 while creating category if all is ok', async () => {
categoriesMock.get201ResponseCategoryCreated('testId1');
const response: CategoryPaging | CategoryEntry = await categoriesApi.createSubcategories('testId1', [{ name: 'testName10' }]);
assert.equal((response as CategoryEntry).entry.parentId, 'testId1');
assert.equal((response as CategoryEntry).entry.name, 'testName10');
});
it('should return 409 while creating subcategory if subcategory already exists', async () => {
categoriesMock.get409CategoryCreateAlreadyExists('testId1');
try {
await categoriesApi.createSubcategories('testId1', [{ name: 'testName10' }]);
assert.fail('Expected createSubcategories to reject with 409');
} catch (error: any) {
assert.equal(error.status, 409);
}
});
it('should return 403 while creating category if user has no rights to create', async () => {
categoriesMock.get403CategoryCreatedPermissionDenied('testId1');
try {
await categoriesApi.createSubcategories('testId1', [{ name: 'testName10' }]);
assert.fail('Expected createSubcategories to reject with 403');
} catch (error: any) {
assert.equal(error.status, 403);
}
});
it('should return 201 while linking category if all is ok', async () => {
categoriesMock.get201ResponseCategoryLinked('testNode');
const response = await categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]);
if (response instanceof CategoryEntry) {
assert.equal(response.entry.id, 'testId1');
assert.equal(response.entry.name, 'testName1');
done();
});
} else {
assert.fail('Expected CategoryEntry response');
}
});
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) => {
it('should return 201 while linking multiple categories if all is ok', async () => {
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();
});
const response = await categoriesApi.linkNodeToCategory('testNodeArr', [{ categoryId: 'testId1' }, { categoryId: 'testId2' }]);
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');
});
it('should return 404 while linking category if node with nodeId or category with categoryId does not exist', (done) => {
it('should return 404 while linking category if node with nodeId or category with categoryId does not exist', async () => {
categoriesMock.get404CategoryLinkNotFound('testNode');
categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]).then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 404);
done();
}
);
try {
await categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]);
assert.fail('Expected linkNodeToCategory to reject with 404');
} catch (error: any) {
assert.equal(error.status, 404);
}
});
it('should return 403 while linking category if user has no rights to link', (done) => {
it('should return 403 while linking category if user has no rights to link', async () => {
categoriesMock.get403CategoryLinkPermissionDenied('testNode');
categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]).then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 403);
done();
}
);
try {
await categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]);
assert.fail('Expected linkNodeToCategory to reject with 403');
} catch (error: any) {
assert.equal(error.status, 403);
}
});
it('should return 405 while linking category if node of this type cannot be assigned to category', (done) => {
it('should return 405 while linking category if node of this type cannot be assigned to category', async () => {
categoriesMock.get405CategoryLinkCannotAssign('testNode');
categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]).then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 405);
done();
}
);
try {
await categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]);
assert.fail('Expected linkNodeToCategory to reject with 405');
} catch (error: any) {
assert.equal(error.status, 405);
}
});
});
@@ -16,15 +16,17 @@
*/
import assert from 'assert';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { AlfrescoApi, CommentsApi } from '../../src';
import { CommentMock, EcmAuthMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('Comments', () => {
let authResponseMock: EcmAuthMock;
let commentMock: CommentMock;
let commentsApi: CommentsApi;
beforeEach((done) => {
beforeEach(async () => {
const hostEcm = 'https://127.0.0.1:8080';
authResponseMock = new EcmAuthMock(hostEcm);
@@ -38,30 +40,26 @@ describe('Comments', () => {
commentsApi = new CommentsApi(alfrescoJsApi);
alfrescoJsApi.login('admin', 'admin').then(() => {
done();
});
await alfrescoJsApi.login('admin', 'admin');
});
it('should add a comment', (done) => {
afterEach(() => {
resetGlobalMockAgent();
});
it('should add a comment', async () => {
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();
});
const data = await commentsApi.createComment('74cd8a96-8a21-47e5-9b3b-a1b3e296787d', {
content: 'This is a comment'
});
assert.equal(data.entry.content, 'This is a comment');
});
it('should get a comment', (done) => {
it('should get a comment', async () => {
commentMock.get200Response();
commentsApi.listComments('74cd8a96-8a21-47e5-9b3b-a1b3e296787d').then((data) => {
assert.equal(data.list.entries[0].entry.content, 'This is another comment');
done();
});
const data = await commentsApi.listComments('74cd8a96-8a21-47e5-9b3b-a1b3e296787d');
assert.equal(data.list.entries[0].entry.content, 'This is another comment');
});
});
@@ -16,14 +16,18 @@
*/
import { AlfrescoApi, CustomModelApi } from '../../src';
import assert from 'assert';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { EcmAuthMock, CustomModelMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('Custom Model Api', () => {
let authResponseMock: EcmAuthMock;
let customModelMock: CustomModelMock;
let customModelApi: CustomModelApi;
beforeEach((done) => {
beforeEach(async () => {
const hostEcm = 'https://127.0.0.1:8080';
authResponseMock = new EcmAuthMock(hostEcm);
@@ -35,25 +39,26 @@ describe('Custom Model Api', () => {
hostEcm
});
alfrescoJsApi.login('admin', 'admin').then(() => {
done();
});
await alfrescoJsApi.login('admin', 'admin');
customModelApi = new CustomModelApi(alfrescoJsApi);
});
afterEach(() => {
resetGlobalMockAgent();
});
describe('Get', () => {
it('All Custom Model', (done) => {
it('All Custom Model', async () => {
customModelMock.get200AllCustomModel();
customModelApi.getAllCustomModel().then(() => {
done();
}, console.error);
const result = await customModelApi.getAllCustomModel();
assert.ok(result, 'getAllCustomModel should return a result');
});
});
describe('Create', () => {
it('createCustomModel', (done) => {
it('createCustomModel', async () => {
customModelMock.create201CustomModel();
const status = 'DRAFT';
@@ -62,19 +67,18 @@ describe('Custom Model Api', () => {
const namespaceUri = 'https://www.alfresco.org/model/testNamespace/1.0';
const namespacePrefix = 'test';
customModelApi.createCustomModel(status, description, name, namespaceUri, namespacePrefix).then(() => {
done();
}, console.error);
const result = await customModelApi.createCustomModel(status, description, name, namespaceUri, namespacePrefix);
assert.ok(result, 'createCustomModel should return a result');
assert.equal(result.entry.name, name, 'Created model should have correct name');
});
});
describe('PUT', () => {
it('activateCustomModel', (done) => {
it('activateCustomModel', async () => {
customModelMock.activateCustomModel200();
customModelApi.activateCustomModel('testModel').then(() => {
done();
}, console.error);
const result = await customModelApi.activateCustomModel('testModel');
assert.ok(result, 'activateCustomModel should return a result');
});
});
});
@@ -16,15 +16,17 @@
*/
import assert from 'assert';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { AlfrescoApi, GroupsApi } from '../../src';
import { EcmAuthMock, GroupsMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('Groups', () => {
let authResponseMock: EcmAuthMock;
let groupsMock: GroupsMock;
let groupsApi: GroupsApi;
beforeEach((done) => {
beforeEach(async () => {
const hostEcm = 'https://127.0.0.1:8080';
authResponseMock = new EcmAuthMock(hostEcm);
@@ -35,25 +37,25 @@ describe('Groups', () => {
hostEcm
});
alfrescoJsApi.login('admin', 'admin').then(() => {
done();
});
await alfrescoJsApi.login('admin', 'admin');
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();
});
afterEach(() => {
resetGlobalMockAgent();
});
it('create group', (done) => {
it('get groups', async () => {
groupsMock.get200GetGroups();
const data = await groupsApi.listGroups();
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');
});
it('create group', async () => {
groupsMock.get200CreateGroupResponse();
const groupBody = {
@@ -61,55 +63,46 @@ describe('Groups', () => {
displayName: 'SAMPLE'
};
groupsApi.createGroup(groupBody).then((data) => {
assert.equal(data.entry.id, 'GROUP_TEST');
done();
});
const data = await groupsApi.createGroup(groupBody);
assert.equal(data.entry.id, 'GROUP_TEST');
});
it('delete group', (done) => {
it('delete group', async () => {
groupsMock.getDeleteGroupSuccessfulResponse('group_test');
groupsApi.deleteGroup('group_test').then(() => {
done();
});
const result = await groupsApi.deleteGroup('group_test');
assert.ok(result !== undefined, 'deleteGroup should complete successfully');
});
it('get single group', (done) => {
it('get single group', async () => {
groupsMock.get200GetSingleGroup();
groupsApi.getGroup('GROUP_TEST').then((data) => {
assert.equal(data.entry.id, 'GROUP_TEST');
assert.equal(data.entry.displayName, 'SAMPLE');
done();
});
const data = await groupsApi.getGroup('GROUP_TEST');
assert.equal(data.entry.id, 'GROUP_TEST');
assert.equal(data.entry.displayName, 'SAMPLE');
});
it('update group', (done) => {
it('update group', async () => {
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();
});
const data = await groupsApi.updateGroup('GROUP_TEST', groupBody);
assert.equal(data.entry.id, 'GROUP_TEST');
assert.equal(data.entry.displayName, 'CHANGED');
});
it('get group members', (done) => {
it('get group members', async () => {
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();
});
const data = await groupsApi.listGroupMemberships('GROUP_TEST');
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');
});
it('add group member', (done) => {
it('add group member', async () => {
groupsMock.get200AddGroupMembershipResponse();
const groupBody = {
@@ -117,17 +110,14 @@ describe('Groups', () => {
memberType: 'GROUP'
};
groupsApi.createGroupMembership('GROUP_TEST', groupBody).then((data) => {
assert.equal(data.entry.id, 'GROUP_SUB_TEST');
assert.equal(data.entry.displayName, 'SAMPLE');
done();
});
const data = await groupsApi.createGroupMembership('GROUP_TEST', groupBody);
assert.equal(data.entry.id, 'GROUP_SUB_TEST');
assert.equal(data.entry.displayName, 'SAMPLE');
});
it('delete group member', (done) => {
it('delete group member', async () => {
groupsMock.getDeleteMemberForGroupSuccessfulResponse('GROUP_TEST', 'GROUP_SUB_TEST');
groupsApi.deleteGroupMembership('GROUP_TEST', 'GROUP_SUB_TEST').then(() => {
done();
});
const result = await groupsApi.deleteGroupMembership('GROUP_TEST', 'GROUP_SUB_TEST');
assert.ok(result !== undefined, 'deleteGroupMembership should complete successfully');
});
});
@@ -16,15 +16,17 @@
*/
import assert from 'assert';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { AlfrescoApi, NodesApi } from '../../src';
import { EcmAuthMock, NodeMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('Node', () => {
let authResponseMock: EcmAuthMock;
let nodeMock: NodeMock;
let nodesApi: NodesApi;
beforeEach((done) => {
beforeEach(async () => {
const hostEcm = 'https://127.0.0.1:8080';
authResponseMock = new EcmAuthMock(hostEcm);
@@ -36,94 +38,85 @@ describe('Node', () => {
hostEcm
});
alfrescoJsApi.login('admin', 'admin').then(() => {
done();
});
await alfrescoJsApi.login('admin', 'admin');
nodesApi = new NodesApi(alfrescoJsApi);
});
afterEach(() => {
resetGlobalMockAgent();
});
describe('Get Children Node', () => {
it('information for the node with identifier nodeId should return 200 if is all ok', (done) => {
it('information for the node with identifier nodeId should return 200 if is all ok', async () => {
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();
});
const data = await nodesApi.listNodeChildren('b4cff62a-664d-4d45-9302-98723eac1319');
assert.equal(data.list.pagination.count, 5);
assert.equal(data.list.entries[0].entry.name, 'dataLists');
});
it('information for the node with identifier nodeId should return 404 if the id is does not exist', (done) => {
it('information for the node with identifier nodeId should return 404 if the id is does not exist', async () => {
nodeMock.get404ChildrenNotExist();
nodesApi.listNodeChildren('b4cff62a-664d-4d45-9302-98723eac1319').then(
() => {},
(error) => {
assert.equal(error.status, 404);
done();
}
);
try {
await nodesApi.listNodeChildren('b4cff62a-664d-4d45-9302-98723eac1319');
} catch (error: any) {
assert.equal(error.status, 404);
}
});
it('dynamic augmenting object parameters', (done) => {
it('dynamic augmenting object parameters', async () => {
nodeMock.get200ResponseChildrenFutureNewPossibleValue();
nodesApi.listNodeChildren('b4cff62a-664d-4d45-9302-98723eac1319').then((data: any) => {
assert.equal(data.list.entries[0].entry.impossibleProperties, 'impossibleRightValue');
done();
});
const data: any = await nodesApi.listNodeChildren('b4cff62a-664d-4d45-9302-98723eac1319');
assert.equal(data.list.entries[0].entry.impossibleProperties, 'impossibleRightValue');
});
it('should return dates as timezone-aware', (done) => {
it('should return dates as timezone-aware', async () => {
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();
});
const data = await nodesApi.listNodeChildren('b4cff62a-664d-4d45-9302-98723eac1320');
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);
});
});
describe('Delete', () => {
it('delete the node with identifier nodeId', (done) => {
it('delete the node with identifier nodeId', async () => {
nodeMock.get204SuccessfullyDeleted();
nodesApi.deleteNode('80a94ac8-3ece-47ad-864e-5d939424c47c').then(() => {
done();
});
const result = await nodesApi.deleteNode('80a94ac8-3ece-47ad-864e-5d939424c47c');
assert.ok(result !== undefined, 'deleteNode should complete successfully');
});
it('delete the node with identifier nodeId should return 404 if the id is does not exist', (done) => {
it('delete the node with identifier nodeId should return 404 if the id is does not exist', async () => {
nodeMock.get404DeleteNotFound();
nodesApi.deleteNode('80a94ac8-test-47ad-864e-5d939424c47c').then(
() => {},
(error) => {
assert.equal(error.status, 404);
done();
}
);
try {
await nodesApi.deleteNode('80a94ac8-test-47ad-864e-5d939424c47c');
} catch (error: any) {
assert.equal(error.status, 404);
}
});
it('delete the node with identifier nodeId should return 403 if current user does not have permission to delete', (done) => {
it('delete the node with identifier nodeId should return 403 if current user does not have permission to delete', async () => {
nodeMock.get403DeletePermissionDenied();
nodesApi.deleteNode('80a94ac8-3ece-47ad-864e-5d939424c47c').then(
() => {},
() => {
done();
}
);
try {
await nodesApi.deleteNode('80a94ac8-3ece-47ad-864e-5d939424c47c');
assert.fail('Expected deleteNode to throw error on 403 response');
} catch (error: any) {
assert.equal(error.status, 403, 'Error should have 403 status');
}
});
});
describe('Delete nodes', () => {
it('should call deleteNode for every id in the given array', (done) => {
it('should call deleteNode for every id in the given array', async () => {
let calls = 0;
nodesApi.deleteNode = () => {
@@ -131,78 +124,67 @@ describe('Node', () => {
return Promise.resolve();
};
nodesApi.deleteNodes(['80a94ac8-3ece-47ad-864e-5d939424c47c', '80a94ac8-3ece-47ad-864e-5d939424c47d']).then(() => {
assert.equal(calls, 2);
done();
});
await nodesApi.deleteNodes(['80a94ac8-3ece-47ad-864e-5d939424c47c', '80a94ac8-3ece-47ad-864e-5d939424c47d']);
assert.equal(calls, 2);
});
it('should return throw an error if one of the promises fails', (done) => {
it('should return throw an error if one of the promises fails', async () => {
nodeMock.get204SuccessfullyDeleted();
nodeMock.get404DeleteNotFound();
nodesApi.deleteNodes(['80a94ac8-3ece-47ad-864e-5d939424c47c', '80a94ac8-test-47ad-864e-5d939424c47c']).then(
() => {},
(error) => {
assert.equal(error.status, 404);
done();
}
);
try {
await nodesApi.deleteNodes(['80a94ac8-3ece-47ad-864e-5d939424c47c', '80a94ac8-test-47ad-864e-5d939424c47c']);
assert.fail('Expected deleteNodes to throw error when one deletion fails');
} catch (error: any) {
assert.equal(error.status, 404, 'Error should have 404 status from failed deletion');
}
});
});
describe('FolderInformation', () => {
it('should return jobId on initiateFolderSizeCalculation API call if everything is ok', (done) => {
it('should return jobId on initiateFolderSizeCalculation API call if everything is ok', async () => {
nodeMock.post200ResponseInitiateFolderSizeCalculation();
nodesApi.initiateFolderSizeCalculation('b4cff62a-664d-4d45-9302-98723eac1319').then((response) => {
assert.equal(response.entry.jobId, '5ade426e-8a04-4d50-9e42-6e8a041d50f3');
done();
});
const response = await nodesApi.initiateFolderSizeCalculation('b4cff62a-664d-4d45-9302-98723eac1319');
assert.equal(response.entry.jobId, '5ade426e-8a04-4d50-9e42-6e8a041d50f3');
});
it('should return 404 error on initiateFolderSizeCalculation API call if nodeId is not found', (done) => {
it('should return 404 error on initiateFolderSizeCalculation API call if nodeId is not found', async () => {
nodeMock.post404NodeIdNotFound();
nodesApi.initiateFolderSizeCalculation('b4cff62a-664d-4d45-9302-98723eac1319').then(
() => {},
(err) => {
const { error } = JSON.parse(err.message);
assert.equal(error.statusCode, 404);
assert.equal(error.errorKey, 'framework.exception.EntityNotFound');
assert.equal(error.briefSummary, '11207522 The entity with id: b4cff62a-664d-4d45-9302-98723eac1319 was not found');
done();
}
);
try {
await nodesApi.initiateFolderSizeCalculation('b4cff62a-664d-4d45-9302-98723eac1319');
} catch (err: any) {
const { error } = JSON.parse(err.message);
assert.equal(error.statusCode, 404);
assert.equal(error.errorKey, 'framework.exception.EntityNotFound');
assert.equal(error.briefSummary, '11207522 The entity with id: b4cff62a-664d-4d45-9302-98723eac1319 was not found');
}
});
it('should return size details on getFolderSizeInfo API call if everything is ok', (done) => {
it('should return size details on getFolderSizeInfo API call if everything is ok', async () => {
nodeMock.get200ResponseGetFolderSizeInfo();
nodesApi.getFolderSizeInfo('b4cff62a-664d-4d45-9302-98723eac1319', '5ade426e-8a04-4d50-9e42-6e8a041d50f3').then((response) => {
assert.equal(response.entry.id, '32e522f1-1f28-4ea3-a522-f11f284ea397');
assert.equal(response.entry.jobId, '5ade426e-8a04-4d50-9e42-6e8a041d50f3');
assert.equal(response.entry.sizeInBytes, 2689);
assert.equal(response.entry.numberOfFiles, 100);
assert.equal(response.entry.calculatedAt, '2024-12-20T12:02:23.989+0000');
assert.equal(response.entry.status, 'COMPLETED');
done();
});
const response = await nodesApi.getFolderSizeInfo('b4cff62a-664d-4d45-9302-98723eac1319', '5ade426e-8a04-4d50-9e42-6e8a041d50f3');
assert.equal(response.entry.id, '32e522f1-1f28-4ea3-a522-f11f284ea397');
assert.equal(response.entry.jobId, '5ade426e-8a04-4d50-9e42-6e8a041d50f3');
assert.equal(response.entry.sizeInBytes, 2689);
assert.equal(response.entry.numberOfFiles, 100);
assert.equal(response.entry.calculatedAt, '2024-12-20T12:02:23.989+0000');
assert.equal(response.entry.status, 'COMPLETED');
});
it('should return 404 error on getFolderSizeInfo API call if jobId is not found', (done) => {
it('should return 404 error on getFolderSizeInfo API call if jobId is not found', async () => {
nodeMock.get404JobIdNotFound();
nodesApi.getFolderSizeInfo('b4cff62a-664d-4d45-9302-98723eac1319', '5ade426e-8a04-4d50-9e42-6e8a041d50f3').then(
() => {},
(err) => {
const { error } = JSON.parse(err.message);
assert.equal(error.statusCode, 404);
assert.equal(error.errorKey, 'jobId does not exist');
assert.equal(error.briefSummary, '11207212 jobId does not exist');
done();
}
);
try {
await nodesApi.getFolderSizeInfo('b4cff62a-664d-4d45-9302-98723eac1319', '5ade426e-8a04-4d50-9e42-6e8a041d50f3');
} catch (err: any) {
const { error } = JSON.parse(err.message);
assert.equal(error.statusCode, 404);
assert.equal(error.errorKey, 'jobId does not exist');
assert.equal(error.briefSummary, '11207212 jobId does not exist');
}
});
});
});
@@ -16,14 +16,17 @@
*/
import { AlfrescoApi, PersonBodyCreate, PeopleApi } from '../../src';
import assert from 'assert';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { EcmAuthMock, PeopleMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('PeopleApi', () => {
let authResponseMock: EcmAuthMock;
let peopleMock: PeopleMock;
let peopleApi: PeopleApi;
beforeEach((done) => {
beforeEach(async () => {
const hostEcm = 'https://127.0.0.1:8080';
authResponseMock = new EcmAuthMock(hostEcm);
@@ -34,14 +37,16 @@ describe('PeopleApi', () => {
hostEcm
});
alfrescoJsApi.login('admin', 'admin').then(() => {
done();
});
await alfrescoJsApi.login('admin', 'admin');
peopleApi = new PeopleApi(alfrescoJsApi);
});
it('should add a person', (done) => {
afterEach(() => {
resetGlobalMockAgent();
});
it('should add a person', async () => {
peopleMock.get201Response();
const payload: PersonBodyCreate = {
@@ -52,21 +57,14 @@ describe('PeopleApi', () => {
password: 'Rrrrrrrghghghghgh'
};
peopleApi.createPerson(payload).then(() => {
done();
});
const result = await peopleApi.createPerson(payload);
assert.ok(result, 'createPerson should return a result');
});
it('should get list of people', (done) => {
it('should get list of people', async () => {
peopleMock.get200ResponsePersons();
peopleApi.listPeople().then(
() => {
done();
},
(err) => {
done(new Error('listPeople rejected: ' + JSON.stringify(err)));
}
);
const data = await peopleApi.listPeople();
assert.ok(data, 'listPeople should return data');
});
});
@@ -16,15 +16,17 @@
*/
import assert from 'assert';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { AlfrescoApi, QueriesApi } from '../../src';
import { EcmAuthMock, FindNodesMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('Queries', () => {
let authResponseMock: EcmAuthMock;
let nodesMock: FindNodesMock;
let queriesApi: QueriesApi;
beforeEach((done) => {
beforeEach(async () => {
const hostEcm = 'https://127.0.0.1:8080';
authResponseMock = new EcmAuthMock(hostEcm);
@@ -36,13 +38,15 @@ describe('Queries', () => {
hostEcm
});
alfrescoJsApi.login('admin', 'admin').then(() => {
done();
});
await alfrescoJsApi.login('admin', 'admin');
queriesApi = new QueriesApi(alfrescoJsApi);
});
afterEach(() => {
resetGlobalMockAgent();
});
describe('nodes', () => {
const searchTerm = 'test';
@@ -52,26 +56,24 @@ describe('Queries', () => {
}, `Error: Missing param 'term'`);
});
it('should invoke error handler on a server error', (done) => {
it('should invoke error handler on a server error', async () => {
nodesMock.get401Response();
queriesApi.findNodes(searchTerm).then(
() => {},
() => {
done();
}
);
try {
await queriesApi.findNodes(searchTerm);
assert.fail('Expected findNodes to throw error on 401 response');
} catch (error: any) {
assert.equal(error.status, 401, 'Error should have 401 status');
}
});
it('should return query results', (done) => {
it('should return query results', async () => {
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();
});
const data = await queriesApi.findNodes(searchTerm);
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');
});
});
});
@@ -16,15 +16,17 @@
*/
import assert from 'assert';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { AlfrescoApi, RenditionsApi } from '../../src';
import { EcmAuthMock, RenditionMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('Rendition', () => {
let authResponseMock: EcmAuthMock;
let renditionMock: RenditionMock;
let renditionsApi: RenditionsApi;
beforeEach((done) => {
beforeEach(async () => {
const hostEcm = 'https://127.0.0.1:8080';
authResponseMock = new EcmAuthMock(hostEcm);
@@ -36,37 +38,34 @@ describe('Rendition', () => {
hostEcm
});
alfrescoJsApi.login('admin', 'admin').then(() => {
done();
});
await alfrescoJsApi.login('admin', 'admin');
renditionsApi = new RenditionsApi(alfrescoJsApi);
});
it('Get Rendition', (done) => {
afterEach(() => {
resetGlobalMockAgent();
});
it('Get Rendition', async () => {
renditionMock.get200RenditionResponse();
renditionsApi.getRendition('97a29e9c-1e4f-4d9d-bb02-1ec920dda045', 'pdf').then((data) => {
assert.equal(data.entry.id, 'pdf');
done();
});
const data = await renditionsApi.getRendition('97a29e9c-1e4f-4d9d-bb02-1ec920dda045', 'pdf');
assert.equal(data.entry.id, 'pdf');
});
it('Create Rendition', (done) => {
it('Create Rendition', async () => {
renditionMock.createRendition200();
renditionsApi.createRendition('97a29e9c-1e4f-4d9d-bb02-1ec920dda045', { id: 'pdf' }).then(() => {
done();
});
const result = await renditionsApi.createRendition('97a29e9c-1e4f-4d9d-bb02-1ec920dda045', { id: 'pdf' });
assert.ok(result, 'createRendition should return a result');
});
it('Get Renditions list for node id', (done) => {
it('Get Renditions list for node id', async () => {
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();
});
const data = await renditionsApi.listRenditions('97a29e9c-1e4f-4d9d-bb02-1ec920dda045');
assert.equal(data.list.pagination.count, 6);
assert.equal(data.list.entries[0].entry.id, 'avatar');
});
});
+51 -64
View File
@@ -16,15 +16,17 @@
*/
import assert from 'assert';
import { AlfrescoApi, TagBody, TagEntry, TagPaging, TagsApi } from '../../src';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { AlfrescoApi, TagBody, TagEntry, TagsApi } from '../../src';
import { EcmAuthMock, TagMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('Tags', () => {
let authResponseMock: EcmAuthMock;
let tagMock: TagMock;
let tagsApi: TagsApi;
beforeEach((done) => {
beforeEach(async () => {
const hostEcm = 'https://127.0.0.1:8080';
authResponseMock = new EcmAuthMock(hostEcm);
@@ -36,81 +38,70 @@ describe('Tags', () => {
hostEcm
});
alfrescoJsApi.login('admin', 'admin').then(() => {
done();
});
await alfrescoJsApi.login('admin', 'admin');
tagsApi = new TagsApi(alfrescoJsApi);
});
afterEach(() => {
resetGlobalMockAgent();
});
describe('listTags', () => {
it('should load list of tags', (done) => {
it('should load list of tags', async () => {
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();
});
const data = await tagsApi.listTags();
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');
});
it('should handle 401 error', (done) => {
it('should handle 401 error', async () => {
tagMock.get401Response();
tagsApi.listTags().then(
() => {},
() => {
done();
}
);
try {
await tagsApi.listTags();
assert.fail('Expected listTags to throw error on 401 response');
} catch (error: any) {
assert.equal(error.status, 401, 'Error should have 401 status');
}
});
it('should return specified tag', (done) => {
it('should return specified tag', async () => {
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();
});
const data = await tagsApi.listTags({
tag: 'tag-test-1'
});
assert.equal(data.list.entries[0].entry.tag, 'tag-test-1');
assert.equal(data.list.entries[0].entry.id, '0d89aa82-f2b8-4a37-9a54-f4c5148174d6');
});
it('should return tags contained specified value', (done) => {
it('should return tags contained specified value', async () => {
tagMock.getTagsByNameFilteredByMatching200Response();
tagsApi
.listTags({
tag: '*tag-test*',
matching: true
})
.then((data) => {
assert.equal(data?.list.entries.length, 2);
const data = await tagsApi.listTags({
tag: '*tag-test*',
matching: true
});
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[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();
});
assert.equal(data.list.entries[1].entry.tag, 'tag-test-2');
assert.equal(data.list.entries[1].entry.id, 'd79bdbd0-9f55-45bb-9521-811e15bf48f6');
});
});
describe('createTags', () => {
it('should return created tags', (done) => {
it('should return created tags', async () => {
tagMock.createTags201Response();
tagsApi.createTags([new TagBody(), new TagBody()]).then((tags: TagPaging) => {
assert.equal(tags.list.entries.length, 2);
assert.equal(tags.list.entries[0].entry.tag, 'tag-test-1');
assert.equal(tags.list.entries[1].entry.tag, 'tag-test-2');
done();
});
const tags = await tagsApi.createTags([new TagBody(), new TagBody()]);
assert.equal(tags.list.entries.length, 2);
assert.equal(tags.list.entries[0].entry.tag, 'tag-test-1');
assert.equal(tags.list.entries[1].entry.tag, 'tag-test-2');
});
it('should throw error if tags are not passed', () => {
@@ -119,7 +110,7 @@ describe('Tags', () => {
});
describe('assignTagsToNode', () => {
it('should return tags after assigning them to node', (done) => {
it('should return tags after assigning them to node', async () => {
const tag1 = new TagBody();
tag1.tag = 'tag-test-1';
const tag2 = new TagBody();
@@ -127,25 +118,21 @@ describe('Tags', () => {
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();
});
const tagPaging = await tagsApi.assignTagsToNode('someNodeId', tags);
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);
});
it('should return tag after assigning it to node', (done) => {
it('should return tag after assigning it to node', async () => {
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();
});
const data = await tagsApi.assignTagsToNode('someNodeId', tags);
const tagEntry = data as TagEntry;
assert.equal(tagEntry.entry.tag, tag.tag);
});
});
});
@@ -16,8 +16,10 @@
*/
import assert from 'assert';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { AlfrescoApi, VersionsApi } from '../../src';
import { EcmAuthMock, VersionMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('Versions', () => {
const nodeId = '74cd8a96-8a21-47e5-9b3b-a1b3e296787d';
@@ -41,52 +43,47 @@ describe('Versions', () => {
versionsApi = new VersionsApi(alfrescoJsApi);
});
it('should list all node version renditions', (done) => {
afterEach(() => {
resetGlobalMockAgent();
});
it('should list all node version renditions', async () => {
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();
});
const data = await versionsApi.listVersionRenditions(nodeId, versionId);
const entries = data.list.entries;
assert.equal(entries.length, 6);
assert.equal(data.list.entries[0].entry.id, 'avatar');
});
it('should create rendition for a node versionId', (done) => {
it('should create rendition for a node versionId', async () => {
versionMock.create200VersionRendition(nodeId, versionId);
versionsApi.createVersionRendition(nodeId, versionId, { id: 'pdf' }).then(() => {
done();
});
const result = await versionsApi.createVersionRendition(nodeId, versionId, { id: 'pdf' });
assert.ok(result !== undefined, 'createVersionRendition should complete successfully');
});
it('should get a node version rendition', (done) => {
it('should get a node version rendition', async () => {
versionMock.get200VersionRendition(nodeId, versionId, renditionId);
versionsApi.getVersionRendition(nodeId, versionId, renditionId).then((data) => {
assert.equal(data.entry.id, 'pdf');
done();
});
const data = await versionsApi.getVersionRendition(nodeId, versionId, renditionId);
assert.equal(data.entry.id, 'pdf');
});
it('should get version history', (done) => {
it('should get version history', async () => {
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();
});
const data = await versionsApi.listVersionHistory(nodeId);
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');
});
it('should revert a version', (done) => {
it('should revert a version', async () => {
versionMock.post201Response(nodeId, versionId);
versionsApi.revertVersion(nodeId, versionId, { majorVersion: true, comment: '' }).then((data) => {
assert.equal(data.entry.id, '3.0');
done();
});
const data = await versionsApi.revertVersion(nodeId, versionId, { majorVersion: true, comment: '' });
assert.equal(data.entry.id, '3.0');
});
});
@@ -16,8 +16,10 @@
*/
import assert from 'assert';
import { resetGlobalMockAgent } from '../mockObjects/base.mock';
import { AlfrescoApi, WebscriptApi } from '../../src';
import { EcmAuthMock, WebScriptMock } from '../mockObjects';
import { describe, it, beforeEach, afterEach } from 'node:test';
describe('WebScript', () => {
const hostEcm = 'https://127.0.0.1:8080';
@@ -29,7 +31,7 @@ describe('WebScript', () => {
let webScriptMock: WebScriptMock;
let webscriptApi: WebscriptApi;
beforeEach((done) => {
beforeEach(async () => {
authResponseMock = new EcmAuthMock(hostEcm);
webScriptMock = new WebScriptMock(hostEcm, contextRoot, servicePath, scriptPath);
authResponseMock.get201Response();
@@ -38,74 +40,90 @@ describe('WebScript', () => {
hostEcm
});
alfrescoJsApi.login('admin', 'admin').then(() => {
done();
});
await alfrescoJsApi.login('admin', 'admin');
webscriptApi = new WebscriptApi(alfrescoJsApi);
});
it('execute webScript return 400 error if is not present on the server should be handled by reject promise', (done) => {
afterEach(() => {
resetGlobalMockAgent();
});
it('execute webScript return 400 error if is not present on the server should be handled by reject promise', async () => {
webScriptMock.get404Response();
webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath).catch((error: any) => {
assert.equal(error.status, 404);
done();
});
await assert.rejects(
() => webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath),
(error: any) => error.status === 404
);
});
it('execute webScript GET return 200 if all is ok should be handled by resolve promise', (done) => {
it('execute webScript GET return 200 if all is ok should be handled by resolve promise', async () => {
webScriptMock.get200Response();
webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath).then(() => {
done();
});
const result = await webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath);
assert.ok(result, 'executeWebScript should return a result');
});
it('execute webScript that return HTML should not return it as Object', (done) => {
it('execute webScript that return HTML should not return it as Object', async () => {
webScriptMock.get200ResponseHTMLFormat();
webscriptApi.executeWebScript('GET', 'sample/folder/Company%20Home').then((data) => {
try {
JSON.parse(data);
} catch {
done();
}
});
const data = await webscriptApi.executeWebScript('GET', 'sample/folder/Company%20Home');
assert.ok(data, 'executeWebScript should return data');
let isValidJson = false;
try {
JSON.parse(data);
isValidJson = true;
} catch {
// Expected - HTML cannot be parsed as JSON
}
assert.equal(isValidJson, false, 'HTML response should not be valid JSON');
});
describe('Events', () => {
it('WebScript should fire success event at the end', (done) => {
it('WebScript should fire success event at the end', async () => {
webScriptMock.get200Response();
let successEventFired = false;
const webscriptPromise: any = webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath);
webscriptPromise.catch(() => {});
webscriptPromise.on('success', () => {
done();
successEventFired = true;
});
await webscriptPromise;
assert.equal(successEventFired, true, 'Success event should have fired');
});
it('WebScript should fire error event if something go wrong', (done) => {
it('WebScript should fire error event if something go wrong', async () => {
webScriptMock.get404Response();
let errorEventFired = false;
const webscriptPromise: any = webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath);
webscriptPromise.catch(() => {});
webscriptPromise.on('error', () => {
done();
errorEventFired = true;
});
await webscriptPromise.catch(() => {});
assert.equal(errorEventFired, true, 'Error event should have fired');
});
it('WebScript should fire unauthorized event if get 401', (done) => {
it('WebScript should fire unauthorized event if get 401', async () => {
webScriptMock.get401Response();
let unauthorizedEventFired = false;
const webscriptPromise: any = webscriptApi.executeWebScript('GET', scriptPath, null, contextRoot, servicePath);
webscriptPromise.catch(() => {});
webscriptPromise.on('unauthorized', () => {
done();
unauthorizedEventFired = true;
});
await webscriptPromise.catch(() => {});
assert.equal(unauthorizedEventFired, true, 'Unauthorized event should have fired');
});
});
});