Skip to content

Commit

Permalink
[ACS-4296] adding mapping in tags service (#8240)
Browse files Browse the repository at this point in the history
* ACS-4296 Adding mapping in tags service

* ACS-4296 Correct lint issue

* ACS-4296 Excluded failing e2e

* ACS-4296 Trigger build

* ACS-4296 Trigger build

* ACS-4296 Reverted excluded tests
  • Loading branch information
AleksanderSklorz authored Feb 8, 2023
1 parent 08b4cc7 commit dd1feee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
26 changes: 22 additions & 4 deletions lib/content-services/src/lib/tag/services/tag.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import { ContentTestingModule } from '../../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { throwError } from 'rxjs';
import {
Pagination,
RequestQuery,
RequestSortDefinitionInner,
ResultNode,
ResultSetContext,
ResultSetContextFacetQueries,
ResultSetPaging,
ResultSetPagingList,
ResultSetRowEntry,
Tag,
TagBody,
TagEntry,
Expand Down Expand Up @@ -129,6 +132,13 @@ describe('TagService', () => {

beforeEach(() => {
result = new ResultSetPaging();
result.list = new ResultSetPagingList();
const tag = new ResultSetRowEntry();
tag.entry = new ResultNode();
tag.entry.id = 'some id';
tag.entry.name = 'some name';
result.list.entries = [tag];
result.list.pagination = new Pagination();
});

it('should call search on searchApi with correct parameters', () => {
Expand Down Expand Up @@ -156,14 +166,22 @@ describe('TagService', () => {
});
});

it('should return observable which emits paging object for tags', (done) => {
it('should return observable which emits paging object for tags', fakeAsync(() => {
spyOn(service.searchApi, 'search').and.returnValue(Promise.resolve(result));

service.searchTags('test').subscribe((tagsResult) => {
expect(tagsResult).toBe(result);
done();
const tagPaging = new TagPaging();
tagPaging.list = new TagPagingList();
const tagEntry = new TagEntry();
tagEntry.entry = new Tag();
tagEntry.entry.id = 'some id';
tagEntry.entry.tag = 'some name';
tagPaging.list.entries = [tagEntry];
tagPaging.list.pagination = new Pagination();
expect(tagsResult).toEqual(tagPaging);
});
});
tick();
}));

it('should call error on logService when error occurs during fetching paging object for tags', fakeAsync(() => {
spyOn(logService, 'error');
Expand Down
19 changes: 16 additions & 3 deletions lib/content-services/src/lib/tag/services/tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import {
RequestQuery,
RequestSortDefinitionInner,
ResultSetContextFacetQueries,
ResultSetPaging,
SearchApi,
Tag,
TagBody,
TagEntry,
TagPaging,
TagPagingList,
TagsApi
} from '@alfresco/js-api';

Expand Down Expand Up @@ -160,7 +161,7 @@ export class TagService {
* @param maxItems Specify max number of returned tags. Default is specified by UserPreferencesService.
* @returns Found tags which name contains searched name.
*/
searchTags(name: string, skipCount = 0, maxItems?: number): Observable<ResultSetPaging> {
searchTags(name: string, skipCount = 0, maxItems?: number): Observable<TagPaging> {
maxItems = maxItems || this.userPreferencesService.paginationSize;
const sortingByName: RequestSortDefinitionInner = new RequestSortDefinitionInner();
sortingByName.field = 'cm:name';
Expand All @@ -176,7 +177,19 @@ export class TagService {
maxItems
},
sort: [sortingByName]
})).pipe(catchError((error) => this.handleError(error)));
})).pipe(map((resultSetPaging) => {
const tagPaging = new TagPaging();
tagPaging.list = new TagPagingList();
tagPaging.list.pagination = resultSetPaging.list.pagination;
tagPaging.list.entries = resultSetPaging.list.entries.map((resultEntry) => {
const tagEntry = new TagEntry();
tagEntry.entry = new Tag();
tagEntry.entry.tag = resultEntry.entry.name;
tagEntry.entry.id = resultEntry.entry.id;
return tagEntry;
});
return tagPaging;
}), catchError((error) => this.handleError(error)));
}

/**
Expand Down

0 comments on commit dd1feee

Please sign in to comment.