mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[AAE-5529] Include sorting params in the PeopleContentQueryRequestModel (#7182)
* [AAE-5529] Include sorting params in the PeopleContentQueryRequestModel * * Added unit tests to the recent changes on people content service * * Fixed comment
This commit is contained in:
parent
29b4190888
commit
4940ffb006
@ -18,7 +18,7 @@
|
||||
import { fakeEcmUser, fakeEcmUserList, createNewPersonMock, getFakeUserWithContentAdminCapability } from '../mock/ecm-user.service.mock';
|
||||
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { PeopleContentService, PeopleContentQueryResponse } from './people-content.service';
|
||||
import { PeopleContentService, PeopleContentQueryResponse, PeopleContentQueryRequestModel } from './people-content.service';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { setupTestBed } from '../testing/setup-test-bed';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
@ -94,6 +94,16 @@ describe('PeopleContentService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should call listPeople api with requested query params', async () => {
|
||||
const listPeopleSpy = spyOn(service.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList));
|
||||
const requestQueryParams: PeopleContentQueryRequestModel = { skipCount: 10, maxItems: 20, sorting: { orderBy: 'firstName', direction: 'asc' } };
|
||||
const expectedValue = { skipCount: 10, maxItems: 20, orderBy: ['firstName ASC'] };
|
||||
|
||||
await service.listPeople(requestQueryParams).toPromise();
|
||||
|
||||
expect(listPeopleSpy).toHaveBeenCalledWith(expectedValue);
|
||||
});
|
||||
|
||||
it('should be able to create new person', (done) => {
|
||||
spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve(new PersonEntry({ entry: fakeEcmUser })));
|
||||
service.createPerson(createNewPersonMock).subscribe((person) => {
|
||||
|
@ -32,9 +32,15 @@ export interface PeopleContentQueryResponse {
|
||||
entries: EcmUserModel[];
|
||||
}
|
||||
|
||||
export interface PeopleContentSortingModel {
|
||||
orderBy: string;
|
||||
direction: string;
|
||||
}
|
||||
|
||||
export interface PeopleContentQueryRequestModel {
|
||||
skipCount: number;
|
||||
maxItems: number;
|
||||
skipCount?: number;
|
||||
maxItems?: number;
|
||||
sorting?: PeopleContentSortingModel;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
@ -46,6 +52,8 @@ export class PeopleContentService {
|
||||
|
||||
private _peopleApi: PeopleApi;
|
||||
|
||||
defaultSorting = ['firstName ASC'];
|
||||
|
||||
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}
|
||||
|
||||
get peopleApi() {
|
||||
@ -79,7 +87,13 @@ export class PeopleContentService {
|
||||
* @returns Response containing pagination and list of entries
|
||||
*/
|
||||
listPeople(requestQuery?: PeopleContentQueryRequestModel): Observable<PeopleContentQueryResponse> {
|
||||
const promise = this.peopleApi.listPeople(requestQuery);
|
||||
const orderBy = this.buildOrderArray(requestQuery?.sorting.orderBy, requestQuery?.sorting.direction);
|
||||
const requestQueryParams = {
|
||||
skipCount: requestQuery?.skipCount,
|
||||
maxItems: requestQuery?.maxItems,
|
||||
orderBy
|
||||
};
|
||||
const promise = this.peopleApi.listPeople(requestQueryParams);
|
||||
return from(promise).pipe(
|
||||
map(response => {
|
||||
return {
|
||||
@ -113,6 +127,10 @@ export class PeopleContentService {
|
||||
return this.hasContentAdminRole;
|
||||
}
|
||||
|
||||
private buildOrderArray(key: string, direction: string): string[] {
|
||||
return key && direction ? [ `${key} ${direction.toUpperCase()}` ] : this.defaultSorting ;
|
||||
}
|
||||
|
||||
private handleError(error: any) {
|
||||
this.logService.error(error);
|
||||
return throwError(error || 'Server error');
|
||||
|
Loading…
x
Reference in New Issue
Block a user