AAE-30882 - Fixed unit test for js-api

This commit is contained in:
VitoAlbano
2025-08-22 12:48:30 +01:00
committed by Vito Albano
parent e400bc1068
commit c17c8232af
43 changed files with 575 additions and 460 deletions

View File

@@ -39,136 +39,131 @@ describe('Categories', () => {
categoriesApi = new CategoriesApi(alfrescoJsApi);
});
it('should return 200 while getting subcategories for category with categoryId if all is ok', (done) => {
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 error not thrown');
} catch (error) {
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 error not thrown');
} catch (error) {
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 error not thrown');
} catch (error) {
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 error not thrown');
} catch (error) {
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();
});
await categoriesApi.unlinkNodeFromCategory('testNode', 'testId1');
});
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 error not thrown');
} catch (error) {
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 error not thrown');
} catch (error) {
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) => {
assert.equal(response.entry.id, 'testId1');
assert.equal(response.entry.name, 'testName1');
done();
});
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', (done) => {
it('should return 404 while updating category if category with categoryId does not exist', async () => {
categoriesMock.get404CategoryUpdateNotFound('testId1');
categoriesApi.updateCategory('testId1', { name: 'testName1' }).then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 404);
done();
}
);
try {
await categoriesApi.updateCategory('testId1', { name: 'testName1' });
assert.fail('Expected error not thrown');
} catch (error) {
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 error not thrown');
} catch (error) {
assert.equal(error.response.status, 403);
}
});
it('should return 403 while updating category if user has no rights to update', (done) => {
it('should return 403 while updating category if user has no rights to update', async () => {
categoriesMock.get403CategoryUpdatePermissionDenied('testId1');
categoriesApi.updateCategory('testId1', { name: 'testName1' }).then(
() => {},
(error: { status: number }) => {
assert.equal(error.status, 403);
done();
}
);
try {
await categoriesApi.updateCategory('testId1', { name: 'testName1' });
assert.fail('Expected error not thrown');
} catch (error) {
assert.equal(error.status, 403);
}
});
it('should return 201 while creating category if all is ok', (done) => {

View File

@@ -161,19 +161,17 @@ describe('Node', () => {
});
});
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.response.text);
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) {
const error = err.response.data.error;
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) => {
@@ -196,7 +194,7 @@ describe('Node', () => {
nodesApi.getFolderSizeInfo('b4cff62a-664d-4d45-9302-98723eac1319', '5ade426e-8a04-4d50-9e42-6e8a041d50f3').then(
() => {},
(err) => {
const { error } = JSON.parse(err.response.text);
const error = err.response.data.error;
assert.equal(error.statusCode, 404);
assert.equal(error.errorKey, 'jobId does not exist');
assert.equal(error.briefSummary, '11207212 jobId does not exist');