From 2cc3ba4d6b97667ba87516f7ff70e1935af4e75e Mon Sep 17 00:00:00 2001
From: AleksanderSklorz <115619721+AleksanderSklorz@users.noreply.github.com>
Date: Wed, 21 May 2025 08:08:49 +0200
Subject: [PATCH] [ACS-7706] create tags return promise tag paging instead of
tag entry (#10869)
* [ACS-7706] Corrected returned type for createTags function
* [ACS-7706] Updated documentation for createTags and fixed unit tests
---
docs/content-services/services/tag.service.md | 4 ++--
.../src/lib/tag/services/tag.service.spec.ts | 18 ++++++++----------
.../src/lib/tag/services/tag.service.ts | 2 +-
.../src/api/content-rest-api/api/tags.api.ts | 4 ++--
.../src/api/content-rest-api/docs/TagsApi.md | 2 +-
.../test/content-services/tagApi.spec.ts | 10 +++++-----
.../mockObjects/content-services/tag.mock.ts | 2 +-
7 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/docs/content-services/services/tag.service.md b/docs/content-services/services/tag.service.md
index 966449438e..108f5e56c7 100644
--- a/docs/content-services/services/tag.service.md
+++ b/docs/content-services/services/tag.service.md
@@ -23,10 +23,10 @@ Manages tags in Content Services.
- _nodeId:_ `string` - Id of node to which tags should be assigned.
- _tags:_ `TagBody[]` - List of tags to create and assign or just assign if they already exist.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TagPaging`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/TagPaging.md)`|`[`TagEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/TagEntry.md)`>` - Just linked tags to node or single tag if linked only one tag.
-- **createTags**(tags: `TagBody[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TagEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/TagEntry.md)`[]>`
+- **createTags**(tags: `TagBody[]`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TagEntry`](../../../lib/js-api/src/api/content-rest-api/docs/TagsApi.md#TagEntry) `|` [`TagPaging`](../../../lib/js-api/src/api/content-rest-api/docs/TagsApi.md#TagPaging)`>`
Creates tags.
- _tags:_ `TagBody[]` - list of tags to create.
- - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TagEntry`](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/TagEntry.md)`[]>` - Created tags.
+ - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TagEntry`](../../../lib/js-api/src/api/content-rest-api/docs/TagsApi.md#TagEntry) `|` [`TagPaging`](../../../lib/js-api/src/api/content-rest-api/docs/TagsApi.md#TagPaging)`>` - Created tags.
- **deleteTag**(tagId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)``
Deletes a tag with tagId. This will cause the tag to be removed from all nodes. You must have admin rights to delete a tag.
- _tagId:_ `string` - of the tag to be deleted
diff --git a/lib/content-services/src/lib/tag/services/tag.service.spec.ts b/lib/content-services/src/lib/tag/services/tag.service.spec.ts
index b22d3b6196..c89767e9fc 100644
--- a/lib/content-services/src/lib/tag/services/tag.service.spec.ts
+++ b/lib/content-services/src/lib/tag/services/tag.service.spec.ts
@@ -89,7 +89,7 @@ describe('TagService', () => {
describe('createTags', () => {
it('should call createTags on tagsApi', () => {
- spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve([]));
+ spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve({}));
const tag1 = new TagBody();
tag1.tag = 'Some tag 1';
const tag2 = new TagBody();
@@ -101,19 +101,17 @@ describe('TagService', () => {
});
it('should emit refresh when tags creation is success', async () => {
- const tags: TagEntry[] = [
- {
- entry: {
- id: 'Some id 1',
- tag: 'Some tag 1'
- }
+ const tag: TagEntry = {
+ entry: {
+ id: 'Some id 1',
+ tag: 'Some tag 1'
}
- ];
+ };
spyOn(service.refresh, 'emit');
- spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve(tags));
+ spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve(tag));
await service.createTags([]).toPromise();
- expect(service.refresh.emit).toHaveBeenCalledWith(tags);
+ expect(service.refresh.emit).toHaveBeenCalledWith(tag);
});
});
diff --git a/lib/content-services/src/lib/tag/services/tag.service.ts b/lib/content-services/src/lib/tag/services/tag.service.ts
index b7b18254c3..0679595fbb 100644
--- a/lib/content-services/src/lib/tag/services/tag.service.ts
+++ b/lib/content-services/src/lib/tag/services/tag.service.ts
@@ -99,7 +99,7 @@ export class TagService {
* @param tags list of tags to create.
* @returns Created tags.
*/
- createTags(tags: TagBody[]): Observable {
+ createTags(tags: TagBody[]): Observable {
return from(this.tagsApi.createTags(tags)).pipe(tap((tagEntries) => this.refresh.emit(tagEntries)));
}
diff --git a/lib/js-api/src/api/content-rest-api/api/tags.api.ts b/lib/js-api/src/api/content-rest-api/api/tags.api.ts
index f726f6257b..ccbadb5ebf 100644
--- a/lib/js-api/src/api/content-rest-api/api/tags.api.ts
+++ b/lib/js-api/src/api/content-rest-api/api/tags.api.ts
@@ -209,9 +209,9 @@ export class TagsApi extends BaseApi {
/**
* Create specified by **tags** list of tags.
* @param tags List of tags to create.
- * @returns Promise
+ * @returns Promise
*/
- createTags(tags: TagBody[]): Promise {
+ createTags(tags: TagBody[]): Promise {
throwIfNotDefined(tags, 'tags');
return this.post({
diff --git a/lib/js-api/src/api/content-rest-api/docs/TagsApi.md b/lib/js-api/src/api/content-rest-api/docs/TagsApi.md
index cf3915921b..e172606f84 100644
--- a/lib/js-api/src/api/content-rest-api/docs/TagsApi.md
+++ b/lib/js-api/src/api/content-rest-api/docs/TagsApi.md
@@ -240,7 +240,7 @@ Create specified by **tags** list of tags.
|----------|-----------------------|-------------------------|
| **tags** | [TagBody[]](#TagBody) | List of tags to create. |
-**Return type**: [TagEntry[]](#TagEntry)
+**Return type**: [TagEntry](#TagEntry) | [TagPaging](#TagPaging)
**Example**
diff --git a/lib/js-api/test/content-services/tagApi.spec.ts b/lib/js-api/test/content-services/tagApi.spec.ts
index 6cf98ce6e3..bac4108d9e 100644
--- a/lib/js-api/test/content-services/tagApi.spec.ts
+++ b/lib/js-api/test/content-services/tagApi.spec.ts
@@ -16,7 +16,7 @@
*/
import assert from 'assert';
-import { AlfrescoApi, TagBody, TagEntry, TagsApi } from '../../src';
+import { AlfrescoApi, TagBody, TagEntry, TagPaging, TagsApi } from '../../src';
import { EcmAuthMock, TagMock } from '../mockObjects';
describe('Tags', () => {
@@ -105,10 +105,10 @@ describe('Tags', () => {
describe('createTags', () => {
it('should return created tags', (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');
+ 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();
});
});
diff --git a/lib/js-api/test/mockObjects/content-services/tag.mock.ts b/lib/js-api/test/mockObjects/content-services/tag.mock.ts
index 45ea219932..ba3362c1b3 100644
--- a/lib/js-api/test/mockObjects/content-services/tag.mock.ts
+++ b/lib/js-api/test/mockObjects/content-services/tag.mock.ts
@@ -65,7 +65,7 @@ export class TagMock extends BaseMock {
createTags201Response(): void {
nock(this.host, { encodedQueryParams: true })
.post('/alfresco/api/-default-/public/alfresco/versions/1/tags')
- .reply(201, [this.mockTagEntry(), this.mockTagEntry('tag-test-2', 'd79bdbd0-9f55-45bb-9521-811e15bf48f6')]);
+ .reply(201, this.getPaginatedListOfTags());
}
get201ResponseForAssigningTagsToNode(body: TagBody[]): void {