Files
alfresco-ng2-components/lib/js-api/test/mockObjects/content-services/categories.mock.ts
Vito Albano a347b20f20 AAE-30882 Replace superagent (#11134)
* [AAE-30878] - Migrating from event-emitter to eventemitter3 which is ESM and commonJs compatibile

* [AAE-30878] - Using types to avoid compilation isues with the new ruels

* AAE-30878 - fixed lint issue on js-api

* AAE-30878 - reverted misplaced changes

* [AAE-30882] - migrating from superagent to axios

* AAE-30882 - Fixed unit test for js-api

* AAE-30882 - Fixed unit test for js-api

* AAE-30882 - Fixed unit test for js-api

* AAE-30882 - Improved some unit tests

* [ci:force]

* AAE-30882 - Checking why is ok locally but fails on CI

* AAE-30882 - Start fixing some unit tests - check 1

* AAE-30882 - Start fixing some unit tests - check 2

* [AAE-30882] - rebased

* [AAE-30882] - added missing import
2025-09-16 11:31:07 +01:00

348 lines
14 KiB
TypeScript

/*!
* @license
* Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import nock from 'nock';
import { BaseMock } from '../base.mock';
export class CategoriesMock extends BaseMock {
get200ResponseSubcategories(categoryId: string): void {
this.createNockWithCors()
.get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`)
.reply(200, {
list: {
pagination: {
count: 2,
hasMoreItems: false,
totalItems: 2,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: {
id: 'testId1',
name: 'testName1',
parentId: '-root-',
hasChildren: true,
count: 0
}
},
{
entry: {
id: 'testId2',
name: 'testName2',
parentId: '-root-',
hasChildren: true,
count: 0
}
}
]
}
});
}
get404SubcategoryNotExist(categoryId: string): void {
this.createNockWithCors()
.get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`)
.reply(404, {
error: {
errorKey: 'framework.exception.EntityNotFound',
statusCode: 404,
briefSummary: `05220073 The entity with id: ${categoryId} was not found`,
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
descriptionURL: 'https://api-explorer.alfresco.com'
}
});
}
get200ResponseCategory(categoryId: string): void {
this.createNockWithCors()
.get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`)
.reply(200, {
entry: {
id: 'testId1',
name: 'testName1',
parentId: '-root-',
hasChildren: true,
count: 0
}
});
}
get404CategoryNotExist(categoryId: string): void {
this.createNockWithCors()
.get(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`)
.reply(404, {
error: {
errorKey: 'framework.exception.EntityNotFound',
statusCode: 404,
briefSummary: `05220073 The entity with id: ${categoryId} was not found`,
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
descriptionURL: 'https://api-explorer.alfresco.com'
}
});
}
get200ResponseNodeCategoryLinks(nodeId: string): void {
this.createNockWithCors()
.get(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`)
.reply(200, {
list: {
pagination: {
count: 1,
hasMoreItems: false,
totalItems: 1,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: {
id: 'testId1',
name: 'testName1',
parentId: 'testNode',
hasChildren: true,
count: 0
}
}
]
}
});
}
get403NodeCategoryLinksPermissionDenied(nodeId: string): void {
this.createNockWithCors()
.get(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`)
.reply(403, {
error: {
statusCode: 403
}
});
}
get404NodeNotExist(nodeId: string): void {
this.createNockWithCors()
.get(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`)
.reply(404, {
error: {
errorKey: 'framework.exception.EntityNotFound',
statusCode: 404,
briefSummary: `05220073 The entity with id: ${nodeId} was not found`,
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
descriptionURL: 'https://api-explorer.alfresco.com'
}
});
}
get204CategoryUnlinked(nodeId: string, categoryId: string): void {
this.createNockWithCors()
.delete(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links/${categoryId}`)
.reply(204);
}
get403CategoryUnlinkPermissionDenied(nodeId: string, categoryId: string): void {
this.createNockWithCors()
.delete(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links/${categoryId}`)
.reply(403, {
error: {
statusCode: 403
}
});
}
get404CategoryUnlinkNotFound(nodeId: string, categoryId: string): void {
this.createNockWithCors()
.delete(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links/${categoryId}`)
.reply(404, {
error: {
errorKey: 'framework.exception.EntityNotFound',
statusCode: 404,
briefSummary: `05230078 The entity with id: ${nodeId} or ${categoryId} was not found`,
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
descriptionURL: 'https://api-explorer.alfresco.com'
}
});
}
get200ResponseCategoryUpdated(categoryId: string): void {
this.createNockWithCors()
.put(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`, { name: 'testName1' })
.reply(200, {
entry: {
id: 'testId1',
name: 'testName1',
parentId: '-root-',
hasChildren: true,
count: 0
}
});
}
get403CategoryUpdatePermissionDenied(categoryId: string): void {
this.createNockWithCors()
.put(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`, { name: 'testName1' })
.reply(403, {
error: {
statusCode: 403
}
});
}
get404CategoryUpdateNotFound(categoryId: string): void {
this.createNockWithCors()
.put(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}`, { name: 'testName1' })
.reply(404, {
error: {
errorKey: 'framework.exception.EntityNotFound',
statusCode: 404,
briefSummary: `05230078 The entity with id: ${categoryId} was not found`,
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
descriptionURL: 'https://api-explorer.alfresco.com'
}
});
}
get201ResponseCategoryCreated(categoryId: string): void {
this.createNockWithCors()
.post(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`, [{ name: 'testName10' }])
.reply(201, {
entry: {
id: 'testId10',
name: 'testName10',
parentId: categoryId,
hasChildren: true,
count: 0
}
});
}
get403CategoryCreatedPermissionDenied(categoryId: string): void {
this.createNockWithCors()
.post(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`, [{ name: 'testName10' }])
.reply(403, {
error: {
statusCode: 403
}
});
}
get409CategoryCreateAlreadyExists(categoryId: string): void {
this.createNockWithCors()
.post(`/alfresco/api/-default-/public/alfresco/versions/1/categories/${categoryId}/subcategories`, [{ name: 'testName10' }])
.reply(409, {
error: {
errorKey: 'Duplicate child name not allowed: testName10',
statusCode: 409,
briefSummary: '06050055 Duplicate child name not allowed: testName10',
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
descriptionURL: 'https://api-explorer.alfresco.com'
}
});
}
get201ResponseCategoryLinked(nodeId: string): void {
this.createNockWithCors()
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }])
.reply(201, {
entry: {
id: 'testId1',
name: 'testName1',
parentId: nodeId,
hasChildren: true,
count: 0
}
});
}
get201ResponseCategoryLinkedArray(nodeId: string): void {
this.createNockWithCors()
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [
{ categoryId: 'testId1' },
{ categoryId: 'testId2' }
])
.reply(201, {
list: {
pagination: {
count: 2,
hasMoreItems: false,
totalItems: 2,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: {
id: 'testId1',
name: 'testName1',
parentId: 'testNodeArr',
hasChildren: true,
count: 0
}
},
{
entry: {
id: 'testId2',
name: 'testName2',
parentId: 'testNodeArr',
hasChildren: true,
count: 0
}
}
]
}
});
}
get403CategoryLinkPermissionDenied(nodeId: string): void {
this.createNockWithCors()
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }])
.reply(403, {
error: {
statusCode: 403
}
});
}
get404CategoryLinkNotFound(nodeId: string): void {
this.createNockWithCors()
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }])
.reply(404, {
error: {
errorKey: 'framework.exception.EntityNotFound',
statusCode: 404,
briefSummary: `05230078 The entity with id: ${nodeId} or testId1 was not found`,
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
descriptionURL: 'https://api-explorer.alfresco.com'
}
});
}
get405CategoryLinkCannotAssign(nodeId: string): void {
this.createNockWithCors()
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }])
.reply(405, {
error: {
errorKey: 'Cannot assign node of this type to a category',
statusCode: 405,
briefSummary: `05230078 Cannot assign a node of this type to a category`,
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
descriptionURL: 'https://api-explorer.alfresco.com'
}
});
}
}