From 1aa7f27b8bc4ebf9e51a5cd9f8aca352abf232a2 Mon Sep 17 00:00:00 2001 From: VitoAlbano Date: Fri, 22 Aug 2025 13:32:56 +0100 Subject: [PATCH] AAE-30882 - Fixed unit test for js-api --- lib/js-api/test/ecmAuth.spec.ts | 16 ++++++++-------- .../content-services/ecm-auth.mock.ts | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/js-api/test/ecmAuth.spec.ts b/lib/js-api/test/ecmAuth.spec.ts index 94a0e705b3..7d51635afd 100644 --- a/lib/js-api/test/ecmAuth.spec.ts +++ b/lib/js-api/test/ecmAuth.spec.ts @@ -48,20 +48,20 @@ describe('Ecm Auth test', () => { assert.equal(auth.authentications.basicAuth.username, 'johndoe'); }); - it('should forget username on logout', (done) => { + it('should forget username on logout', async () => { const auth = new ContentAuth({}, alfrescoJsApi); - authEcmMock.get201Response(); + authEcmMock.get201ResponseJohnDoe(); - auth.login('johndoe', 'password'); - assert.equal(auth.authentications.basicAuth.username, 'johndoe'); + await auth.login('johndoe', 'password'); + assert.equal(auth.authentications.basicAuth.username, 'ROLE_TICKET'); + assert.equal(auth.storage.getItem('ACS_USERNAME'), 'johndoe'); authEcmMock.get204ResponseLogout(); - auth.logout().then(() => { - assert.equal(auth.authentications.basicAuth.username, null); - done(); - }); + await auth.logout(); + assert.equal(auth.authentications.basicAuth.username, null); + assert.equal(auth.storage.getItem('ACS_USERNAME'), ''); }); describe('With Authentication', () => { diff --git a/lib/js-api/test/mockObjects/content-services/ecm-auth.mock.ts b/lib/js-api/test/mockObjects/content-services/ecm-auth.mock.ts index 57ac9478d0..dd109fdd40 100644 --- a/lib/js-api/test/mockObjects/content-services/ecm-auth.mock.ts +++ b/lib/js-api/test/mockObjects/content-services/ecm-auth.mock.ts @@ -44,6 +44,22 @@ export class EcmAuthMock extends BaseMock { }); } + get201ResponseJohnDoe(forceTicket?: string): void { + const returnMockTicket = forceTicket || 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1'; + + this.createNockWithCors() + .post('/alfresco/api/-default-/public/authentication/versions/1/tickets', { + userId: 'johndoe', + password: 'password' + }) + .reply(201, { + entry: { + id: returnMockTicket, + userId: 'johndoe' + } + }); + } + get200ValidTicket(forceTicket?: string): void { const returnMockTicket = forceTicket || 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1';