Skip to content

Commit

Permalink
HARMONY-398: More user filter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnyinverso committed Oct 11, 2023
1 parent 2b1cc67 commit 40706f7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/frontends/workflow-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ export async function getJobTableRows(
req.user, req.context.logger,
);
const requestQuery = keysToLowerCase(req.query);
const { tableQuery } = parseQuery(requestQuery, JobStatus, isAdmin);
const { tableQuery } = parseQuery(requestQuery, JobStatus, req.context.isAdminAccess);
const jobQuery = tableQueryToJobQuery(tableQuery, isAdmin, req.user, jobIDs);
const jobs = (await Job.queryAll(db, jobQuery, false, 0, jobIDs.length)).data;
const resJson = {};
Expand Down
18 changes: 18 additions & 0 deletions test/helpers/workflow-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ export function workflowUIJobRows(
return request(app).post('/workflow-ui/jobs').query(actualQuery).send({ jobIDs });
}

/**
* Makes a request to the admin workflow UI job rows endpoint
*
* @param app - The express application (typically this.frontend)
* @param options - Mapping object. Includes query param object (which maps query
* param names to values), jobIDs (array of jobID), and username.
* e.g. \{ jobIDs, username: 'billy', query: \{...\}\}
*/
export function adminWorkflowUIJobRows(
app: Express.Application,
options: { username: string; query: object, jobIDs: string[] },
): Test {
const { jobIDs, query } = options;
const actualQuery = query || {};
return request(app).post('/admin/workflow-ui/jobs').query(actualQuery).send({ jobIDs });
}

/**
* Makes a request to view the workflow UI work items row endpoint
*
Expand Down Expand Up @@ -199,6 +216,7 @@ export const hookWorkflowUIWorkItems = hookRequest.bind(this, workflowUIWorkItem
export const hookAdminWorkflowUIWorkItems = hookRequest.bind(this, adminWorkflowUIWorkItems);
export const hookWorkflowUIWorkItemsRow = hookRequest.bind(this, workflowUIWorkItemsRow);
export const hookWorkflowUIJobRows = hookRequest.bind(this, workflowUIJobRows);
export const hookAdminWorkflowUIJobRows = hookRequest.bind(this, adminWorkflowUIJobRows);
export const hookWorkflowUIWorkItemRetry = hookRequest.bind(this, workflowUIWorkItemRetry);
export const hookWorkflowUILinks = hookRequest.bind(this, workflowUILinks);
export const hookAdminWorkflowUILinks = hookRequest.bind(this, adminWorkflowUILinks);
Expand Down
23 changes: 17 additions & 6 deletions test/workflow-ui/job-table-rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { JobStatus } from '../../app/models/job';
import hookServersStartStop from '../helpers/servers';
import { hookTransaction } from '../helpers/db';
import { buildJob } from '../helpers/jobs';
import { hookWorkflowUIJobRows } from '../helpers/workflow-ui';
import { hookAdminWorkflowUIJobRows, hookWorkflowUIJobRows } from '../helpers/workflow-ui';
import * as sinon from 'sinon';
import * as services from '../../app/models/services';

Expand All @@ -13,6 +13,7 @@ import * as services from '../../app/models/services';
const boJob1 = buildJob({ status: JobStatus.FAILED, username: 'bo' });
const boJob2 = buildJob({ status: JobStatus.SUCCESSFUL, username: 'bo', service_name: 'cog-maker' });
const adamJob1 = buildJob({ status: JobStatus.RUNNING, username: 'adam' });
const woodyJob1 = buildJob({ status: JobStatus.RUNNING, username: 'woody' });

describe('Workflow UI job table rows route', function () {
hookServersStartStop({ skipEarthdataLogin: false });
Expand All @@ -24,6 +25,7 @@ describe('Workflow UI job table rows route', function () {
await boJob1.save(this.trx);
await boJob2.save(this.trx);
await adamJob1.save(this.trx);
await woodyJob1.save(this.trx);
this.trx.commit();
});
after(function () {
Expand Down Expand Up @@ -62,13 +64,22 @@ describe('Workflow UI job table rows route', function () {
});
});

describe('who uses a user filter', function () {
hookWorkflowUIJobRows({ username: 'adam', jobIDs: [boJob1.jobID, boJob2.jobID],
query: { disallowUser: true, tableFilter: '[{"value":"user: bo","dbValue":"bo","field":"user"}]' } });
describe('who uses a user filter with the non-admin route', function () {
hookWorkflowUIJobRows({ username: 'adam', jobIDs: [woodyJob1.jobID],
query: { disallowUser: true, tableFilter: '[{"value":"user: woody","dbValue":"woody","field":"user"}]' } });
it('ignores the user filter', function () {
const response = JSON.parse(this.res.text);
expect(response[woodyJob1.jobID]).contains(`<tr id="job-${woodyJob1.jobID}" class='job-table-row'>`);
expect(Object.keys(response).length).to.eq(1);
});
});

describe('who uses a user filter with the admin route', function () {
hookAdminWorkflowUIJobRows({ username: 'adam', jobIDs: [woodyJob1.jobID],
query: { disallowUser: 'on', tableFilter: '[{"value":"user: woody","dbValue":"woody","field":"user"}]' } });
it('returns only the job row matching the user filter', function () {
const response = JSON.parse(this.res.text);
expect(response[boJob1.jobID]).to.eq(undefined);
expect(response[boJob2.jobID]).contains(undefined);
expect(response[woodyJob1.jobID]).eq(undefined);
expect(Object.keys(response).length).to.eq(0);
});
});
Expand Down

0 comments on commit 40706f7

Please sign in to comment.