[AAE-5021] Add listPeople method to PeopleContentService (#6947)

* [AAE-5021] Add listPeople method to PeopleContentService

* lint

* Replace Person with EcmUserModel

* Update imports to @alfresco/adf-core

* Change to const + lint
This commit is contained in:
Thomas Hunter
2021-04-28 17:50:53 +02:00
committed by GitHub
parent 42c81e46bb
commit 9cbae9abd8
11 changed files with 124 additions and 46 deletions

View File

@@ -18,7 +18,7 @@
import { EcmCompanyModel } from '../models/ecm-company.model';
import { PersonEntry, Person } from '@alfresco/js-api';
export let fakeEcmCompany: EcmCompanyModel = {
export const fakeEcmCompany: EcmCompanyModel = {
organization: 'company-fake-name',
address1: 'fake-address-1',
address2: 'fake-address-2',
@@ -29,7 +29,7 @@ export let fakeEcmCompany: EcmCompanyModel = {
email: 'fakeCompany@fake.com'
};
export let fakeEcmUser = {
export const fakeEcmUser = {
id: 'fake-id',
firstName: 'fake-ecm-first-name',
lastName: 'fake-ecm-last-name',
@@ -50,7 +50,18 @@ export let fakeEcmUser = {
emailNotificationsEnabled: true
};
export let fakeEcmUserNoImage = {
export const fakeEcmUser2 = {
id: 'another-fake-id',
firstName: 'another-fake-first-name',
lastName: 'another',
displayName: 'admin.adf User',
email: 'admin.adf@alfresco.com',
company: null,
enabled: true,
emailNotificationsEnabled: true
};
export const fakeEcmUserNoImage = {
id: 'fake-id',
firstName: 'fake-first-name',
lastName: 'fake-last-name',
@@ -71,7 +82,7 @@ export let fakeEcmUserNoImage = {
emailNotificationsEnabled: true
};
export let fakeEcmEditedUser = {
export const fakeEcmEditedUser = {
id: 'fake-id',
firstName: null,
lastName: 'fake-last-name',
@@ -92,6 +103,26 @@ export let fakeEcmEditedUser = {
emailNotificationsEnabled: true
};
export const fakeEcmUserList = {
list: {
pagination: {
count: 2,
hasMoreItems: false,
totalItems: 2,
skipCount: 0,
maxItems: 100
},
entries: [
{
entry: fakeEcmUser
},
{
entry: fakeEcmUser2
}
]
}
};
export const createNewPersonMock = {
id: 'fake-id',
firstName: 'fake-ecm-first-name',

View File

@@ -15,13 +15,13 @@
* limitations under the License.
*/
import { Person } from '@alfresco/js-api';
import { EcmUserModel } from './ecm-user.model';
export class CommentModel {
id: number;
message: string;
created: Date;
createdBy: Person;
createdBy: EcmUserModel;
isSelected: boolean;
constructor(obj?: any) {

View File

@@ -15,28 +15,32 @@
* limitations under the License.
*/
import { Person } from '@alfresco/js-api';
import { Capabilities } from '@alfresco/js-api';
import { EcmCompanyModel } from './ecm-company.model';
export class EcmUserModel implements Person {
export class EcmUserModel {
id: string;
firstName: string;
lastName: string;
description: string;
avatarId: string;
lastName?: string;
displayName?: string;
description?: string;
avatarId?: string;
email: string;
skypeId: string;
googleId: string;
instantMessageId: string;
jobTitle: string;
location: string;
skypeId?: string;
googleId?: string;
instantMessageId?: string;
jobTitle?: string;
location?: string;
company: EcmCompanyModel;
mobile: string;
telephone: string;
statusUpdatedAt: Date;
userStatus: string;
mobile?: string;
telephone?: string;
statusUpdatedAt?: Date;
userStatus?: string;
enabled: boolean;
emailNotificationsEnabled: boolean;
emailNotificationsEnabled?: boolean;
aspectNames?: string[];
properties?: { [key: string]: string; };
capabilities?: Capabilities;
constructor(obj?: any) {
this.id = obj && obj.id || null;
@@ -57,5 +61,8 @@ export class EcmUserModel implements Person {
this.userStatus = obj && obj.userStatus;
this.enabled = obj && obj.enabled;
this.emailNotificationsEnabled = obj && obj.emailNotificationsEnabled;
this.aspectNames = obj && obj.aspectNames;
this.properties = obj && obj.properties;
this.capabilities = obj && obj.capabilities;
}
}

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { fakeEcmUser, createNewPersonMock, getFakeUserWithContentAdminCapability } from '../mock/ecm-user.service.mock';
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 } from './people-content.service';
@@ -25,6 +25,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { TestBed } from '@angular/core/testing';
import { LogService } from './log.service';
import { of } from 'rxjs';
import { EcmUserModel } from '../models/ecm-user.model';
describe('PeopleContentService', () => {
@@ -71,6 +72,25 @@ describe('PeopleContentService', () => {
});
});
it('should be able to list people', (done) => {
spyOn(service.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList));
service.listPeople().subscribe((people: EcmUserModel[]) => {
expect(people).toBeDefined();
expect(people.length).toEqual(2);
expect(people[0].id).toEqual('fake-id');
expect(people[1].id).toEqual('another-fake-id');
done();
});
});
it('should call listPeople api method', (done) => {
const listPeopleSpy = spyOn(service.peopleApi, 'listPeople').and.returnValue(Promise.resolve(fakeEcmUserList));
service.listPeople().subscribe(() => {
expect(listPeopleSpy).toHaveBeenCalled();
done();
});
});
it('should be able to create new person', (done) => {
spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser }));
service.createPerson(createNewPersonMock).subscribe((person) => {

View File

@@ -63,6 +63,25 @@ export class PeopleContentService {
return this.getPerson('-me-');
}
/**
* Gets a list of people.
* @param opts Optional parameters supported by JS-API
* @returns Array of people
*/
listPeople(options?): Observable<EcmUserModel[]> {
const promise = this.peopleApi.listPeople(options);
return from(promise).pipe(
map(response => {
const people: EcmUserModel[] = [];
response.list.entries.forEach((person: PersonEntry) => {
people.push(<EcmUserModel> person?.entry);
});
return people;
}),
catchError((err) => this.handleError(err))
);
}
/**
* Creates new person.
* @param newPerson Object containing the new person details.