[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
This commit is contained in:
AleksanderSklorz
2025-05-21 08:08:49 +02:00
committed by GitHub
parent 3fea334468
commit 2cc3ba4d6b
7 changed files with 20 additions and 22 deletions

View File

@@ -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);
});
});

View File

@@ -99,7 +99,7 @@ export class TagService {
* @param tags list of tags to create.
* @returns Created tags.
*/
createTags(tags: TagBody[]): Observable<TagEntry[]> {
createTags(tags: TagBody[]): Observable<TagEntry | TagPaging> {
return from(this.tagsApi.createTags(tags)).pipe(tap((tagEntries) => this.refresh.emit(tagEntries)));
}

View File

@@ -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<TagEntry[]>
* @returns Promise<TagEntry | TagPaging>
*/
createTags(tags: TagBody[]): Promise<TagEntry[]> {
createTags(tags: TagBody[]): Promise<TagEntry | TagPaging> {
throwIfNotDefined(tags, 'tags');
return this.post({

View File

@@ -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**

View File

@@ -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();
});
});

View File

@@ -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 {