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 7081ff070e..5c8e9b129e 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 @@ -144,6 +144,32 @@ describe('AlfrescoAuthentication', () => { }); }); + it('ticket should be deleted only after logout request is accepted', (done) => { + + authService.login('fake-username', 'fake-password').subscribe(() => { + let logoutPromise = authService.logout(); + + expect(authService.getTicketEcm()).toBe('fake-post-ticket'); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 204 + }); + + logoutPromise.subscribe(() => { + expect(authService.isLoggedIn()).toBe(false); + expect(authService.isEcmLoggedIn()).toBe(false); + done(); + }); + + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 201, + contentType: 'application/json', + responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}}) + }); + }); + it('should return false if the user is not logged in', () => { expect(authService.isLoggedIn()).toBe(false); expect(authService.isEcmLoggedIn()).toBe(false); @@ -200,6 +226,30 @@ describe('AlfrescoAuthentication', () => { }); }); + it('ticket should be deleted only after logout request is accepted', (done) => { + + authService.login('fake-username', 'fake-password').subscribe(() => { + let logoutPromise = authService.logout(); + + expect(authService.getTicketBpm()).toBe('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk'); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 200 + }); + + logoutPromise.subscribe(() => { + expect(authService.isLoggedIn()).toBe(false); + expect(authService.isBpmLoggedIn()).toBe(false); + done(); + }); + + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 200 + }); + }); + it('should return a ticket undefined after logout', (done) => { authService.login('fake-username', 'fake-password').subscribe(() => { authService.logout().subscribe(() => { 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 870320a27b..dcf54e0343 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoAuthentication.service.ts @@ -114,10 +114,10 @@ export class AlfrescoAuthenticationService { * @returns {Observable|Observable} */ public logout() { - this.removeTicket(); return Observable.fromPromise(this.callApiLogout()) .map(res => res) .do(response => { + this.removeTicket(); this.logoutSubject.next(response); return response; })