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

@@ -29,7 +29,15 @@ export class BpmAuthMock extends BaseMock {
}
get200Response(): void {
this.addCorsSupport();
nock(this.host, { encodedQueryParams: true })
.defaultReplyHeaders({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization, Content-Length, X-Requested-With, Cache-Control, X-CSRF-TOKEN',
'Access-Control-Allow-Credentials': 'true',
'Set-Cookie': 'ACTIVITI_REMEMBER_ME=NjdOdGwvcUtFTkVEczQyMGh4WFp5QT09OmpUL1UwdFVBTC94QTJMTFFUVFgvdFE9PQ; Path=/; HttpOnly'
})
.post(
'/activiti-app/app/authentication',
'j_username=' + this.username + '&j_password=' + this.password + '&_spring_security_remember_me=true&submit=Login'
@@ -38,11 +46,11 @@ export class BpmAuthMock extends BaseMock {
}
get200ResponseLogout(): void {
nock(this.host, { encodedQueryParams: true }).get('/activiti-app/app/logout', {}).reply(200);
this.createNockWithCors().get('/activiti-app/app/logout').reply(200);
}
get401Response(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.post('/activiti-app/app/authentication', 'j_username=wrong&j_password=name&_spring_security_remember_me=true&submit=Login')
.reply(401, {
error: {
@@ -53,7 +61,7 @@ export class BpmAuthMock extends BaseMock {
}
get403Response(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.post('/activiti-app/app/authentication', 'j_username=wrong&j_password=name&_spring_security_remember_me=true&submit=Login')
.reply(403, {
error: {

View File

@@ -15,12 +15,11 @@
* limitations under the License.
*/
import nock from 'nock';
import { BaseMock } from '../base.mock';
export class ModelJsonBpmMock extends BaseMock {
get200EditorDisplayJsonClient(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/app/rest/models/1/model-json')
.reply(200, {
elements: [
@@ -87,7 +86,7 @@ export class ModelJsonBpmMock extends BaseMock {
}
get200HistoricEditorDisplayJsonClient(): void {
nock('https://127.0.0.1:9999', { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/app/rest/models/1/history/1/model-json')
.reply(200, {
elements: [

View File

@@ -15,12 +15,11 @@
* limitations under the License.
*/
import nock from 'nock';
import { BaseMock } from '../base.mock';
export class ModelsMock extends BaseMock {
get200getModels(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/models')
.query({ filter: 'myReusableForms', modelType: '2' })
.reply(200, {

View File

@@ -34,13 +34,13 @@ const fakeVariablesList = [fakeVariable1, fakeVariable2];
export class ProcessInstanceVariablesMock extends BaseMock {
addListProcessInstanceVariables200Response(processInstanceId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables')
.reply(200, fakeVariablesList);
}
addListProcessInstanceVariables500Response(processInstanceId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables')
.reply(500, {
messageKey: 'UNKNOWN',
@@ -49,13 +49,13 @@ export class ProcessInstanceVariablesMock extends BaseMock {
}
addPutProcessInstanceVariables200Response(processInstanceId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables')
.reply(200, fakeVariablesList);
}
addPutProcessInstanceVariables500Response(processInstanceId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables')
.reply(500, {
messageKey: 'UNKNOWN',
@@ -64,13 +64,13 @@ export class ProcessInstanceVariablesMock extends BaseMock {
}
addGetProcessInstanceVariable200Response(processInstanceId: string, variableName: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
.reply(200, fakeVariable1);
}
addGetProcessInstanceVariable500Response(processInstanceId: string, variableName: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
.reply(500, {
messageKey: 'UNKNOWN',
@@ -79,13 +79,13 @@ export class ProcessInstanceVariablesMock extends BaseMock {
}
addUpdateProcessInstanceVariable200Response(processInstanceId: string, variableName: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
.reply(200, fakeVariable1);
}
addUpdateProcessInstanceVariable500Response(processInstanceId: string, variableName: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.put('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
.reply(500, {
messageKey: 'UNKNOWN',
@@ -94,13 +94,13 @@ export class ProcessInstanceVariablesMock extends BaseMock {
}
addDeleteProcessInstanceVariable200Response(processInstanceId: string, variableName: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.delete('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
.reply(200);
}
addDeleteProcessInstanceVariable500Response(processInstanceId: string, variableName: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.delete('/activiti-app/api/enterprise/process-instances/' + processInstanceId + '/variables/' + variableName)
.reply(500, {
messageKey: 'UNKNOWN',

View File

@@ -15,12 +15,11 @@
* limitations under the License.
*/
import nock from 'nock';
import { BaseMock } from '../base.mock';
export class ProcessMock extends BaseMock {
get200Response(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.post('/activiti-app/api/enterprise/process-instances/query')
.reply(200, {
size: 2,
@@ -82,7 +81,7 @@ export class ProcessMock extends BaseMock {
}
get200getProcessDefinitionStartForm(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/process-definitions/testProcess%3A1%3A7504/start-form')
.reply(200, {
id: 2002,

View File

@@ -20,7 +20,7 @@ import { BaseMock } from '../base.mock';
export class ProfileMock extends BaseMock {
get200getProfile(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/profile')
.reply(200, {
id: 1,
@@ -94,10 +94,10 @@ export class ProfileMock extends BaseMock {
}
get401getProfile(): void {
nock(this.host, { encodedQueryParams: true }).get('/activiti-app/api/enterprise/profile').reply(401);
this.createNockWithCors().get('/activiti-app/api/enterprise/profile').reply(401);
}
get200getProfilePicture(): void {
nock(this.host, { encodedQueryParams: true }).get('/activiti-app/api/enterprise/profile-picture').reply(200, 'BUFFERSIZE');
this.createNockWithCors().get('/activiti-app/api/enterprise/profile-picture').reply(200, 'BUFFERSIZE');
}
}

View File

@@ -15,7 +15,6 @@
* limitations under the License.
*/
import nock from 'nock';
import { BaseMock } from '../base.mock';
const fakeReportList = [
@@ -154,58 +153,56 @@ const fakeProcessDefinitionsNoApp: any[] = [
export class ReportsMock extends BaseMock {
get200ResponseCreateDefaultReport(): void {
nock(this.host, { encodedQueryParams: true }).post('/activiti-app/app/rest/reporting/default-reports').reply(200);
this.createNockWithCors().post('/activiti-app/app/rest/reporting/default-reports').reply(200);
}
get200ResponseTasksByProcessDefinitionId(reportId: string, processDefinitionId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/app/rest/reporting/report-params/' + reportId + '/tasks')
.query({ processDefinitionId })
.reply(200, ['Fake Task 1', 'Fake Task 2', 'Fake Task 3']);
}
get200ResponseReportList(): void {
nock(this.host, { encodedQueryParams: true }).get('/activiti-app/app/rest/reporting/reports').reply(200, fakeReportList);
this.createNockWithCors().get('/activiti-app/app/rest/reporting/reports').reply(200, fakeReportList);
}
get200ResponseReportParams(reportId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/app/rest/reporting/report-params/' + reportId)
.reply(200, fakeReportParams);
}
get200ResponseReportsByParams(reportId: string, paramsQuery: { status: string }): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.post('/activiti-app/app/rest/reporting/report-params/' + reportId, paramsQuery)
.reply(200, fakeChartReports);
}
get200ResponseProcessDefinitions(): void {
nock(this.host, { encodedQueryParams: true })
.get('/activiti-app/app/rest/reporting/process-definitions')
.reply(200, fakeProcessDefinitionsNoApp);
this.createNockWithCors().get('/activiti-app/app/rest/reporting/process-definitions').reply(200, fakeProcessDefinitionsNoApp);
}
get200ResponseUpdateReport(reportId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.put('/activiti-app/app/rest/reporting/reports/' + reportId)
.reply(200);
}
get200ResponseExportReport(reportId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.post('/activiti-app/app/rest/reporting/reports/' + reportId + '/export-to-csv')
.reply(200, 'CSV');
}
get200ResponseSaveReport(reportId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.post('/activiti-app/app/rest/reporting/reports/' + reportId)
.reply(200);
}
get200ResponseDeleteReport(reportId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.delete('/activiti-app/app/rest/reporting/reports/' + reportId)
.reply(200);
}

View File

@@ -15,12 +15,11 @@
* limitations under the License.
*/
import nock from 'nock';
import { BaseMock } from '../base.mock';
export class TaskFormMock extends BaseMock {
get200getTaskFormVariables(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/task-forms/5028/variables')
.reply(
200,

View File

@@ -15,7 +15,6 @@
* limitations under the License.
*/
import nock from 'nock';
import { BaseMock } from '../base.mock';
const formValues = [
@@ -42,7 +41,7 @@ const formValues = [
export class TasksMock extends BaseMock {
get200Response(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.post('/activiti-app/api/enterprise/tasks/query', {})
.reply(200, {
size: 2,
@@ -128,7 +127,7 @@ export class TasksMock extends BaseMock {
}
get200ResponseGetTask(taskId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/tasks/' + taskId)
.reply(200, {
id: '10',
@@ -166,14 +165,14 @@ export class TasksMock extends BaseMock {
}
get400TaskFilter(): void {
nock(this.host, { encodedQueryParams: true }).post('/activiti-app/api/enterprise/tasks/filter', {}).reply(400, {
this.createNockWithCors().post('/activiti-app/api/enterprise/tasks/filter', {}).reply(400, {
message: 'A valid filterId or filter params must be provided',
messageKey: 'GENERAL.ERROR.BAD-REQUEST'
});
}
get200TaskFilter(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.post('/activiti-app/api/enterprise/tasks/filter', { appDefinitionId: 1 })
.reply(200, {
size: 2,
@@ -249,7 +248,7 @@ export class TasksMock extends BaseMock {
}
get404CompleteTask(taskId: string): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.put('/activiti-app/api/enterprise/tasks/' + taskId + '/action/complete')
.reply(404, {
message: 'Task with id: ' + taskId + ' does not exist',
@@ -258,7 +257,7 @@ export class TasksMock extends BaseMock {
}
get200CreateTask(name: string): void {
nock(this.host, { encodedQueryParams: true }).post('/activiti-app/api/enterprise/tasks', { name }).reply(200, {
this.createNockWithCors().post('/activiti-app/api/enterprise/tasks', { name }).reply(200, {
id: '10001',
name: 'test-name',
description: null,
@@ -293,7 +292,7 @@ export class TasksMock extends BaseMock {
}
get200getTaskForm(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/task-forms/2518')
.reply(200, {
id: 1,
@@ -1033,14 +1032,10 @@ export class TasksMock extends BaseMock {
}
get200getRestFieldValuesColumn(): void {
nock(this.host, { encodedQueryParams: true })
.get('/activiti-app/api/enterprise/task-forms/1/form-values/label/user')
.reply(200, formValues);
this.createNockWithCors().get('/activiti-app/api/enterprise/task-forms/1/form-values/label/user').reply(200, formValues);
}
get200getRestFieldValues(): void {
nock(this.host, { encodedQueryParams: true })
.get('/activiti-app/api/enterprise/task-forms/2/form-values/label')
.reply(200, formValues);
this.createNockWithCors().get('/activiti-app/api/enterprise/task-forms/2/form-values/label').reply(200, formValues);
}
}

View File

@@ -15,12 +15,11 @@
* limitations under the License.
*/
import nock from 'nock';
import { BaseMock } from '../base.mock';
export class UserFiltersMock extends BaseMock {
get200getUserTaskFilters(): void {
nock(this.host, { encodedQueryParams: true })
this.createNockWithCors()
.get('/activiti-app/api/enterprise/filters/tasks')
.query({ appId: '1' })
.reply(200, {