Merge pull request #895 from Alfresco/dev-valbano-741

Dev valbano 741
This commit is contained in:
Eugenio Romano
2016-10-13 21:26:49 +01:00
committed by GitHub
15 changed files with 634 additions and 604 deletions

View File

@@ -45,6 +45,10 @@ module.exports = function (config) {
// ng2-components
{ pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false },
// Fake files
{ pattern: 'src/assets/ecmImg.gif', included: false, watched: true, served: true },
{ pattern: 'src/assets/bpmImg.gif', included: false, watched: true, served: true },
{ pattern: 'src/img/anonymous.gif', included: false, watched: true, served: true },
// paths to support debugging with source maps in dev tools
{pattern: 'src/**/*.ts', included: false, watched: false},

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -60,7 +60,30 @@ export var fakeBpmUser: BpmUserModel = {
lastUpdate: 'fake-update-date',
latestSyncTimeStamp: 'fake-timestamp',
password: 'fake-password',
pictureId: 'fake-picture-id',
pictureId: 'src/assets/bpmImg.gif',
status: 'fake-status',
tenantId: 'fake-tenant-id',
tenantName: 'fake-tenant-name',
tenantPictureId: 'fake-tenant-picture-id',
type: 'fake-type'
};
export var fakeBpmEditedUser: BpmUserModel = {
apps: {},
capabilities: 'fake-capability',
company: 'fake-company',
created: 'fake-create-date',
email: 'fakeBpm@fake.com',
externalId: 'fake-external-id',
firstName: 'fake-first-name',
lastName: 'fake-last-name',
fullname: 'fake-full-name',
groups: {},
id: 'fake-id',
lastUpdate: 'fake-update-date',
latestSyncTimeStamp: 'fake-timestamp',
password: 'fake-password',
pictureId: 'src/assets/bpmImg.gif',
status: 'fake-status',
tenantId: 'fake-tenant-id',
tenantName: 'fake-tenant-name',
@@ -70,27 +93,31 @@ export var fakeBpmUser: BpmUserModel = {
export class FakeBpmUserService {
lastPromise: Observable<BpmUserModel>;
public userNeeded = 0;
usersList = [fakeBpmUser, fakeBpmUserNoImage];
lastPromise: Observable<BpmUserModel>;
public userNeeded = 0;
usersList = [fakeBpmUser, fakeBpmUserNoImage, fakeBpmEditedUser];
getUserInfo(userName: string) {
return this.lastPromise = Observable.of(this.usersList[this.userNeeded]);
};
getUserInfo(userName: string) {
return this.lastPromise = Observable.of(this.usersList[this.userNeeded]);
};
getCurrentUserInfo() {
return this.getUserInfo('fake-id');
};
getCurrentUserInfo() {
return this.getUserInfo('fake-id');
};
getCurrentUserProfileImage() {
return this.usersList[this.userNeeded].pictureId;
};
getCurrentUserProfileImage() {
return Observable.of(this.usersList[this.userNeeded].pictureId);
};
respondWithTheUserWithoutImage() {
this.userNeeded = 1;
}
respondWithTheUserWithoutImage() {
this.userNeeded = 1;
}
respondWithTheUserWithImage() {
this.userNeeded = 0;
}
respondWithTheUserWithImage() {
this.userNeeded = 0;
}
respondWithEditedUser() {
this.userNeeded = 2;
}
}

View File

@@ -0,0 +1,132 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// re-export for tester convenience
export { EcmUserModel } from '../models/ecm-user.model';
export { EcmUserService } from '../services/ecm-user.service';
import { EcmUserModel } from '../models/ecm-user.model';
import { EcmCompanyModel } from '../models/ecm-company.model';
import { Observable } from 'rxjs/Rx';
export var fakeEcmCompany: EcmCompanyModel = {
organization: 'company-fake-name',
address1: 'fake-address-1',
address2: 'fake-address-2',
address3: 'fake-address-3',
postcode: 'fAk1',
telephone: '00000000',
fax: '11111111',
email: 'fakeCompany@fake.com'
};
export var fakeEcmUserNoImage: EcmUserModel = {
id: 'fake-id',
firstName: 'fake-first-name',
lastName: 'fake-last-name',
description: 'i am a fake user for test',
avatarId: undefined,
email: 'fakeEcm@ecmUser.com',
skypeId: 'fake-skype-id',
googleId: 'fake-googleId-id',
instantMessageId: 'fake-instantMessageId-id',
company: fakeEcmCompany,
jobTitle: 'test job',
location: 'fake location',
mobile: '000000000',
telephone: '11111111',
statusUpdatedAt: 'fake-date',
userStatus: 'active',
enabled: true,
emailNotificationsEnabled: true
};
export var fakeEcmUser: EcmUserModel = {
id: 'fake-id',
firstName: 'fake-first-name',
lastName: 'fake-last-name',
description: 'i am a fake user for test',
avatarId: 'fake-avatar-id',
email: 'fakeEcm@ecmUser.com',
skypeId: 'fake-skype-id',
googleId: 'fake-googleId-id',
instantMessageId: 'fake-instantMessageId-id',
company: fakeEcmCompany,
jobTitle: 'test job',
location: 'fake location',
mobile: '000000000',
telephone: '11111111',
statusUpdatedAt: 'fake-date',
userStatus: 'active',
enabled: true,
emailNotificationsEnabled: true
};
export var fakeEcmEditedUser: EcmUserModel = {
id: 'fake-id',
firstName: 'fake-first-name',
lastName: 'fake-last-name',
description: 'i am a fake user for test',
avatarId: 'fake-avatar-id',
email: 'fakeEcm@ecmUser.com',
skypeId: 'fake-skype-id',
googleId: 'fake-googleId-id',
instantMessageId: 'fake-instantMessageId-id',
company: fakeEcmCompany,
jobTitle: 'test job',
location: 'fake location',
mobile: '000000000',
telephone: '11111111',
statusUpdatedAt: 'fake-date',
userStatus: 'active',
enabled: true,
emailNotificationsEnabled: true
};
export class FakeEcmUserService {
lastPromise: Observable<EcmUserModel>;
public userNeeded = 0;
usersList = [fakeEcmUser, fakeEcmUserNoImage, fakeEcmEditedUser];
getUserInfo(userName: string) {
return this.lastPromise = Observable.of(this.usersList[this.userNeeded]);
};
getCurrentUserInfo() {
return this.getUserInfo('fake-id');
};
getUserProfileImage(avatarId: string) {
if (avatarId) {
return 'src/assets/ecmImg.gif';
}
};
respondWithTheUserWithoutImage() {
this.userNeeded = 1;
};
respondWithTheUserWithImage() {
this.userNeeded = 0;
};
respondWithEditedUser() {
this.userNeeded = 2;
};
}

View File

@@ -2,6 +2,7 @@
text-align: center;
border-radius: 90%;
width: 40px;
height: 40px;
margin-right: 0%;
cursor: pointer;
border: 1px solid #999999;
@@ -16,6 +17,7 @@
.detail-user-profile-list-mdl{
margin-right: 10px;
padding: 0px 0;
}
.user-profile-list-mdl{

View File

@@ -1,56 +1,58 @@
<div id="img_container">
<span *ngIf="ecmUser">{{ecmUser.firstName || ecmUser.lastName}}</span>
<span *ngIf="bpmUser && !ecmUser">
<div id="userinfo_container">
<span id="ecm_username" *ngIf="ecmUser">{{ecmUser.firstName || ecmUser.lastName}}</span>
<span id="bpm_username" *ngIf="bpmUser && !ecmUser">
{{ formatValue(bpmUser.firstName) ||
formatValue(bpmUser.lastName) ||
formatValue(bpmUser.fullName) }}
formatValue(bpmUser.fullname) }}
</span>
<div class="button-profile" id="user-profile" data-automation-id="user-profile">
<div *ngIf="ecmUser || bpmUser" class="button-profile" id="user-profile" data-automation-id="user-profile">
<img id="logged-user-img"
[src]="getUserAvatar()"
class="profile-image"/>
</div>
<div class="user-profile-list-mdl
<div *ngIf="ecmUser || bpmUser" id="user-profile-lists" class="user-profile-list-mdl
mdl-menu mdl-menu--bottom-right
mdl-js-menu mdl-js-ripple-effect"
for="user-profile">
<ul class='detail-user-profile-list-mdl mdl-list'>
<div *ngIf="ecmUser">
<div id="ecm-user-detail" *ngIf="ecmUser">
<hr class="title-start">
<span class="header-profile"><b>ECM</b></span>
<span id="ecm_title" class="header-profile"><b>ECM</b></span>
<li class="mdl-list__item mdl-list__item--two-line">
<span class="mdl-list__item-primary-content">
<i class="mdl-list__item-avatar">
<img id="logged-user-img"
[src]="getEcmUserDetailAvatarUrl()"
<img id="ecm-user-detail-image"
[src]="getEcmUserAvatar()"
class="profile-image"/>
</i>
<span class="truncate-long-names">{{ecmUser.firstName}} {{ecmUser.lastName}}</span>
<span class="mdl-list__item-sub-title">{{ecmUser.email}}</span>
<span id="ecm-full-name" class="truncate-long-names">
{{ecmUser.firstName}} {{ecmUser.lastName}}
</span>
<span id="ecm-email" class="mdl-list__item-sub-title">{{ecmUser.email}}</span>
</span>
<span class="mdl-list__item-secondary-content custom-role-style">
<span id="ecm-job-title" class="mdl-list__item-secondary-content custom-role-style">
<span class="role-label-user">Job Role</span>
{{ ecmUser.jobTitle ? ecmUser.jobTitle : 'N/A' }}
</span>
</li>
<br>
</div>
<br>
<div *ngIf="bpmUser">
<div id="bpm-user-detail" *ngIf="bpmUser">
<hr class="title-start">
<span class="header-profile"><b>BPM</b></span>
<span id="bpm_title" class="header-profile"><b>BPM</b></span>
<li class="mdl-list__item mdl-list__item--two-line">
<span class="mdl-list__item-primary-content">
<i class="mdl-list__item-avatar">
<img id="logged-user-img"
[src]="getBpmUserDetailAvatarUrl()"
<img id="bpm-user-detail-image"
[src]="getBpmUserAvatar()"
class="profile-image"/>
</i>
<span class="truncate-long-names">
{{formatValue(bpmUser.firstName) }} {{ formatValue(bpmUser.lastName) }}
<span id="bpm-full-name" class="truncate-long-names">
{{ formatValue(bpmUser.firstName) }} {{ formatValue(bpmUser.lastName) }}
</span>
<span class="mdl-list__item-sub-title">{{bpmUser.email}}</span>
<span id="bpm-email" class="mdl-list__item-sub-title">{{bpmUser.email}}</span>
</span>
<span class="mdl-list__item-secondary-content custom-role-style">
<span id="bpm-tenant" class="mdl-list__item-secondary-content custom-role-style">
<span class="role-label-user">Tenant</span>
{{bpmUser.tenantName}}
</span>

View File

@@ -18,231 +18,319 @@
import { UserInfoComponent } from './user-info.component';
import { EcmUserService } from '../services/ecm-user.service';
import { BpmUserService } from '../services/bpm-user.service';
import { FakeEcmUserService } from '../testing/fake-ecm-user.service';
import { FakeBpmUserService } from '../testing/fake-bpm-user.service';
import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core';
import { FakeEcmUserService } from '../assets/fake-ecm-user.service.mock';
import { fakeEcmEditedUser } from '../assets/fake-ecm-user.service.mock';
import { FakeBpmUserService } from '../assets/fake-bpm-user.service.mock';
import { fakeBpmEditedUser } from '../assets/fake-bpm-user.service.mock';
import { AlfrescoContentService, AlfrescoSettingsService } from 'ng2-alfresco-core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
class StubAuthentication {
isEcmConnected: boolean;
isBpmConnected: boolean;
setIsEcmLoggedIn(logged: boolean) { this.isEcmConnected = logged; };
setIsBpmLoggedIn(logged: boolean) { this.isBpmConnected = logged; };
isEcmLoggedIn() { return this.isEcmConnected; };
isBpmLoggedIn() { return this.isBpmConnected; };
class StubSetting {
provider: string;
setProviders(provider: string) {
this.provider = provider;
};
getProviders() {
return this.provider;
};
}
class StubAlfrescoContentService {
getContentUrl() { return 'fake/url/image/for/ecm/user'; } ;
getContentUrl() {
return 'fake/url/image/for/ecm/user';
};
}
describe('User info component', () => {
let userInfoComp: UserInfoComponent;
let fixture: ComponentFixture<UserInfoComponent>;
let authStub: StubAuthentication;
let stubSetting: StubSetting;
let fakeEcmService: FakeEcmUserService;
let fakeBpmService: FakeBpmUserService;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ UserInfoComponent ],
providers: [{ provide: EcmUserService, useClass: FakeEcmUserService},
{ provide: BpmUserService, useClass: FakeBpmUserService},
{ provide: AlfrescoAuthenticationService, useClass: StubAuthentication },
{ provide: AlfrescoContentService, useClass: StubAlfrescoContentService }
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(UserInfoComponent);
userInfoComp = fixture.componentInstance;
});
TestBed.configureTestingModule({
declarations: [UserInfoComponent],
providers: [{provide: EcmUserService, useClass: FakeEcmUserService},
{provide: BpmUserService, useClass: FakeBpmUserService},
{provide: AlfrescoSettingsService, useClass: StubSetting},
{provide: AlfrescoContentService, useClass: StubAlfrescoContentService}
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(UserInfoComponent);
userInfoComp = fixture.componentInstance;
element = fixture.nativeElement;
});
}));
it('should NOT have users before ngOnInit only anonymous image', () => {
expect(userInfoComp.ecmUser).toBeUndefined();
expect(userInfoComp.ecmUserImage).toBeUndefined();
expect(userInfoComp.bpmUser).toBeUndefined();
expect(userInfoComp.bpmUserImage).toBeUndefined();
expect(userInfoComp.anonymouseImageUrl).toBeDefined();
it('should not show any image if the user is not logged in', () => {
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#logged-user-img')).toBeNull();
});
it('should NOT have users immediately after ngOnInit', () => {
fixture.detectChanges();
expect(userInfoComp.ecmUser).toBeUndefined();
expect(userInfoComp.ecmUserImage).toBeUndefined();
expect(userInfoComp.bpmUser).toBeUndefined();
expect(userInfoComp.bpmUserImage).toBeUndefined();
expect(userInfoComp.anonymouseImageUrl).toBeDefined();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#ecm_username')).toBeNull();
expect(element.querySelector('#bpm_username')).toBeNull();
expect(element.querySelector('#user-profile-lists')).toBeNull();
});
it('should format null string values in null value', () => {
let res = userInfoComp.formatValue('null');
expect(res).toBeDefined();
expect(res).toBeNull();
});
it('should return the value when it is not null string', () => {
let res = userInfoComp.formatValue('fake-value');
expect(res).toBeDefined();
expect(res).not.toBeNull();
expect(res).toEqual('fake-value');
});
describe('when user is logged on ecm', () => {
beforeEach( async(() => {
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
beforeEach(async(() => {
stubSetting = fixture.debugElement.injector.get(AlfrescoSettingsService);
fakeEcmService = fixture.debugElement.injector.get(EcmUserService);
authStub.setIsEcmLoggedIn(true);
fixture.detectChanges(); // runs ngOnInit -> getUsers
stubSetting.setProviders('ECM');
fixture.detectChanges();
fixture.whenStable()
.then( () => {
fixture.detectChanges();
} );
.then(() => {
fixture.detectChanges();
});
}));
it('should get the ecm current user image from the service', () => {
expect(userInfoComp.ecmUser).toBeDefined();
expect(userInfoComp.ecmUserImage).toBeDefined();
expect(userInfoComp.ecmUserImage).toEqual('fake/url/image/for/ecm/user');
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#logged-user-img')).toBeDefined();
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('src/assets/ecmImg.gif');
});
it('should get the ecm user informations from the service', () => {
expect(userInfoComp.ecmUser).toBeDefined();
expect(userInfoComp.ecmUser.firstName).toEqual('fake-first-name');
expect(userInfoComp.ecmUser.lastName).toEqual('fake-last-name');
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#ecm_username')).toBeDefined();
expect(element.querySelector('#ecm_title')).toBeDefined();
expect(element.querySelector('#ecm-user-detail-image')).toBeDefined();
expect(element.querySelector('#ecm-user-detail-image').getAttribute('src')).toEqual('src/assets/ecmImg.gif');
expect(element.querySelector('#ecm-full-name').innerHTML).toContain('fake-first-name fake-last-name');
expect(element.querySelector('#ecm-job-title').innerHTML).toContain('test job');
});
it('should return the anonynous user avatar image url when user does not have avatarId', async(() => {
it('should return the anonymous user avatar image url when user does not have avatarId', () => {
fakeEcmService.respondWithTheUserWithoutImage();
userInfoComp.ngOnInit();
fixture.whenStable()
.then( () => {
fixture.detectChanges();
let res = userInfoComp.getEcmUserDetailAvatarUrl();
expect(userInfoComp.ecmUserImage).toBeUndefined();
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
});
}));
.then(() => {
fixture.detectChanges();
let res = userInfoComp.getEcmUserAvatar();
expect(res).toBeDefined();
expect(element.querySelector('#logged-user-img').getAttribute('src'))
.toContain('src/img/anonymous.gif');
});
});
it('should show N/A when the job title is null', () => {
fakeEcmEditedUser.jobTitle = null;
fakeEcmService.respondWithEditedUser();
userInfoComp.ngOnInit();
fixture.whenStable()
.then(() => {
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#ecm-job-title')).toBeDefined();
expect(element.querySelector('#ecm-job-title').innerHTML).toContain('N/A');
});
});
});
describe('when user is logged on bpm', () => {
beforeEach( async(() => {
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
beforeEach(async(() => {
stubSetting = fixture.debugElement.injector.get(AlfrescoSettingsService);
fakeBpmService = fixture.debugElement.injector.get(BpmUserService);
authStub.setIsBpmLoggedIn(true);
fixture.detectChanges(); // runs ngOnInit -> getUsers
stubSetting.setProviders('BPM');
fixture.detectChanges();
fixture.whenStable()
.then( () => {
fixture.detectChanges();
} );
.then(() => {
fixture.detectChanges();
});
}));
it('should get the bpm current user image from the service', () => {
expect(userInfoComp.bpmUser).toBeDefined();
expect(userInfoComp.bpmUserImage).toBeDefined();
expect(userInfoComp.bpmUserImage).toEqual('fake-picture-id');
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#logged-user-img')).toBeDefined();
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('src/assets/bpmImg.gif');
});
it('should show last name if first name is null', () => {
fakeBpmEditedUser.firstName = null;
fakeBpmService.respondWithEditedUser();
userInfoComp.ngOnInit();
fixture.whenStable()
.then(() => {
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#bpm_username')).toBeDefined();
expect(element.querySelector('#bpm_username').innerHTML).toContain('fake-last-name');
});
});
it('should show full name if first and last name are null', () => {
fakeBpmEditedUser.firstName = null;
fakeBpmEditedUser.lastName = null;
fakeBpmService.respondWithEditedUser();
userInfoComp.ngOnInit();
fixture.whenStable()
.then(() => {
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#bpm_username')).toBeDefined();
expect(element.querySelector('#bpm_username').innerHTML).toContain('fake-full-name');
});
});
it('should not show first name if it is null string', () => {
fakeBpmEditedUser.firstName = 'null';
fakeBpmEditedUser.lastName = 'fake-last-name';
fakeBpmService.respondWithEditedUser();
userInfoComp.ngOnInit();
fixture.whenStable()
.then(() => {
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#bpm-full-name')).toBeDefined();
expect(element.querySelector('#bpm-full-name').innerHTML).not.toContain('fake-first-name');
expect(element.querySelector('#bpm-full-name').innerHTML).toContain('fake-last-name');
});
});
it('should not show last name if it is null string', () => {
fakeBpmEditedUser.lastName = 'null';
fakeBpmEditedUser.firstName = 'fake-first-name';
fakeBpmService.respondWithEditedUser();
userInfoComp.ngOnInit();
fixture.whenStable()
.then(() => {
fixture.detectChanges();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#bpm-full-name')).toBeDefined();
expect(element.querySelector('#bpm-full-name').innerHTML).toContain('fake-first-name');
expect(element.querySelector('#bpm-full-name').innerHTML).not.toContain('fake-last-name');
});
});
it('should get the bpm user informations from the service', () => {
expect(userInfoComp.bpmUser).toBeDefined();
expect(userInfoComp.bpmUser.firstName).toEqual('fake-first-name');
expect(userInfoComp.bpmUser.lastName).toEqual('fake-last-name');
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#bpm_username')).toBeDefined();
expect(element.querySelector('#bpm_title')).toBeDefined();
expect(element.querySelector('#bpm-user-detail-image')).toBeDefined();
expect(element.querySelector('#bpm-user-detail-image').getAttribute('src')).toEqual('src/assets/bpmImg.gif');
expect(element.querySelector('#bpm-full-name').innerHTML).toContain('fake-first-name fake-last-name');
expect(element.querySelector('#bpm-tenant').innerHTML).toContain('fake-tenant-name');
});
it('should return the anonynous user avatar image url when user does not have avatarId', async(() => {
it('should return the anonymous user avatar image url when user does not have avatarId', () => {
fakeBpmService.respondWithTheUserWithoutImage();
userInfoComp.ngOnInit();
fixture.whenStable()
.then( () => {
fixture.detectChanges();
let res = userInfoComp.getBpmUserDetailAvatarUrl();
expect(userInfoComp.bpmUserImage).toBeUndefined();
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
});
}));
.then(() => {
fixture.detectChanges();
let res = userInfoComp.getBpmUserAvatar();
expect(res).toBeDefined();
expect(element.querySelector('#logged-user-img').getAttribute('src'))
.toContain('src/img/anonymous.gif');
});
});
});
describe('when user is logged on bpm and ecm', () => {
beforeEach( async(() => {
authStub = fixture.debugElement.injector.get(AlfrescoAuthenticationService);
beforeEach(async(() => {
stubSetting = fixture.debugElement.injector.get(AlfrescoSettingsService);
fakeBpmService = fixture.debugElement.injector.get(BpmUserService);
fakeEcmService = fixture.debugElement.injector.get(EcmUserService);
authStub.setIsBpmLoggedIn(true);
authStub.setIsEcmLoggedIn(true);
fixture.detectChanges(); // runs ngOnInit -> getUsers
stubSetting.setProviders('ALL');
fixture.detectChanges();
fixture.whenStable()
.then( () => {
fixture.detectChanges();
} );
.then(() => {
fixture.detectChanges();
});
}));
it('should get the bpm current user image from the service', () => {
expect(userInfoComp.bpmUser).toBeDefined();
expect(userInfoComp.bpmUserImage).toBeDefined();
expect(userInfoComp.bpmUserImage).toEqual('fake-picture-id');
expect(userInfoComp.ecmUser).toBeDefined();
expect(userInfoComp.ecmUserImage).toBeDefined();
expect(userInfoComp.ecmUserImage).toEqual('fake/url/image/for/ecm/user');
});
it('should get the bpm user informations from the service', () => {
expect(userInfoComp.bpmUser).toBeDefined();
expect(userInfoComp.bpmUser.firstName).toEqual('fake-first-name');
expect(userInfoComp.bpmUser.lastName).toEqual('fake-last-name');
expect(userInfoComp.ecmUser).toBeDefined();
expect(userInfoComp.ecmUser.firstName).toEqual('fake-first-name');
expect(userInfoComp.ecmUser.lastName).toEqual('fake-last-name');
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#bpm_username')).toBeDefined();
expect(element.querySelector('#bpm_title')).toBeDefined();
expect(element.querySelector('#bpm-user-detail-image')).toBeDefined();
expect(element.querySelector('#bpm-user-detail-image').getAttribute('src')).toEqual('src/assets/bpmImg.gif');
expect(element.querySelector('#bpm-full-name').innerHTML).toContain('fake-first-name fake-last-name');
expect(element.querySelector('#bpm-tenant').innerHTML).toContain('fake-tenant-name');
});
it('should return the anonynous user avatar image url when user does not have avatarId', async(() => {
it('should get the ecm user informations from the service', () => {
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#ecm_username')).toBeDefined();
expect(element.querySelector('#ecm_title')).toBeDefined();
expect(element.querySelector('#ecm-user-detail-image')).toBeDefined();
expect(element.querySelector('#ecm-user-detail-image').getAttribute('src')).toEqual('src/assets/ecmImg.gif');
expect(element.querySelector('#ecm-full-name').innerHTML).toContain('fake-first-name fake-last-name');
expect(element.querySelector('#ecm-job-title').innerHTML).toContain('test job');
});
it('should return the anonymous avatar when users do not have images', () => {
fakeBpmService.respondWithTheUserWithoutImage();
fakeEcmService.respondWithTheUserWithoutImage();
userInfoComp.ngOnInit();
fixture.whenStable()
.then( () => {
fixture.detectChanges();
let resBpm = userInfoComp.getBpmUserDetailAvatarUrl();
expect(userInfoComp.bpmUserImage).toBeUndefined();
expect(resBpm).toEqual(userInfoComp.anonymouseImageUrl);
let resEcm = userInfoComp.getEcmUserDetailAvatarUrl();
expect(userInfoComp.ecmUserImage).toBeUndefined();
expect(resEcm).toEqual(userInfoComp.anonymouseImageUrl);
});
}));
.then(() => {
fixture.detectChanges();
let res = userInfoComp.getUserAvatar();
expect(res).toBeDefined();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#logged-user-img')).toBeDefined();
expect(element.querySelector('#logged-user-img').getAttribute('src')).toContain('src/img/anonymous.gif');
});
});
it('should return the ecm image if exists', async(() => {
it('should show the ecm image if exists', () => {
fakeBpmService.respondWithTheUserWithImage();
fakeEcmService.respondWithTheUserWithImage();
userInfoComp.ngOnInit();
fixture.whenStable()
.then( () => {
fixture.detectChanges();
let res = userInfoComp.getUserAvatar();
expect(userInfoComp.bpmUserImage).toBeDefined();
expect(userInfoComp.ecmUserImage).toBeDefined();
expect(res).toEqual(userInfoComp.ecmUserImage);
});
}));
.then(() => {
fixture.detectChanges();
let res = userInfoComp.getUserAvatar();
expect(res).toBeDefined();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#logged-user-img')).toBeDefined();
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('src/assets/ecmImg.gif');
});
});
it('should return the bpm image if ecm does not have it', async(() => {
it('should show the bpm image if ecm does not have it', () => {
fakeBpmService.respondWithTheUserWithImage();
fakeEcmService.respondWithTheUserWithoutImage();
userInfoComp.ngOnInit();
fixture.whenStable()
.then( () => {
fixture.detectChanges();
let res = userInfoComp.getUserAvatar();
expect(userInfoComp.bpmUserImage).toBeDefined();
expect(userInfoComp.ecmUserImage).toBeUndefined();
expect(res).toEqual(userInfoComp.bpmUserImage);
});
}));
it('should return the anonynous avatar if no user has it', async(() => {
fakeBpmService.respondWithTheUserWithoutImage();
fakeEcmService.respondWithTheUserWithoutImage();
userInfoComp.ngOnInit();
fixture.whenStable()
.then( () => {
fixture.detectChanges();
let res = userInfoComp.getUserAvatar();
expect(userInfoComp.bpmUserImage).toBeUndefined();
expect(userInfoComp.ecmUserImage).toBeUndefined();
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
});
}));
.then(() => {
fixture.detectChanges();
let res = userInfoComp.getUserAvatar();
expect(res).toBeDefined();
expect(element.querySelector('#userinfo_container')).toBeDefined();
expect(element.querySelector('#logged-user-img')).toBeDefined();
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('src/assets/bpmImg.gif');
});
});
});
});

View File

@@ -20,7 +20,7 @@ import { EcmUserModel } from './../models/ecm-user.model';
import { BpmUserModel } from './../models/bpm-user.model';
import { EcmUserService } from './../services/ecm-user.service';
import { BpmUserService } from './../services/bpm-user.service';
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
@Component({
selector: 'ng2-alfresco-userinfo',
@@ -35,58 +35,58 @@ export class UserInfoComponent implements OnInit {
ecmUser: EcmUserModel;
bpmUser: BpmUserModel;
anonymouseImageUrl: string = this.baseComponentPath + 'img/anonymous.gif';
anonymousImageUrl: string = this.baseComponentPath + 'img/anonymous.gif';
bpmUserImage: any;
ecmUserImage: any;
constructor(private ecmUserService: EcmUserService,
private bpmUserService: BpmUserService,
public authService: AlfrescoAuthenticationService) {
public setting: AlfrescoSettingsService) {
}
ngOnInit() {
if ( this.authService.isEcmLoggedIn() ) {
if (this.setting.getProviders() === 'ECM' ||
this.setting.getProviders() === 'ALL') {
this.ecmUserService.getCurrentUserInfo()
.subscribe(
(res) => {
this.ecmUser = <EcmUserModel> res;
this.getEcmUserProfileImage();
}
);
.subscribe((res) => {
this.ecmUser = <EcmUserModel> res;
this.getEcmAvatar();
}
);
}
if ( this.authService.isBpmLoggedIn() ) {
if (this.setting.getProviders() === 'BPM' ||
this.setting.getProviders() === 'ALL') {
this.bpmUserService.getCurrentUserInfo()
.subscribe((res) => {
this.bpmUser = <BpmUserModel> res;
});
this.bpmUserService.getCurrentUserProfileImage()
.subscribe(
(res) => {
this.bpmUser = <BpmUserModel> res;
this.getBpmUserProfileImage();
}
);
this.bpmUserImage = res;
}
);
}
}
private getBpmUserProfileImage() {
this.bpmUserImage = this.bpmUserService.getCurrentUserProfileImage();
private getEcmAvatar() {
this.ecmUserImage = this.ecmUserService.getUserProfileImage(this.ecmUser.avatarId);
}
private getEcmUserProfileImage() {
this.ecmUserImage = this.ecmUserService.getCurrentUserProfileImageUrl(this.ecmUser.avatarId);
getUserAvatar() {
return this.ecmUserImage || this.bpmUserImage || this.anonymousImageUrl;
}
public getUserAvatar() {
return this.ecmUserImage || this.bpmUserImage || this.anonymouseImageUrl;
getBpmUserAvatar() {
return this.bpmUserImage || this.anonymousImageUrl;
}
public getBpmUserDetailAvatarUrl() {
return this.bpmUserImage || this.anonymouseImageUrl;
getEcmUserAvatar() {
return this.ecmUserImage || this.anonymousImageUrl;
}
public getEcmUserDetailAvatarUrl() {
return this.ecmUserImage || this.anonymouseImageUrl;
}
public formatValue(value: string) {
formatValue(value: string) {
return value === 'null' ? null : value;
}
}

View File

@@ -15,132 +15,92 @@
* limitations under the License.
*/
import { ReflectiveInjector } from '@angular/core';
import { BpmUserService } from '../services/bpm-user.service';
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
import { TestBed, async, inject } from '@angular/core/testing';
import { BpmUserModel } from '../models/bpm-user.model';
// import { BpmUserModel } from '../models/bpm-user.model';
import { AlfrescoAuthenticationService, AlfrescoApiService, AlfrescoSettingsService } from 'ng2-alfresco-core';
import { fakeBpmUser } from '../assets/fake-bpm-user.service.mock';
export var fakeBpmUser: BpmUserModel = {
apps: {},
capabilities: 'fake-capability',
company: 'fake-company',
created: 'fake-create-date',
email: 'fakeBpm@fake.com',
externalId: 'fake-external-id',
firstName: 'fake-first-name',
lastName: 'fake-last-name',
fullname: 'fake-full-name',
groups: {},
id: 'fake-id',
lastUpdate: 'fake-update-date',
latestSyncTimeStamp: 'fake-timestamp',
password: 'fake-password',
pictureId: 'fake-picture-id',
status: 'fake-status',
tenantId: 'fake-tenant-id',
tenantName: 'fake-tenant-name',
tenantPictureId: 'fake-tenant-picture-id',
type: 'fake-type'
};
class StubAuthentication {
isEcmConnected: boolean;
isBpmConnected: boolean;
setIsEcmLoggedIn(logged: boolean) { this.isEcmConnected = logged; };
setIsBpmLoggedIn(logged: boolean) { this.isBpmConnected = logged; };
isEcmLoggedIn() { return this.isEcmConnected; };
isBpmLoggedIn() { return this.isBpmConnected; };
callApiGetPersonInfo() { return Promise.resolve(fakeBpmUser); };
};
declare let jasmine: any;
describe('Bpm User service', () => {
beforeEach( async(() => {
TestBed.configureTestingModule({
providers: [ BpmUserService,
{ provide: AlfrescoAuthenticationService, useClass: StubAuthentication }
]
})
.compileComponents();
}));
let service, injector, authService;
it('can instantiate service when inject service',
inject([BpmUserService], (service: BpmUserService) => {
expect(service instanceof BpmUserService).toBe(true);
}));
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
BpmUserService
]);
});
it('can instantiate service with authorization', inject([AlfrescoAuthenticationService],
(auth: AlfrescoAuthenticationService) => {
expect(auth).not.toBeNull('authorization should be provided');
let service = new BpmUserService(auth);
expect(service instanceof BpmUserService).toBe(true, 'new service should be ok');
}));
beforeEach(() => {
service = injector.get(BpmUserService);
authService = injector.get(AlfrescoAuthenticationService);
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('can instantiate service with authorization', () => {
let serviceTest = new BpmUserService(authService);
expect(serviceTest instanceof BpmUserService).toBe(true, 'new service should be ok');
});
describe('when user is logged in', () => {
let service: BpmUserService;
let authServiceForTest: AlfrescoAuthenticationService;
beforeEach(
inject(
[AlfrescoAuthenticationService ],
( authService: AlfrescoAuthenticationService ) => {
authServiceForTest = authService;
service = new BpmUserService(authService);
spyOn(authServiceForTest, 'isBpmLoggedIn').and.returnValue(true);
}));
it('should be able to retrieve current user info', (done) => {
spyOn(service, 'callApiGetProfile').and.returnValue(Promise.resolve(fakeBpmUser));
service.getCurrentUserInfo().subscribe(
(user) => {
expect(user).toBeDefined();
expect(user.firstName).toEqual('fake-first-name');
expect(user.lastName).toEqual('fake-last-name');
expect(user.email).toEqual('fakeBpm@fake.com');
done();
});
});
service.getCurrentUserInfo().subscribe(
(user) => {
expect(user.fakeBpmUser).toBeDefined();
expect(user.fakeBpmUser.firstName).toEqual('fake-first-name');
expect(user.fakeBpmUser.lastName).toEqual('fake-last-name');
expect(user.fakeBpmUser.email).toEqual('fakeBpm@fake.com');
done();
});
it('should retrieve current logged user information via js api', () => {
spyOn(service, 'callApiGetProfile');
service.getCurrentUserInfo();
expect(service.callApiGetProfile).toHaveBeenCalled();
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {fakeBpmUser}
});
});
it('should retrieve avatar url for current user', (done) => {
spyOn(service, 'callApiGetProfilePicture').and.returnValue(Promise.resolve('fake/img/path'));
service.getCurrentUserProfileImage().subscribe(
(path) => {
expect(path).toBeDefined();
expect(path).toEqual('fake/img/path');
done();
});
});
});
describe('when user is not logged in', () => {
let service: BpmUserService;
let authServiceForTest: AlfrescoAuthenticationService;
beforeEach(
inject(
[AlfrescoAuthenticationService],
(authService: AlfrescoAuthenticationService) => {
authServiceForTest = authService;
service = new BpmUserService(authService);
spyOn(authServiceForTest, 'isBpmLoggedIn').and.returnValue(false);
}));
it('should not retrieve the user information', () => {
spyOn(service, 'callApiGetProfile');
service.getCurrentUserInfo();
expect(service.callApiGetProfile).not.toHaveBeenCalled();
spyOn(service, 'callGetProfilePictureApi').and.returnValue(Promise.resolve('fake/img/path'));
service.getCurrentUserProfileImage().subscribe(
(path) => {
expect(path).toBeDefined();
expect(path).toEqual('fake/img/path');
done();
});
});
it('should not retrieve the user avatar', () => {
spyOn(service, 'callApiGetProfilePicture');
service.getCurrentUserInfo();
expect(service.callApiGetProfilePicture).not.toHaveBeenCalled();
it('should catch errors on call for profile', (done) => {
service.getCurrentUserInfo().subscribe(() => {
}, () => {
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 403
});
});
it('should catch errors on call for profile picture', (done) => {
service.getCurrentUserProfileImage().subscribe(() => {
}, () => {
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 403
});
});
});
});

View File

@@ -37,42 +37,19 @@ export class BpmUserService {
* @param userName - the user name
*/
getCurrentUserInfo(): Observable<BpmUserModel> {
if ( this.authService.isBpmLoggedIn() ) {
return Observable.fromPromise(this.callApiGetProfile())
.map(
(data) => <BpmUserModel> data
)
.catch(this.handleError);
}
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile())
.map((data) => <BpmUserModel> data)
.catch(this.handleError);
}
getCurrentUserProfileImage(): any {
if ( this.authService.isBpmLoggedIn() ) {
return Observable.fromPromise(this.callApiGetProfilePicture())
.map(
(data) => data
)
.catch(this.handleError);
}
getCurrentUserProfileImage(): Observable<any> {
return Observable.fromPromise(this.callGetProfilePictureApi())
.map((data) => data)
.catch(this.handleError);
}
/**
* Call js api to get current user profile picture
*/
callApiGetProfilePicture() {
try {
return this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture();
} catch (exc) {
console.error(exc);
return null;
}
}
/**
* Call js api to get current user information
*/
callApiGetProfile() {
return this.authService.getAlfrescoApi().activiti.profileApi.getProfile();
private callGetProfilePictureApi() {
return this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture();
}
/**

View File

@@ -15,165 +15,111 @@
* limitations under the License.
*/
import { ReflectiveInjector } from '@angular/core';
import {
AlfrescoAuthenticationService,
AlfrescoApiService,
AlfrescoSettingsService,
AlfrescoContentService
} from 'ng2-alfresco-core';
import { EcmUserService } from '../services/ecm-user.service';
import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core';
import { TestBed, async, inject } from '@angular/core/testing';
import { EcmUserModel } from '../models/ecm-user.model';
import { EcmCompanyModel } from '../models/ecm-company.model';
import { fakeEcmUser } from '../assets/fake-ecm-user.service.mock';
export var fakeEcmCompany: EcmCompanyModel = {
organization: 'company-fake-name',
address1: 'fake-address-1',
address2: 'fake-address-2',
address3: 'fake-address-3',
postcode: 'fAk1',
telephone: '00000000',
fax: '=1111111',
email: 'fakeCompany@fake.com'
};
export var fakeEcmUser: EcmUserModel = {
id: 'fake-id',
firstName: 'fake-first-name',
lastName: 'fake-last-name',
description: 'i am a fake user for test',
avatarId: 'fake-avatar-id',
email: 'fakeEcm@ecmUser.com',
skypeId: 'fake-skype-id',
googleId: 'fake-googleId-id',
instantMessageId: 'fake-instantMessageId-id',
company: fakeEcmCompany,
jobTitle: 'test job',
location: 'fake location',
mobile: '000000000',
telephone: '11111111',
statusUpdatedAt: 'fake-date',
userStatus: 'active',
enabled: true,
emailNotificationsEnabled: true
};
class StubAuthentication {
isEcmConnected: boolean;
isBpmConnected: boolean;
setIsEcmLoggedIn(logged: boolean) { this.isEcmConnected = logged; };
setIsBpmLoggedIn(logged: boolean) { this.isBpmConnected = logged; };
isEcmLoggedIn() { return this.isEcmConnected; };
isBpmLoggedIn() { return this.isBpmConnected; };
callApiGetPersonInfo() { return Promise.resolve(fakeEcmUser); };
};
class StubAlfrescoContentService {
getContentUrl() { return 'fake/url/image/for/ecm/user'; } ;
}
declare let jasmine: any;
describe('Ecm User service', () => {
beforeEach( async(() => {
TestBed.configureTestingModule({
providers: [ EcmUserService,
{ provide: AlfrescoAuthenticationService, useClass: StubAuthentication },
{ provide: AlfrescoContentService, useClass: StubAlfrescoContentService }
]
})
.compileComponents();
}));
let service, injector, authService, contentService;
it('can instantiate service when inject service',
inject([EcmUserService], (service: EcmUserService) => {
expect(service instanceof EcmUserService).toBe(true);
}));
beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([
AlfrescoSettingsService,
AlfrescoApiService,
AlfrescoAuthenticationService,
AlfrescoContentService,
EcmUserService
]);
});
it('can instantiate service with authorization', inject([AlfrescoAuthenticationService],
(auth: AlfrescoAuthenticationService) => {
expect(auth).not.toBeNull('authorization should be provided');
let service = new EcmUserService(auth, null);
expect(service instanceof EcmUserService).toBe(true, 'new service should be ok');
}));
beforeEach(() => {
service = injector.get(EcmUserService);
authService = injector.get(AlfrescoAuthenticationService);
contentService = injector.get(AlfrescoContentService);
});
it('can instantiate service with content service', inject([AlfrescoContentService],
(content: AlfrescoContentService) => {
expect(content).not.toBeNull('contentService should be provided');
let service = new EcmUserService(null, content);
expect(service instanceof EcmUserService).toBe(true, 'new service should be ok');
}));
it('can instantiate service with authorization', () => {
expect(authService).not.toBeNull('authorization should be provided');
let serviceAuth = new EcmUserService(authService, null);
expect(serviceAuth instanceof EcmUserService).toBe(true, 'new service should be ok');
});
it('can instantiate service with content service', () => {
expect(contentService).not.toBeNull('contentService should be provided');
let serviceContent = new EcmUserService(null, contentService);
expect(serviceContent instanceof EcmUserService).toBe(true, 'new service should be ok');
});
describe('when user is logged in', () => {
let service: EcmUserService;
let authServiceForTest: AlfrescoAuthenticationService;
let contentServiceForTest: AlfrescoContentService;
beforeEach(
inject(
[AlfrescoAuthenticationService, AlfrescoContentService],
(authService: AlfrescoAuthenticationService, content: AlfrescoContentService) => {
authServiceForTest = authService;
contentServiceForTest = content;
service = new EcmUserService(authService, content);
spyOn(authServiceForTest, 'isEcmLoggedIn').and.returnValue(true);
}));
it('should be able to retrieve current user info', (done) => {
let userJsApiResponse = {entry: fakeEcmUser};
spyOn(service, 'callApiGetPersonInfo').and.returnValue(Promise.resolve(userJsApiResponse));
service.getCurrentUserInfo().subscribe(
(user) => {
expect(user).toBeDefined();
expect(user.firstName).toEqual('fake-first-name');
expect(user.lastName).toEqual('fake-last-name');
expect(user.email).toEqual('fakeEcm@ecmUser.com');
done();
});
beforeEach(() => {
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
jasmine.Ajax.install();
});
it('should retrieve current logged user information', () => {
spyOn(service, 'getUserInfo');
spyOn(service, 'callApiGetPersonInfo').and.callThrough();
service.getCurrentUserInfo();
expect(service.getUserInfo).toHaveBeenCalledWith('-me-');
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('should be able to retrieve current user info', (done) => {
service.getCurrentUserInfo().subscribe(
(user) => {
expect(user).toBeDefined();
expect(user.firstName).toEqual('fake-first-name');
expect(user.lastName).toEqual('fake-last-name');
expect(user.email).toEqual('fakeEcm@ecmUser.com');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: {entry: fakeEcmUser}
});
});
it('should be able to log errors on call', (done) => {
service.getCurrentUserInfo().subscribe(() => {
}, () => {
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 403
});
});
it('should retrieve avatar url for current user', () => {
spyOn(contentServiceForTest, 'getContentUrl').and.returnValue('fake/url/image/for/ecm/user');
let urlRs = service.getCurrentUserProfileImageUrl('fake-avatar-id');
spyOn(contentService, 'getContentUrl').and.returnValue('fake/url/image/for/ecm/user');
let urlRs = service.getUserProfileImage('fake-avatar-id');
expect(urlRs).toEqual('fake/url/image/for/ecm/user');
expect(urlRs).toEqual('fake/url/image/for/ecm/user');
});
it('should not call content service without avatar id', () => {
spyOn(contentServiceForTest, 'getContentUrl').and.callThrough();
let urlRs = service.getCurrentUserProfileImageUrl(undefined);
expect(urlRs).toBeUndefined();
expect(contentServiceForTest.getContentUrl).not.toHaveBeenCalled();
spyOn(contentService, 'getContentUrl').and.callThrough();
let urlRs = service.getUserProfileImage(undefined);
expect(urlRs).toBeUndefined();
expect(contentService.getContentUrl).not.toHaveBeenCalled();
});
it('should build the body for the content service', () => {
spyOn(contentServiceForTest, 'getContentUrl').and.callThrough();
let urlRs = service.getCurrentUserProfileImageUrl('fake-avatar-id');
expect(urlRs).toBeDefined();
expect(contentServiceForTest.getContentUrl).toHaveBeenCalledWith( {entry: {id: 'fake-avatar-id'} });
});
});
spyOn(contentService, 'getContentUrl').and.callThrough();
let urlRs = service.getUserProfileImage('fake-avatar-id');
describe('when user is not logged in', () => {
let service: EcmUserService;
let authServiceForTest: AlfrescoAuthenticationService;
let contentServiceForTest: AlfrescoContentService;
beforeEach(
inject(
[AlfrescoAuthenticationService, AlfrescoContentService],
(authService: AlfrescoAuthenticationService, content: AlfrescoContentService) => {
authServiceForTest = authService;
contentServiceForTest = content;
service = new EcmUserService(authService, content);
spyOn(authServiceForTest, 'isEcmLoggedIn').and.returnValue(false);
}));
it('should not retrieve the user information', () => {
spyOn(service, 'callApiGetPersonInfo');
service.getCurrentUserInfo();
expect(service.callApiGetPersonInfo).not.toHaveBeenCalled();
expect(urlRs).toBeDefined();
expect(contentService.getContentUrl).toHaveBeenCalledWith({entry: {id: 'fake-avatar-id'}});
});
});
});

View File

@@ -30,35 +30,34 @@ import { EcmUserModel } from '../models/ecm-user.model';
export class EcmUserService {
constructor(private authService: AlfrescoAuthenticationService,
private contentService: AlfrescoContentService) {}
private contentService: AlfrescoContentService) {
}
/**
* get User Information via ECM
* @param userName - the user name
*/
getUserInfo(userName: string): Observable<EcmUserModel> {
if ( this.authService.isEcmLoggedIn() ) {
return Observable.fromPromise(this.callApiGetPersonInfo(userName))
.map(
(data) => <EcmUserModel> data['entry']
)
(data) => <EcmUserModel> data['entry']
)
.catch(this.handleError);
}
}
getCurrentUserInfo() {
return this.getUserInfo('-me-');
}
callApiGetPersonInfo(userName: string, opts?: any) {
private callApiGetPersonInfo(userName: string, opts?: any) {
return this.authService.getAlfrescoApi().core.peopleApi.getPerson(userName, opts);
}
getCurrentUserProfileImageUrl(avatarId: string) {
if ( avatarId ) {
getUserProfileImage(avatarId: string) {
if (avatarId) {
let nodeObj = {entry: {id: avatarId}};
return this.contentService.getContentUrl(nodeObj);
}
}
}
/**

View File

@@ -1,107 +0,0 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// re-export for tester convenience
export { EcmUserModel } from '../models/ecm-user.model';
export { EcmUserService } from '../services/ecm-user.service';
import { EcmUserModel } from '../models/ecm-user.model';
import { EcmCompanyModel } from '../models/ecm-company.model';
import { Observable } from 'rxjs/Rx';
export var fakeEcmCompany: EcmCompanyModel = {
organization: 'company-fake-name',
address1: 'fake-address-1',
address2: 'fake-address-2',
address3: 'fake-address-3',
postcode: 'fAk1',
telephone: '00000000',
fax: '11111111',
email: 'fakeCompany@fake.com'
};
export var fakeEcmUserNoImage: EcmUserModel = {
id: 'fake-id',
firstName: 'fake-first-name',
lastName: 'fake-last-name',
description: 'i am a fake user for test',
avatarId: undefined,
email: 'fakeEcm@ecmUser.com',
skypeId: 'fake-skype-id',
googleId: 'fake-googleId-id',
instantMessageId: 'fake-instantMessageId-id',
company: fakeEcmCompany,
jobTitle: 'test job',
location: 'fake location',
mobile: '000000000',
telephone: '11111111',
statusUpdatedAt: 'fake-date',
userStatus: 'active',
enabled: true,
emailNotificationsEnabled: true
};
export var fakeEcmUser: EcmUserModel = {
id: 'fake-id',
firstName: 'fake-first-name',
lastName: 'fake-last-name',
description: 'i am a fake user for test',
avatarId: 'fake-avatar-id',
email: 'fakeEcm@ecmUser.com',
skypeId: 'fake-skype-id',
googleId: 'fake-googleId-id',
instantMessageId: 'fake-instantMessageId-id',
company: fakeEcmCompany,
jobTitle: 'test job',
location: 'fake location',
mobile: '000000000',
telephone: '11111111',
statusUpdatedAt: 'fake-date',
userStatus: 'active',
enabled: true,
emailNotificationsEnabled: true
};
export class FakeEcmUserService {
lastPromise: Observable<EcmUserModel>;
public userNeeded = 0;
usersList = [fakeEcmUser, fakeEcmUserNoImage];
getUserInfo(userName: string) {
return this.lastPromise = Observable.of(this.usersList[this.userNeeded]);
};
getCurrentUserInfo() {
return this.getUserInfo('fake-id');
};
getCurrentUserProfileImageUrl(avatarId: string) {
if ( avatarId ) {
return 'fake/url/image/for/ecm/user';
}
};
respondWithTheUserWithoutImage() {
this.userNeeded = 1;
};
respondWithTheUserWithImage() {
this.userNeeded = 0;
};
}