diff --git a/cypress/e2e/autoApproved.cy.js b/cypress/e2e/autoApproved.cy.js index 65d9d65a1..41a8cf4b9 100644 --- a/cypress/e2e/autoApproved.cy.js +++ b/cypress/e2e/autoApproved.cy.js @@ -63,11 +63,9 @@ describe('Auto-Approved Push Test', () => { .local() .format('dddd, MMMM Do YYYY, h:mm:ss a'); - cy.get('kbd') - .trigger('mouseover') - .then(() => { - cy.get('.MuiTooltip-tooltip').should('contain', expectedTooltipTimestamp); - }); + cy.get('kbd').trigger('mouseover'); + + cy.get('.MuiTooltip-tooltip').should('contain', expectedTooltipTimestamp); cy.contains('approved this contribution').should('not.exist'); }); diff --git a/cypress/e2e/repo.cy.js b/cypress/e2e/repo.cy.js index 682a41881..5eca98737 100644 --- a/cypress/e2e/repo.cy.js +++ b/cypress/e2e/repo.cy.js @@ -133,11 +133,11 @@ describe('Repo', () => { .next() .get('svg.octicon-copy') .should('exist') - .click() - .get('svg.octicon-copy') - .should('not.exist') - .get('svg.octicon-check') - .should('exist'); + .click(); + + cy.get('svg.octicon-copy').should('not.exist'); + + cy.get('svg.octicon-check').should('exist'); }); after(() => { diff --git a/src/db/file/repo.ts b/src/db/file/repo.ts index f660c7ca3..11c3d775f 100644 --- a/src/db/file/repo.ts +++ b/src/db/file/repo.ts @@ -106,20 +106,19 @@ export const createRepo = async (repo: Repo): Promise => { export const addUserCanPush = async (_id: string, user: string): Promise => { user = user.toLowerCase(); - return new Promise(async (resolve, reject) => { - const repo = await getRepoById(_id); - if (!repo) { - reject(new Error('Repo not found')); - return; - } - - if (repo.users?.canPush.includes(user)) { - resolve(); - return; - } - repo.users?.canPush.push(user); - - const options = { multi: false, upsert: false }; + const repo = await getRepoById(_id); + if (!repo) { + throw new Error('Repo not found'); + } + + if (repo.users?.canPush.includes(user)) { + return; + } + repo.users?.canPush.push(user); + + const options = { multi: false, upsert: false }; + + return new Promise((resolve, reject) => { db.update({ _id: _id }, repo, options, (err) => { // ignore for code coverage as neDB rarely returns errors even for an invalid query /* istanbul ignore if */ @@ -134,21 +133,20 @@ export const addUserCanPush = async (_id: string, user: string): Promise = export const addUserCanAuthorise = async (_id: string, user: string): Promise => { user = user.toLowerCase(); - return new Promise(async (resolve, reject) => { - const repo = await getRepoById(_id); - if (!repo) { - reject(new Error('Repo not found')); - return; - } + const repo = await getRepoById(_id); + if (!repo) { + throw new Error('Repo not found'); + } - if (repo.users.canAuthorise.includes(user)) { - resolve(); - return; - } + if (repo.users.canAuthorise.includes(user)) { + return; + } - repo.users.canAuthorise.push(user); + repo.users.canAuthorise.push(user); - const options = { multi: false, upsert: false }; + const options = { multi: false, upsert: false }; + + return new Promise((resolve, reject) => { db.update({ _id: _id }, repo, options, (err) => { // ignore for code coverage as neDB rarely returns errors even for an invalid query /* istanbul ignore if */ @@ -163,16 +161,16 @@ export const addUserCanAuthorise = async (_id: string, user: string): Promise => { user = user.toLowerCase(); - return new Promise(async (resolve, reject) => { - const repo = await getRepoById(_id); - if (!repo) { - reject(new Error('Repo not found')); - return; - } + const repo = await getRepoById(_id); + if (!repo) { + throw new Error('Repo not found'); + } - repo.users.canAuthorise = repo.users.canAuthorise.filter((x: string) => x != user); + repo.users.canAuthorise = repo.users.canAuthorise.filter((x: string) => x != user); - const options = { multi: false, upsert: false }; + const options = { multi: false, upsert: false }; + + return new Promise((resolve, reject) => { db.update({ _id: _id }, repo, options, (err) => { // ignore for code coverage as neDB rarely returns errors even for an invalid query /* istanbul ignore if */ @@ -187,16 +185,16 @@ export const removeUserCanAuthorise = async (_id: string, user: string): Promise export const removeUserCanPush = async (_id: string, user: string): Promise => { user = user.toLowerCase(); - return new Promise(async (resolve, reject) => { - const repo = await getRepoById(_id); - if (!repo) { - reject(new Error('Repo not found')); - return; - } + const repo = await getRepoById(_id); + if (!repo) { + throw new Error('Repo not found'); + } + + repo.users.canPush = repo.users.canPush.filter((x) => x != user); - repo.users.canPush = repo.users.canPush.filter((x) => x != user); + const options = { multi: false, upsert: false }; - const options = { multi: false, upsert: false }; + return new Promise((resolve, reject) => { db.update({ _id: _id }, repo, options, (err) => { // ignore for code coverage as neDB rarely returns errors even for an invalid query /* istanbul ignore if */ diff --git a/src/db/index.ts b/src/db/index.ts index 062094492..d743663b7 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -100,57 +100,44 @@ export const createRepo = async (repo: AuthorisedRepo) => { export const isUserPushAllowed = async (url: string, user: string) => { user = user.toLowerCase(); - return new Promise(async (resolve) => { - const repo = await getRepoByUrl(url); - if (!repo) { - resolve(false); - return; - } - - if (repo.users?.canPush.includes(user) || repo.users?.canAuthorise.includes(user)) { - resolve(true); - } else { - resolve(false); - } - }); + const repo = await getRepoByUrl(url); + if (!repo) { + return false; + } + + return repo.users?.canPush.includes(user) || repo.users?.canAuthorise.includes(user); }; export const canUserApproveRejectPush = async (id: string, user: string) => { - return new Promise(async (resolve) => { - const action = await getPush(id); - if (!action) { - resolve(false); - return; - } - - const theRepo = await sink.getRepoByUrl(action.url); - - if (theRepo?.users?.canAuthorise?.includes(user)) { - console.log(`user ${user} can approve/reject for repo ${action.url}`); - resolve(true); - } else { - console.log(`user ${user} cannot approve/reject for repo ${action.url}`); - resolve(false); - } - }); + const action = await getPush(id); + if (!action) { + return false; + } + + const theRepo = await sink.getRepoByUrl(action.url); + + if (theRepo?.users?.canAuthorise?.includes(user)) { + console.log(`user ${user} can approve/reject for repo ${action.url}`); + return true; + } else { + console.log(`user ${user} cannot approve/reject for repo ${action.url}`); + return false; + } }; export const canUserCancelPush = async (id: string, user: string) => { - return new Promise(async (resolve) => { - const action = await getPush(id); - if (!action) { - resolve(false); - return; - } - - const isAllowed = await isUserPushAllowed(action.url, user); - - if (isAllowed) { - resolve(true); - } else { - resolve(false); - } - }); + const action = await getPush(id); + if (!action) { + return false; + } + + const isAllowed = await isUserPushAllowed(action.url, user); + + if (isAllowed) { + return true; + } else { + return false; + } }; export const getSessionStore = (): MongoDBStore | null => diff --git a/src/proxy/routes/index.ts b/src/proxy/routes/index.ts index 1b103ba71..a7d39cc6b 100644 --- a/src/proxy/routes/index.ts +++ b/src/proxy/routes/index.ts @@ -8,9 +8,7 @@ import { ProxyOptions } from 'express-http-proxy'; enum ActionType { ALLOWED = 'Allowed', - ERROR = 'Error', - BLOCKED = 'Blocked', } diff --git a/test/chain.test.js b/test/chain.test.js index d3ac6ac81..0db86ac91 100644 --- a/test/chain.test.js +++ b/test/chain.test.js @@ -58,8 +58,6 @@ const mockPreProcessors = { parseAction: sinon.stub(), }; -let mockPushProcessors; - const clearCache = (sandbox) => { delete require.cache[require.resolve('../src/proxy/processors')]; delete require.cache[require.resolve('../src/proxy/chain')]; diff --git a/test/integration/forcePush.integration.test.js b/test/integration/forcePush.integration.test.js index e9af074d7..0ef35c8fb 100644 --- a/test/integration/forcePush.integration.test.js +++ b/test/integration/forcePush.integration.test.js @@ -15,7 +15,7 @@ describe('Force Push Integration Test', () => { let rebasedCommitSHA; before(async function () { - this.timeout(10000); // eslint-disable-line no-invalid-this + this.timeout(10000); tempDir = path.join(__dirname, '../temp-integration-repo'); await fs.mkdir(tempDir, { recursive: true }); @@ -58,7 +58,7 @@ describe('Force Push Integration Test', () => { describe('Complete force push pipeline', () => { it('should handle valid diff after rebase scenario', async function () { - this.timeout(5000); // eslint-disable-line no-invalid-this + this.timeout(5000); // Create action simulating force push with valid SHAs that have actual changes const action = new Action( @@ -101,7 +101,7 @@ describe('Force Push Integration Test', () => { }); it('should handle unreachable commit SHA error', async function () { - this.timeout(5000); // eslint-disable-line no-invalid-this + this.timeout(5000); // Invalid SHA to trigger error const action = new Action( diff --git a/test/testProxy.test.js b/test/testProxy.test.js index 99508b982..6927f25e1 100644 --- a/test/testProxy.test.js +++ b/test/testProxy.test.js @@ -264,7 +264,7 @@ describe('Proxy', () => { await proxy.start(); // simulate error in server close - mockHttpServer.close.callsFake((callback) => { + mockHttpServer.close.callsFake(() => { throw new Error('Server close error'); });