diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts index 73791070b5..c43a10b753 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.spec.ts @@ -84,6 +84,21 @@ describe('AlfrescoAuthentication', () => { }); }); + it('should save only ECM ticket on localStorage', (done) => { + authService.login('fake-username', 'fake-password').subscribe(() => { + expect(authService.isLoggedIn()).toBe(true); + expect(authService.getTicketBpm()).toBeNull(); + expect(authService.getAlfrescoApi().bpmAuth.isLoggedIn()).toBeFalsy(); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 201, + contentType: 'application/json', + responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}}) + }); + }); + it('should return ticket undefined when the credentials are wrong', (done) => { authService.login('fake-wrong-username', 'fake-wrong-password').subscribe( (res) => { @@ -164,6 +179,21 @@ describe('AlfrescoAuthentication', () => { }); }); + it('should save only BPM ticket on localStorage', (done) => { + authService.login('fake-username', 'fake-password').subscribe(() => { + expect(authService.isLoggedIn()).toBe(true); + expect(authService.getTicketEcm()).toBeNull(); + expect(authService.getAlfrescoApi().ecmAuth.isLoggedIn()).toBeFalsy(); + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 201, + contentType: 'application/json', + responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}}) + }); + }); + it('should return ticket undefined when the credentials are wrong', (done) => { authService.login('fake-wrong-username', 'fake-wrong-password').subscribe( (res) => { diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts index 50313d5c89..fed60c3356 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts @@ -177,7 +177,7 @@ export class AlfrescoAuthenticationService { * The method save the ECM ticket in the localStorage */ public saveTicketEcm(): void { - if (this.alfrescoApi) { + if (this.alfrescoApi && this.alfrescoApi.getTicketEcm()) { localStorage.setItem('ticket-ECM', this.alfrescoApi.getTicketEcm()); } } @@ -186,7 +186,7 @@ export class AlfrescoAuthenticationService { * The method save the BPM ticket in the localStorage */ public saveTicketBpm(): void { - if (this.alfrescoApi) { + if (this.alfrescoApi && this.alfrescoApi.getTicketBpm()) { localStorage.setItem('ticket-BPM', this.alfrescoApi.getTicketBpm()); } }