Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1562 from Alfresco/feature/dev-mkinas-ACS-4966-ad…
Browse files Browse the repository at this point in the history
…d-path-to-categories-api

[ACS-4966] Add path to category model
  • Loading branch information
MichalKinas authored Apr 20, 2023
2 parents 23a6240 + 4f6d62d commit 8ed4008
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 9 deletions.
36 changes: 30 additions & 6 deletions src/api/content-rest-api/api/categories.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class CategoriesApi extends BaseApi {
* @param opts.include Returns additional information about the category. The following optional fields can be requested:
* count
* path
* @return Promise<CategoryPaging>
*/
Expand Down Expand Up @@ -112,6 +113,7 @@ export class CategoriesApi extends BaseApi {
* @param opts.include Returns additional information about the category. The following optional fields can be requested:
* count
* path
* @return Promise<CategoryEntry>
*/
Expand Down Expand Up @@ -162,6 +164,13 @@ export class CategoriesApi extends BaseApi {
The list applies to a returned individual
entity or entries within a collection.
If the API method also supports the **include**
parameter, then the fields specified in the **include**
parameter are returned in addition to those specified in the **fields** parameter.
* @param opts.include Returns additional information about the category. The following optional fields can be requested:
* path
* @return Promise<CategoryPaging>
*/
getCategoryLinksForNode(nodeId: string, opts?: any): Promise<CategoryPaging> {
Expand All @@ -176,7 +185,8 @@ export class CategoriesApi extends BaseApi {
const queryParams = {
'skipCount': opts['skipCount'],
'maxItems': opts['maxItems'],
'fields': buildCollectionParam(opts['fields'], 'csv')
'fields': buildCollectionParam(opts['fields'], 'csv'),
'include': buildCollectionParam(opts['include'], 'csv')
};

const headerParams = {};
Expand Down Expand Up @@ -274,6 +284,10 @@ export class CategoriesApi extends BaseApi {
parameter, then the fields specified in the **include**
parameter are returned in addition to those specified in the **fields** parameter.
* @param opts.include Returns additional information about the category. The following optional fields can be requested:
* count
* path
* @return Promise<CategoryEntry>
*/
updateCategory(categoryId: string, categoryBodyUpdate: CategoryBody, opts?: any): Promise<CategoryEntry> {
Expand All @@ -289,7 +303,8 @@ export class CategoriesApi extends BaseApi {
};

const queryParams = {
'fields': buildCollectionParam(opts['fields'], 'csv')
'fields': buildCollectionParam(opts['fields'], 'csv'),
'include': buildCollectionParam(opts['include'], 'csv')
};

const headerParams = {};
Expand Down Expand Up @@ -372,6 +387,10 @@ export class CategoriesApi extends BaseApi {
parameter, then the fields specified in the **include**
parameter are returned in addition to those specified in the **fields** parameter.
* @param opts.include Returns additional information about the category. The following optional fields can be requested:
* count
* path
* @return Promise<CategoryPaging | CategoryEntry>
*/
createSubcategories(categoryId: string, categoryBodyCreate: CategoryBody[], opts?: any): Promise<CategoryPaging | CategoryEntry> {
Expand All @@ -387,7 +406,8 @@ export class CategoriesApi extends BaseApi {
};

const queryParams = {
'fields': buildCollectionParam(opts['fields'], 'csv')
'fields': buildCollectionParam(opts['fields'], 'csv'),
'include': buildCollectionParam(opts['include'], 'csv')
};

const headerParams = {};
Expand Down Expand Up @@ -468,9 +488,12 @@ export class CategoriesApi extends BaseApi {
parameter, then the fields specified in the **include**
parameter are returned in addition to those specified in the **fields** parameter.
* @return Promise<CategoryEntry>
* @param opts.include Returns additional information about the category. The following optional fields can be requested:
* path
* @return Promise<CategoryPaging | CategoryEntry>
*/
linkNodeToCategory(nodeId: string, categoryLinkBodyCreate: CategoryLinkBody[], opts?: any): Promise<CategoryEntry> {
linkNodeToCategory(nodeId: string, categoryLinkBodyCreate: CategoryLinkBody[], opts?: any): Promise<CategoryPaging | CategoryEntry> {

throwIfNotDefined(nodeId, 'nodeId');
throwIfNotDefined(categoryLinkBodyCreate, 'categoryLinkBodyCreate');
Expand All @@ -483,7 +506,8 @@ export class CategoriesApi extends BaseApi {
};

const queryParams = {
'fields': buildCollectionParam(opts['fields'], 'csv')
'fields': buildCollectionParam(opts['fields'], 'csv'),
'include': buildCollectionParam(opts['include'], 'csv')
};

const headerParams = {};
Expand Down
1 change: 1 addition & 0 deletions src/api/content-rest-api/docs/Category.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ Name | Type | Description | Notes
**parentId** | **string** | | [optional] [default to null]
**hasChildren** | **boolean** | | [optional] [default to null]
**count** | **number** | | [optional] [default to null]
**path** | **string** | | [optional] [default to null]


1 change: 1 addition & 0 deletions src/api/content-rest-api/model/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class Category {
parentId?: string;
hasChildren?: boolean;
count?: number;
path?: string;

constructor(input?: any) {
if (input) {
Expand Down
24 changes: 21 additions & 3 deletions test/content-services/categoriesApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EcmAuthMock } from '../../test/mockObjects';
import { CategoriesMock } from '../mockObjects/content-services/categories.mock';
import { CategoryPaging } from '../../src/api/content-rest-api/model/categoryPaging';
import { CategoryEntry } from '../../src/api/content-rest-api/model/categoryEntry';
import { fail } from 'assert';

describe('Categories', () => {
let authResponseMock: EcmAuthMock;
Expand Down Expand Up @@ -195,9 +196,26 @@ describe('Categories', () => {

it('should return 201 while linking category if all is ok', (done) => {
categoriesMock.get201ResponseCategoryLinked('testNode');
categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]).then((response: CategoryEntry) => {
expect(response.entry.id).equal('testId1');
expect(response.entry.name).equal('testName1');
categoriesApi.linkNodeToCategory('testNode', [{ categoryId: 'testId1' }]).then((response) => {
if (response instanceof CategoryEntry) {
expect(response.entry.id).equal('testId1');
expect(response.entry.name).equal('testName1');
done();
} else {
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;
expect(categoriesPaging.list.pagination.count).equal(2);
expect(categoriesPaging.list.entries[0].entry.id).equal('testId1');
expect(categoriesPaging.list.entries[0].entry.name).equal('testName1');
expect(categoriesPaging.list.entries[1].entry.id).equal('testId2');
expect(categoriesPaging.list.entries[1].entry.name).equal('testName2');
done();
});
});
Expand Down
36 changes: 36 additions & 0 deletions test/mockObjects/content-services/categories.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,42 @@ export class CategoriesMock extends BaseMock {
});
}

get201ResponseCategoryLinkedArray(nodeId: string): void {
nock(this.host, { encodedQueryParams: true })
.post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }, { categoryId: 'testId2' }])
.reply(201, {
list: {
pagination: {
count: 2,
hasMoreItems: false,
totalItems: 2,
skipCount: 0,
maxItems: 100,
},
entries: [
{
entry: {
id: 'testId1',
name: 'testName1',
parentId: 'testNodeArr',
hasChildren: true,
count: 0
}
},
{
entry: {
id: 'testId2',
name: 'testName2',
parentId: 'testNodeArr',
hasChildren: true,
count: 0
}
}
]
}
});
}

get403CategoryLinkPermissionDenied(nodeId: string): void {
nock(this.host, { encodedQueryParams: true }).post(`/alfresco/api/-default-/public/alfresco/versions/1/nodes/${nodeId}/category-links`, [{ categoryId: 'testId1' }])
.reply(403, {
Expand Down

0 comments on commit 8ed4008

Please sign in to comment.