From b5037734750add40cf48741893c8c4c706f8f6b7 Mon Sep 17 00:00:00 2001 From: Nikita Maliarchuk <84377976+nikita-web-ua@users.noreply.github.com> Date: Fri, 27 Jan 2023 19:06:33 +0100 Subject: [PATCH] [ACS-4411] updateTag method added to tags service (#8200) * [ACS-4411] added updateTag method to tags service & tests & docs * [ACS-4411] docs formatting fix * [ACS-4411] unit test fix --- docs/content-services/services/tag.service.md | 5 +++ .../src/lib/tag/services/tag.service.spec.ts | 41 +++++++++++++++++++ .../src/lib/tag/services/tag.service.ts | 16 ++++++++ 3 files changed, 62 insertions(+) diff --git a/docs/content-services/services/tag.service.md b/docs/content-services/services/tag.service.md index 0ba9bd8107..d99a4068cd 100644 --- a/docs/content-services/services/tag.service.md +++ b/docs/content-services/services/tag.service.md @@ -35,6 +35,11 @@ Manages tags in Content Services. Creates tags. - _tags:_ `TagBody[]` - List of tags to create. - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`` - List of created tags. +- **updateTag**(tagId: `string`, tagBody: `TagBody`): [`Observable`](http://reactivex.io/documentation/observable.html)``
+ Updates a tag. + - _tagId:_ `string` - The identifier of a tag. + - _tagBody:_ `TagBody` - The updated tag. + - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`` - Updated tag. - **searchTags**(name: `string`, skipCount: `number`): [`Observable`](http://reactivex.io/documentation/observable.html)``
Find tags which name contains searched name. - _name:_ `string` - Value for name which should be used during searching tags. 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 dbc5cd3bda..24479a4ecc 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 @@ -168,5 +168,46 @@ describe('TagService', () => { tick(); })); }); + + describe('updateTag', () => { + const tag: TagEntry = { + entry: { + tag: 'fake-tag', + id: 'fake-node-id' + } + }; + const tagBody: TagBody = {tag: 'updated-tag'}; + const updatedTag: TagEntry = { + entry: { + ...tagBody, + id: 'fake-node-id' + } + }; + + it('should call updateTag on tagsApi', () => { + spyOn(service.tagsApi, 'updateTag').and.returnValue(Promise.resolve(updatedTag)); + + service.updateTag(tag.entry.id, tagBody); + expect(service.tagsApi.updateTag).toHaveBeenCalledWith(tag.entry.id, tagBody); + }); + + it('should emit refresh when tag updated successfully', fakeAsync(() => { + spyOn(service.refresh, 'emit'); + spyOn(service.tagsApi, 'updateTag').and.returnValue(Promise.resolve(updatedTag)); + service.updateTag(tag.entry.id, tagBody); + tick(); + expect(service.refresh.emit).toHaveBeenCalledWith(updatedTag); + })); + + it('should call error on logService when error occurs during tag update', fakeAsync(() => { + const logService: LogService = TestBed.inject(LogService); + spyOn(logService, 'error'); + const error: string = 'Some error'; + spyOn(service.tagsApi, 'updateTag').and.returnValue(Promise.reject(error)); + service.updateTag(tag.entry.id, tagBody); + tick(); + expect(logService.error).toHaveBeenCalledWith(error); + })); + }); }); }); 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 9632628ef1..4c98aea67e 100644 --- a/lib/content-services/src/lib/tag/services/tag.service.ts +++ b/lib/content-services/src/lib/tag/services/tag.service.ts @@ -132,6 +132,22 @@ export class TagService { return observableAdd$; } + /** + * Update a tag + * + * @param tagId The identifier of a tag. + * @param tagBody The updated tag. + * @returns Updated tag. + */ + updateTag(tagId: string, tagBody: TagBody): Observable { + const observableUpdate$: Observable = from(this.tagsApi.updateTag(tagId, tagBody)); + observableUpdate$.subscribe( + (tagEntry: TagEntry) => this.refresh.emit(tagEntry), + (err) => this.handleError(err) + ); + return observableUpdate$; + } + /** * Find tags which name contains searched name. *