AAE-30882 Replace superagent (#11134)

* [AAE-30878] - Migrating from event-emitter to eventemitter3 which is ESM and commonJs compatibile

* [AAE-30878] - Using types to avoid compilation isues with the new ruels

* AAE-30878 - fixed lint issue on js-api

* AAE-30878 - reverted misplaced changes

* [AAE-30882] - migrating from superagent to axios

* AAE-30882 - Fixed unit test for js-api

* AAE-30882 - Fixed unit test for js-api

* AAE-30882 - Fixed unit test for js-api

* AAE-30882 - Improved some unit tests

* [ci:force]

* AAE-30882 - Checking why is ok locally but fails on CI

* AAE-30882 - Start fixing some unit tests - check 1

* AAE-30882 - Start fixing some unit tests - check 2

* [AAE-30882] - rebased

* [AAE-30882] - added missing import
This commit is contained in:
Vito Albano
2025-09-16 11:31:07 +01:00
committed by GitHub
parent b400757ad1
commit a347b20f20
55 changed files with 1105 additions and 863 deletions

View File

@@ -44,24 +44,25 @@ describe('Ecm Auth test', () => {
it('should remember username on login', () => {
const auth = new ContentAuth({}, alfrescoJsApi);
authEcmMock.get201ResponseJohnDoe();
auth.login('johndoe', 'password');
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', () => {
@@ -128,16 +129,15 @@ describe('Ecm Auth test', () => {
);
});
it('login should return an error if wrong credential are used 400 userId and/or password are/is not provided', (done) => {
it('login should return an error if wrong credential are used 400 userId and/or password are/is not provided', async () => {
authEcmMock.get400Response();
contentAuth.login(null, null).then(
() => {},
(error) => {
assert.equal(error.status, 400);
done();
}
);
try {
await contentAuth.login(null, null);
assert.fail('Login should have failed');
} catch (error) {
assert.equal(error.status, 400);
}
});
describe('Events ', () => {
@@ -189,8 +189,6 @@ describe('Ecm Auth test', () => {
describe('With Ticket Authentication', () => {
it('Ticket should be present in the client', () => {
authEcmMock.get400Response();
contentAuth = new ContentAuth(
{
ticketEcm: 'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1',
@@ -212,24 +210,22 @@ describe('Ecm Auth test', () => {
});
});
it('Ticket should be absent in the client and the resolve promise should be called', (done) => {
it('Ticket should be absent in the client and the resolve promise should be called', async () => {
authEcmMock.get204ResponseLogout();
contentAuth.logout().then(() => {
assert.equal(contentAuth.config.ticket, undefined);
done();
});
await contentAuth.logout();
assert.equal(contentAuth.config.ticket, undefined);
});
it('Logout should be rejected if the Ticket is already expired', (done) => {
it('Logout should be rejected if the Ticket is already expired', async () => {
authEcmMock.get404ResponseLogout();
contentAuth.logout().then(
() => {},
(error) => {
assert.equal(error.error.toString(), 'Error: Not Found');
done();
}
);
try {
await contentAuth.logout();
assert.fail('Logout should have failed');
} catch (error) {
assert.equal(error.status, 404);
assert.equal(error.response.data.error.briefSummary, 'Not Found');
}
});
});
});