Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nithriel committed Nov 20, 2023
1 parent c9730a2 commit 224fb3e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
10 changes: 9 additions & 1 deletion app/middleware/__mocks__/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ module.exports = async (req, res, next) => {

// Override authorization in order to mock permissions
if (req.query.groups) {
req.user.groups = [req.query.groups];
if (typeof req.query.groups.name === 'object') {
req.user.groups = [];

for (const i of req.query.groups.name) {
req.user.groups.push({name: i});
}
} else {
req.user.groups = [req.query.groups];
}
}

if (req.query.projects) {
Expand Down
17 changes: 8 additions & 9 deletions test/routes/report/report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ const checkReports = (reports) => {
});
};

const checkState = (reports, state) => {
const checkState = (reports, stateCheck) => {
return reports.some((report) => {
return report.state === state;
return report.state === stateCheck;
});
};

Expand Down Expand Up @@ -184,15 +184,15 @@ describe('/reports/{REPORTID}', () => {
const res = await request
.get('/api/reports')
.query({
groups: [{name: NON_PROD_ACCESS}],
groups: [{name: NON_PROD_ACCESS}, {name: UNREVIEWED_ACCESS}],
projects: [{name: project.name}],
})
.auth(username, password)
.type('json')
.expect(HTTP_STATUS.OK);

checkReports(res.body.reports);
expect(checkState(res.body.reports, 'non-production')).toBeTruthy();
expect(checkState(res.body.reports, 'nonproduction')).toBeTruthy();
}, LONGER_TIMEOUT);

test('/ - 200 NOT GET non-production reports with non-authorized group', async () => {
Expand All @@ -207,14 +207,14 @@ describe('/reports/{REPORTID}', () => {
.expect(HTTP_STATUS.OK);

checkReports(res.body.reports);
expect(checkState(res.body.reports, 'non-production')).not.toBeTruthy();
expect(checkState(res.body.reports, 'nonproduction')).not.toBeTruthy();
}, LONGER_TIMEOUT);

test('/ - 200 GET report if have additional report permission', async () => {
const res = await request
.get('/api/reports')
.query({
groups: [{name: NON_PROD_ACCESS}],
groups: [{name: NON_PROD_ACCESS}, {name: UNREVIEWED_ACCESS}],
projects: [{name: project2.name}],
})
.auth(username, password)
Expand Down Expand Up @@ -417,7 +417,7 @@ describe('/reports/{REPORTID}', () => {
const res = await request
.get(`/api/reports/${reportDualProj.ident}`)
.query({
groups: [{name: NON_PROD_ACCESS}],
groups: [{name: NON_PROD_ACCESS}, {name: UNREVIEWED_ACCESS}],
projects: [{name: project2.name, ident: project2.ident}],
})
.auth(username, password)
Expand All @@ -431,7 +431,7 @@ describe('/reports/{REPORTID}', () => {
const res = await request
.get(`/api/reports/${reportNonProduction.ident}`)
.query({
groups: [{name: NON_PROD_ACCESS}],
groups: [{name: NON_PROD_ACCESS}, {name: UNREVIEWED_ACCESS}],
projects: [{name: project.name, ident: project.ident}],
})
.auth(username, password)
Expand Down Expand Up @@ -612,7 +612,6 @@ describe('/reports/{REPORTID}', () => {
await db.models.report.destroy({where: {id: reportReviewed.id}, force: true});
await db.models.report.destroy({where: {id: reportArchived.id}, force: true});
await db.models.report.destroy({where: {id: reportNonProduction.id}, force: true});
await db.models.report.destroy({where: {id: reportNonProduction.id}, force: true});
}, LONGER_TIMEOUT);
});

Expand Down

0 comments on commit 224fb3e

Please sign in to comment.