refactor: Async functions don't need to explicitly return promises (no-changelog) (#6041)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-04-24 11:17:08 +00:00
committed by GitHub
parent 03be725cef
commit 308a94311f
31 changed files with 148 additions and 209 deletions

View File

@@ -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')