refactor: Async functions don't need to explicitly return promises (no-changelog) (#6041)
This commit is contained in:
committed by
GitHub
parent
03be725cef
commit
308a94311f
@@ -205,9 +205,7 @@ test('GET /ldap/config route should retrieve current configuration', async () =>
|
||||
|
||||
describe('POST /ldap/test-connection', () => {
|
||||
test('route should success', async () => {
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'testConnection')
|
||||
.mockImplementation(async () => Promise.resolve());
|
||||
jest.spyOn(LdapService.prototype, 'testConnection').mockResolvedValue();
|
||||
|
||||
const response = await authAgent(owner).post('/ldap/test-connection');
|
||||
expect(response.statusCode).toBe(200);
|
||||
@@ -216,9 +214,7 @@ describe('POST /ldap/test-connection', () => {
|
||||
test('route should fail', async () => {
|
||||
const errorMessage = 'Invalid connection';
|
||||
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'testConnection')
|
||||
.mockImplementation(async () => Promise.reject(new Error(errorMessage)));
|
||||
jest.spyOn(LdapService.prototype, 'testConnection').mockRejectedValue(new Error(errorMessage));
|
||||
|
||||
const response = await authAgent(owner).post('/ldap/test-connection');
|
||||
expect(response.statusCode).toBe(400);
|
||||
@@ -240,9 +236,7 @@ describe('POST /ldap/sync', () => {
|
||||
|
||||
describe('dry mode', () => {
|
||||
const runTest = async (ldapUsers: LdapUser[]) => {
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'searchWithAdminBinding')
|
||||
.mockImplementation(async () => Promise.resolve(ldapUsers));
|
||||
jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue(ldapUsers);
|
||||
|
||||
const response = await authAgent(owner).post('/ldap/sync').send({ type: 'dry' });
|
||||
|
||||
@@ -337,9 +331,7 @@ describe('POST /ldap/sync', () => {
|
||||
|
||||
describe('live mode', () => {
|
||||
const runTest = async (ldapUsers: LdapUser[]) => {
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'searchWithAdminBinding')
|
||||
.mockImplementation(async () => Promise.resolve(ldapUsers));
|
||||
jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue(ldapUsers);
|
||||
|
||||
const response = await authAgent(owner).post('/ldap/sync').send({ type: 'live' });
|
||||
|
||||
@@ -467,9 +459,7 @@ describe('POST /ldap/sync', () => {
|
||||
test('should remove user instance access once the user is disabled during synchronization', async () => {
|
||||
const member = await testDb.createLdapUser({ globalRole: globalMemberRole }, uniqueId());
|
||||
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'searchWithAdminBinding')
|
||||
.mockImplementation(async () => Promise.resolve([]));
|
||||
jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue([]);
|
||||
|
||||
await authAgent(owner).post('/ldap/sync').send({ type: 'live' });
|
||||
|
||||
@@ -508,13 +498,9 @@ describe('POST /login', () => {
|
||||
|
||||
const authlessAgent = utils.createAgent(app);
|
||||
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'searchWithAdminBinding')
|
||||
.mockImplementation(async () => Promise.resolve([ldapUser]));
|
||||
jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue([ldapUser]);
|
||||
|
||||
jest
|
||||
.spyOn(LdapService.prototype, 'validUser')
|
||||
.mockImplementation(async () => Promise.resolve());
|
||||
jest.spyOn(LdapService.prototype, 'validUser').mockResolvedValue();
|
||||
|
||||
const response = await authlessAgent
|
||||
.post('/login')
|
||||
|
||||
@@ -799,11 +799,11 @@ export function installedNodePayload(packageName: string): InstalledNodePayload
|
||||
};
|
||||
}
|
||||
|
||||
export const emptyPackage = () => {
|
||||
export const emptyPackage = async () => {
|
||||
const installedPackage = new InstalledPackages();
|
||||
installedPackage.installedNodes = [];
|
||||
|
||||
return Promise.resolve(installedPackage);
|
||||
return installedPackage;
|
||||
};
|
||||
|
||||
// ----------------------------------
|
||||
|
||||
@@ -18,7 +18,7 @@ jest.mock('@/Db', () => {
|
||||
return {
|
||||
collections: {
|
||||
Execution: {
|
||||
save: jest.fn(async () => Promise.resolve({ id: FAKE_EXECUTION_ID })),
|
||||
save: jest.fn(async () => ({ id: FAKE_EXECUTION_ID })),
|
||||
update: jest.fn(),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -99,12 +99,11 @@ jest.mock('@/Db', () => {
|
||||
return {
|
||||
collections: {
|
||||
Workflow: {
|
||||
find: jest.fn(async () => Promise.resolve(generateWorkflows(databaseActiveWorkflowsCount))),
|
||||
find: jest.fn(async () => generateWorkflows(databaseActiveWorkflowsCount)),
|
||||
findOne: jest.fn(async (searchParams) => {
|
||||
const foundWorkflow = databaseActiveWorkflowsList.find(
|
||||
return databaseActiveWorkflowsList.find(
|
||||
(workflow) => workflow.id.toString() === searchParams.where.id.toString(),
|
||||
);
|
||||
return Promise.resolve(foundWorkflow);
|
||||
}),
|
||||
update: jest.fn(),
|
||||
createQueryBuilder: jest.fn(() => {
|
||||
@@ -112,7 +111,7 @@ jest.mock('@/Db', () => {
|
||||
update: () => fakeQueryBuilder,
|
||||
set: () => fakeQueryBuilder,
|
||||
where: () => fakeQueryBuilder,
|
||||
execute: () => Promise.resolve(),
|
||||
execute: async () => {},
|
||||
};
|
||||
return fakeQueryBuilder;
|
||||
}),
|
||||
@@ -246,7 +245,7 @@ describe('ActiveWorkflowRunner', () => {
|
||||
const workflow = generateWorkflows(1);
|
||||
const additionalData = await WorkflowExecuteAdditionalData.getBase('fake-user-id');
|
||||
|
||||
workflowRunnerRun.mockImplementationOnce(() => Promise.resolve('invalid-execution-id'));
|
||||
workflowRunnerRun.mockResolvedValueOnce('invalid-execution-id');
|
||||
|
||||
await activeWorkflowRunner.runWorkflow(
|
||||
workflow[0],
|
||||
|
||||
@@ -6,7 +6,7 @@ jest.mock('@/Db', () => {
|
||||
return {
|
||||
collections: {
|
||||
ExecutionMetadata: {
|
||||
save: jest.fn(async () => Promise.resolve([])),
|
||||
save: jest.fn(async () => []),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user