Skip to content

Commit

Permalink
[ACS-4411] updateTag method added to tags service (#8200)
Browse files Browse the repository at this point in the history
* [ACS-4411] added updateTag method to tags service & tests & docs

* [ACS-4411] docs formatting fix

* [ACS-4411] unit test fix
  • Loading branch information
nikita-web-ua authored Jan 27, 2023
1 parent efb2558 commit b503773
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/content-services/services/tag.service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`<TagEntry[]>` - List of created tags.
- **updateTag**(tagId: `string`, tagBody: `TagBody`): [`Observable`](http://reactivex.io/documentation/observable.html)`<TagEntry>`<br/>
Updates a tag.
- _tagId:_ `string` - The identifier of a tag.
- _tagBody:_ `TagBody` - The updated tag.
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<TagEntry>` - Updated tag.
- **searchTags**(name: `string`, skipCount: `number`): [`Observable`](http://reactivex.io/documentation/observable.html)`<ResultSetPaging>`<br/>
Find tags which name contains searched name.
- _name:_ `string` - Value for name which should be used during searching tags.
Expand Down
41 changes: 41 additions & 0 deletions lib/content-services/src/lib/tag/services/tag.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));
});
});
});
16 changes: 16 additions & 0 deletions lib/content-services/src/lib/tag/services/tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TagEntry> {
const observableUpdate$: Observable<TagEntry> = 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.
*
Expand Down

0 comments on commit b503773

Please sign in to comment.