Skip to content

Commit 2cc3ba4

Browse files
[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
1 parent 3fea334 commit 2cc3ba4

File tree

7 files changed

+20
-22
lines changed

7 files changed

+20
-22
lines changed

docs/content-services/services/tag.service.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Manages tags in Content Services.
2323
- _nodeId:_ `string` - Id of node to which tags should be assigned.
2424
- _tags:_ `TagBody[]` - List of tags to create and assign or just assign if they already exist.
2525
- **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.
26-
- **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)`[]>`<br/>
26+
- **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)`>`<br/>
2727
Creates tags.
2828
- _tags:_ `TagBody[]` - list of tags to create.
29-
- **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.
29+
- **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.
3030
- **deleteTag**(tagId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<void>`<br/>
3131
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.
3232
- _tagId:_ `string` - of the tag to be deleted

lib/content-services/src/lib/tag/services/tag.service.spec.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('TagService', () => {
8989

9090
describe('createTags', () => {
9191
it('should call createTags on tagsApi', () => {
92-
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve([]));
92+
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve({}));
9393
const tag1 = new TagBody();
9494
tag1.tag = 'Some tag 1';
9595
const tag2 = new TagBody();
@@ -101,19 +101,17 @@ describe('TagService', () => {
101101
});
102102

103103
it('should emit refresh when tags creation is success', async () => {
104-
const tags: TagEntry[] = [
105-
{
106-
entry: {
107-
id: 'Some id 1',
108-
tag: 'Some tag 1'
109-
}
104+
const tag: TagEntry = {
105+
entry: {
106+
id: 'Some id 1',
107+
tag: 'Some tag 1'
110108
}
111-
];
109+
};
112110
spyOn(service.refresh, 'emit');
113-
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve(tags));
111+
spyOn(service.tagsApi, 'createTags').and.returnValue(Promise.resolve(tag));
114112

115113
await service.createTags([]).toPromise();
116-
expect(service.refresh.emit).toHaveBeenCalledWith(tags);
114+
expect(service.refresh.emit).toHaveBeenCalledWith(tag);
117115
});
118116
});
119117

lib/content-services/src/lib/tag/services/tag.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class TagService {
9999
* @param tags list of tags to create.
100100
* @returns Created tags.
101101
*/
102-
createTags(tags: TagBody[]): Observable<TagEntry[]> {
102+
createTags(tags: TagBody[]): Observable<TagEntry | TagPaging> {
103103
return from(this.tagsApi.createTags(tags)).pipe(tap((tagEntries) => this.refresh.emit(tagEntries)));
104104
}
105105

lib/js-api/src/api/content-rest-api/api/tags.api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ export class TagsApi extends BaseApi {
209209
/**
210210
* Create specified by **tags** list of tags.
211211
* @param tags List of tags to create.
212-
* @returns Promise<TagEntry[]>
212+
* @returns Promise<TagEntry | TagPaging>
213213
*/
214-
createTags(tags: TagBody[]): Promise<TagEntry[]> {
214+
createTags(tags: TagBody[]): Promise<TagEntry | TagPaging> {
215215
throwIfNotDefined(tags, 'tags');
216216

217217
return this.post({

lib/js-api/src/api/content-rest-api/docs/TagsApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Create specified by **tags** list of tags.
240240
|----------|-----------------------|-------------------------|
241241
| **tags** | [TagBody[]](#TagBody) | List of tags to create. |
242242

243-
**Return type**: [TagEntry[]](#TagEntry)
243+
**Return type**: [TagEntry](#TagEntry) | [TagPaging](#TagPaging)
244244

245245
**Example**
246246

lib/js-api/test/content-services/tagApi.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import assert from 'assert';
19-
import { AlfrescoApi, TagBody, TagEntry, TagsApi } from '../../src';
19+
import { AlfrescoApi, TagBody, TagEntry, TagPaging, TagsApi } from '../../src';
2020
import { EcmAuthMock, TagMock } from '../mockObjects';
2121

2222
describe('Tags', () => {
@@ -105,10 +105,10 @@ describe('Tags', () => {
105105
describe('createTags', () => {
106106
it('should return created tags', (done) => {
107107
tagMock.createTags201Response();
108-
tagsApi.createTags([new TagBody(), new TagBody()]).then((tags) => {
109-
assert.equal(tags.length, 2);
110-
assert.equal(tags[0].entry.tag, 'tag-test-1');
111-
assert.equal(tags[1].entry.tag, 'tag-test-2');
108+
tagsApi.createTags([new TagBody(), new TagBody()]).then((tags: TagPaging) => {
109+
assert.equal(tags.list.entries.length, 2);
110+
assert.equal(tags.list.entries[0].entry.tag, 'tag-test-1');
111+
assert.equal(tags.list.entries[1].entry.tag, 'tag-test-2');
112112
done();
113113
});
114114
});

lib/js-api/test/mockObjects/content-services/tag.mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class TagMock extends BaseMock {
6565
createTags201Response(): void {
6666
nock(this.host, { encodedQueryParams: true })
6767
.post('/alfresco/api/-default-/public/alfresco/versions/1/tags')
68-
.reply(201, [this.mockTagEntry(), this.mockTagEntry('tag-test-2', 'd79bdbd0-9f55-45bb-9521-811e15bf48f6')]);
68+
.reply(201, this.getPaginatedListOfTags());
6969
}
7070

7171
get201ResponseForAssigningTagsToNode(body: TagBody[]): void {

0 commit comments

Comments
 (0)