mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
Improved test readibility and code
This commit is contained in:
parent
1037385295
commit
90332daa64
@ -49,6 +49,8 @@ module.exports = function (config) {
|
||||
// paths to support debugging with source maps in dev tools
|
||||
{pattern: 'src/**/*.ts', included: false, watched: false},
|
||||
{pattern: 'dist/**/*.js.map', included: false, watched: false}
|
||||
// fake file path
|
||||
{ pattern: '/base/dist/src/img/anonymous.gif', included: false, watched: true, served: true }
|
||||
],
|
||||
|
||||
exclude: [
|
||||
|
@ -83,7 +83,7 @@ export class FakeBpmUserService {
|
||||
};
|
||||
|
||||
getCurrentUserProfileImage() {
|
||||
return this.usersList[this.userNeeded].pictureId;
|
||||
return Observable.of(this.usersList[this.userNeeded].pictureId);
|
||||
};
|
||||
|
||||
respondWithTheUserWithoutImage() {
|
@ -0,0 +1,107 @@
|
||||
/*!
|
||||
* @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');
|
||||
};
|
||||
|
||||
getUserProfileImage(avatarId: string) {
|
||||
if (avatarId) {
|
||||
return 'fake/url/image/for/ecm/user';
|
||||
}
|
||||
};
|
||||
|
||||
respondWithTheUserWithoutImage() {
|
||||
this.userNeeded = 1;
|
||||
};
|
||||
|
||||
respondWithTheUserWithImage() {
|
||||
this.userNeeded = 0;
|
||||
};
|
||||
|
||||
}
|
@ -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{
|
||||
|
@ -22,7 +22,7 @@
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<i class="mdl-list__item-avatar">
|
||||
<img id="logged-user-img"
|
||||
[src]="getEcmUserDetailAvatarUrl()"
|
||||
[src]="getEcmUserAvatar()"
|
||||
class="profile-image"/>
|
||||
</i>
|
||||
<span class="truncate-long-names">{{ecmUser.firstName}} {{ecmUser.lastName}}</span>
|
||||
@ -33,8 +33,8 @@
|
||||
{{ ecmUser.jobTitle ? ecmUser.jobTitle : 'N/A' }}
|
||||
</span>
|
||||
</li>
|
||||
<br>
|
||||
</div>
|
||||
<br>
|
||||
<div *ngIf="bpmUser">
|
||||
<hr class="title-start">
|
||||
<span class="header-profile"><b>BPM</b></span>
|
||||
@ -42,7 +42,7 @@
|
||||
<span class="mdl-list__item-primary-content">
|
||||
<i class="mdl-list__item-avatar">
|
||||
<img id="logged-user-img"
|
||||
[src]="getBpmUserDetailAvatarUrl()"
|
||||
[src]="getBpmUserAvatar()"
|
||||
class="profile-image"/>
|
||||
</i>
|
||||
<span class="truncate-long-names">
|
||||
|
@ -18,8 +18,8 @@
|
||||
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 { FakeEcmUserService } from '../assets/fake-ecm-user.service';
|
||||
import { FakeBpmUserService } from '../assets/fake-bpm-user.service';
|
||||
import { AlfrescoAuthenticationService, AlfrescoContentService } from 'ng2-alfresco-core';
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
|
||||
@ -107,7 +107,7 @@ describe('User info component', () => {
|
||||
fixture.whenStable()
|
||||
.then( () => {
|
||||
fixture.detectChanges();
|
||||
let res = userInfoComp.getEcmUserDetailAvatarUrl();
|
||||
let res = userInfoComp.getEcmUserAvatar();
|
||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
||||
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
|
||||
});
|
||||
@ -146,7 +146,7 @@ describe('User info component', () => {
|
||||
fixture.whenStable()
|
||||
.then( () => {
|
||||
fixture.detectChanges();
|
||||
let res = userInfoComp.getBpmUserDetailAvatarUrl();
|
||||
let res = userInfoComp.getBpmUserAvatar();
|
||||
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
||||
expect(res).toEqual(userInfoComp.anonymouseImageUrl);
|
||||
});
|
||||
@ -194,10 +194,10 @@ describe('User info component', () => {
|
||||
fixture.whenStable()
|
||||
.then( () => {
|
||||
fixture.detectChanges();
|
||||
let resBpm = userInfoComp.getBpmUserDetailAvatarUrl();
|
||||
let resBpm = userInfoComp.getBpmUserAvatar();
|
||||
expect(userInfoComp.bpmUserImage).toBeUndefined();
|
||||
expect(resBpm).toEqual(userInfoComp.anonymouseImageUrl);
|
||||
let resEcm = userInfoComp.getEcmUserDetailAvatarUrl();
|
||||
let resEcm = userInfoComp.getEcmUserAvatar();
|
||||
expect(userInfoComp.ecmUserImage).toBeUndefined();
|
||||
expect(resEcm).toEqual(userInfoComp.anonymouseImageUrl);
|
||||
});
|
||||
|
@ -45,43 +45,46 @@ export class UserInfoComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if ( this.authService.isEcmLoggedIn() ) {
|
||||
|
||||
if (this.authService.isEcmLoggedIn()) {
|
||||
this.ecmUserService.getCurrentUserInfo()
|
||||
.subscribe(
|
||||
(res) => {
|
||||
this.ecmUser = <EcmUserModel> res;
|
||||
this.getEcmUserProfileImage();
|
||||
}
|
||||
);
|
||||
this.ecmUser = <EcmUserModel> res;
|
||||
this.getEcmAvatar();
|
||||
}
|
||||
);
|
||||
}
|
||||
if ( this.authService.isBpmLoggedIn() ) {
|
||||
|
||||
if (this.authService.isBpmLoggedIn()) {
|
||||
this.bpmUserService.getCurrentUserInfo()
|
||||
.subscribe(
|
||||
(res) => {
|
||||
this.bpmUser = <BpmUserModel> res;
|
||||
this.getBpmUserProfileImage();
|
||||
}
|
||||
);
|
||||
this.bpmUser = <BpmUserModel> res;
|
||||
}
|
||||
);
|
||||
this.bpmUserService.getCurrentUserProfileImage()
|
||||
.subscribe(
|
||||
(res) => {
|
||||
this.bpmUserImage = res;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private getBpmUserProfileImage() {
|
||||
this.bpmUserImage = this.bpmUserService.getCurrentUserProfileImage();
|
||||
}
|
||||
|
||||
private getEcmUserProfileImage() {
|
||||
this.ecmUserImage = this.ecmUserService.getCurrentUserProfileImageUrl(this.ecmUser.avatarId);
|
||||
private getEcmAvatar() {
|
||||
this.ecmUserImage = this.ecmUserService.getUserProfileImage(this.ecmUser.avatarId);
|
||||
}
|
||||
|
||||
public getUserAvatar() {
|
||||
return this.ecmUserImage || this.bpmUserImage || this.anonymouseImageUrl;
|
||||
return this.ecmUserImage || this.bpmUserImage || this.anonymouseImageUrl;
|
||||
}
|
||||
|
||||
public getBpmUserDetailAvatarUrl() {
|
||||
public getBpmUserAvatar() {
|
||||
return this.bpmUserImage || this.anonymouseImageUrl;
|
||||
}
|
||||
|
||||
public getEcmUserDetailAvatarUrl() {
|
||||
public getEcmUserAvatar() {
|
||||
return this.ecmUserImage || this.anonymouseImageUrl;
|
||||
}
|
||||
|
||||
|
@ -15,132 +15,100 @@
|
||||
* 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 { AlfrescoAuthenticationService, AlfrescoApiService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { fakeBpmUser } from '../assets/fake-bpm-user.service';
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
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();
|
||||
});
|
||||
beforeEach(() => {
|
||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
|
||||
});
|
||||
|
||||
it('should retrieve current logged user information via js api', () => {
|
||||
spyOn(service, 'callApiGetProfile');
|
||||
service.getCurrentUserInfo();
|
||||
expect(service.callApiGetProfile).toHaveBeenCalled();
|
||||
it('should be able to retrieve current user info', (done) => {
|
||||
spyOn(service, 'getCurrentUserProfileImage').and.callThrough();
|
||||
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();
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
service.getCurrentUserProfileImage().subscribe(
|
||||
(path) => {
|
||||
expect(path).toBeDefined();
|
||||
expect(path).toEqual('fake/img/path');
|
||||
done();
|
||||
});
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'json',
|
||||
responseText: 'fake/img/path'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
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);
|
||||
}));
|
||||
beforeEach(() => {
|
||||
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
|
||||
});
|
||||
|
||||
it('should not retrieve the user information', () => {
|
||||
spyOn(service, 'callApiGetProfile');
|
||||
service.getCurrentUserInfo();
|
||||
expect(service.callApiGetProfile).not.toHaveBeenCalled();
|
||||
spyOn(service, 'callApiGetProfile');
|
||||
service.getCurrentUserInfo();
|
||||
expect(service.callApiGetProfile).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not retrieve the user avatar', () => {
|
||||
spyOn(service, 'callApiGetProfilePicture');
|
||||
service.getCurrentUserInfo();
|
||||
expect(service.callApiGetProfilePicture).not.toHaveBeenCalled();
|
||||
spyOn(service, 'callApiGetProfilePicture');
|
||||
service.getCurrentUserInfo();
|
||||
expect(service.callApiGetProfilePicture).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});*/
|
||||
});
|
||||
|
@ -38,7 +38,7 @@ export class BpmUserService {
|
||||
*/
|
||||
getCurrentUserInfo(): Observable<BpmUserModel> {
|
||||
if ( this.authService.isBpmLoggedIn() ) {
|
||||
return Observable.fromPromise(this.callApiGetProfile())
|
||||
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfilePicture())
|
||||
.map(
|
||||
(data) => <BpmUserModel> data
|
||||
)
|
||||
@ -46,9 +46,9 @@ export class BpmUserService {
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentUserProfileImage(): any {
|
||||
getCurrentUserProfileImage(): Observable<any> {
|
||||
if ( this.authService.isBpmLoggedIn() ) {
|
||||
return Observable.fromPromise(this.callApiGetProfilePicture())
|
||||
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.profileApi.getProfile())
|
||||
.map(
|
||||
(data) => data
|
||||
)
|
||||
@ -56,25 +56,6 @@ export class BpmUserService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw the error
|
||||
* @param error
|
||||
|
@ -15,165 +15,100 @@
|
||||
* 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';
|
||||
|
||||
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 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'}});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -37,24 +37,22 @@ export class EcmUserService {
|
||||
* @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']
|
||||
)
|
||||
.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) {
|
||||
getUserProfileImage(avatarId: string) {
|
||||
if ( avatarId ) {
|
||||
let nodeObj = {entry: {id: avatarId}};
|
||||
return this.contentService.getContentUrl(nodeObj);
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user