Skip to content

Commit

Permalink
HARMONY-1891: Get tests passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnyinverso committed Oct 7, 2024
1 parent 2bd5212 commit 9e12ec6
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion services/harmony/app/frontends/workflow-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function tableQueryToJobQuery(tableQuery: TableQuery, isAdmin: boolean, user: st
};
}
if (tableQuery.from || tableQuery.to) {
jobQuery.dates = { field: tableQuery.dateKind };
jobQuery.dates = { field: `jobs.${tableQuery.dateKind}` };
jobQuery.dates.from = tableQuery.from;
jobQuery.dates.to = tableQuery.to;
}
Expand Down
37 changes: 19 additions & 18 deletions services/harmony/app/models/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export interface JobQuery {
dates?: {
from?: Date;
to?: Date;
field: 'createdAt' | 'updatedAt';
field: 'jobs.createdAt' | 'jobs.updatedAt';
}
whereIn?: {
status?: { in: boolean, values: string[] };
Expand Down Expand Up @@ -330,6 +330,23 @@ async function getUniqueProviderIds(tx: Transaction): Promise<string[]> {
return results.map((job) => job.provider_id);
}

/**
* Sets the fields on the where clauses (see JobQuery) to be prefixed with a table name to avoid
* ambiguities when joining with other tables
* @param query - the where clauses to process
* @returns An object with its fields prefixed with the table name
*/
function setTableNameForWhereClauses(table: string, whereClauses: {}): {} {
const result = {};
Object.entries(whereClauses).forEach(([key, value]) => {
if (value !== undefined) {
result[`${table}.${key}`] = value;
}
});

return result;
}

/**
* Conditionally modify a job query if specific constraints are present.
* @param queryBuilder - the knex query builder object to modify
Expand All @@ -341,6 +358,7 @@ function modifyQuery(
constraints: JobQuery): void {
if (constraints === undefined) return;
if (constraints.whereIn) {
constraints.whereIn = setTableNameForWhereClauses('jobs', constraints.whereIn);
for (const jobField in constraints.whereIn) {
const constraint = constraints.whereIn[jobField];
if (constraint.in) {
Expand All @@ -360,23 +378,6 @@ function modifyQuery(
}
}

/**
* Sets the fields on the where clauses (see JobQuery) to be prefixed with a table name to avoid
* ambiguities when joining with other tables
* @param query - the where clauses to process
* @returns An object with its fields prefixed with the table name
*/
function setTableNameForWhereClauses(table: string, whereClauses: {}): {} {
const result = {};
Object.entries(whereClauses).forEach(([key, value]) => {
if (value !== undefined) {
result[`${table}.${key}`] = value;
}
});

return result;
}

/**
*
* Wrapper object for persisted jobs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<th scope="col">id</th>
<th scope="col">status</th>
{{#isAdminOrLogViewer}}
<th class="helpful-th" scope="col" title="Links to logs (including all retries) for each work item.">logs
</th>
<th class="helpful-th" scope="col" title="Links to logs (including all retries) for each work item.">logs</th>
{{/isAdminOrLogViewer}}
{{#canShowRetryColumn}}
<th scope="col">retry</th>
Expand Down
58 changes: 29 additions & 29 deletions services/harmony/test/workflow-ui/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ describe('Workflow UI jobs route', function () {
it('returns only failed jobs', function () {
const listing = this.res.text;
expect((listing.match(/job-table-row/g) || []).length).to.equal(1);
expect(listing).to.contain(`<span class="badge bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
});
it('does not have disallowStatus HTML checked', function () {
const listing = this.res.text;
Expand All @@ -400,9 +400,9 @@ describe('Workflow UI jobs route', function () {
it('returns failed and successful jobs', function () {
const listing = this.res.text;
expect((listing.match(/job-table-row/g) || []).length).to.equal(2);
expect(listing).to.contain(`<span class="badge bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
});
it('does not have disallowStatus HTML checked', function () {
const listing = this.res.text;
Expand Down Expand Up @@ -440,9 +440,9 @@ describe('Workflow UI jobs route', function () {
it('returns all jobs that are not failed or successful', function () {
const listing = this.res.text;
expect((listing.match(/job-table-row/g) || []).length).to.equal(1);
expect(listing).to.not.contain(`<span class="badge bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
});
it('does have disallowStatus HTML checked', function () {
const listing = this.res.text;
Expand Down Expand Up @@ -532,9 +532,9 @@ describe('Workflow UI jobs route', function () {
const netcdfToZarrRegExp = new RegExp(netcdfToZarrTd, 'g');
expect((listing.match(netcdfToZarrRegExp) || []).length).to.equal(1);

expect(listing).to.contain(`<span class="badge bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
});
it('has the appropriate HTML (un)checked', function () {
const listing = this.res.text;
Expand Down Expand Up @@ -603,13 +603,13 @@ describe('Workflow UI jobs route', function () {
it('returns jobs with the aforementioned statuses', function () {
const listing = this.res.text;
expect((listing.match(/job-table-row/g) || []).length).to.equal(4);
expect(listing).to.contain(`<span class="badge bg-warning">${JobStatus.RUNNING_WITH_ERRORS.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-success">${JobStatus.COMPLETE_WITH_ERRORS.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-warning">${JobStatus.PAUSED.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-info">${JobStatus.PREVIEWING.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-warning">${JobStatus.RUNNING_WITH_ERRORS.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-success">${JobStatus.COMPLETE_WITH_ERRORS.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-warning">${JobStatus.PAUSED.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-info">${JobStatus.PREVIEWING.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
});
it('does not have disallowStatus HTML checked', function () {
const listing = this.res.text;
Expand All @@ -635,13 +635,13 @@ describe('Workflow UI jobs route', function () {
it('returns jobs without the aforementioned statuses', function () {
const listing = this.res.text;
expect((listing.match(/job-table-row/g) || []).length).to.equal(4);
expect(listing).to.not.contain(`<span class="badge bg-warning">${JobStatus.RUNNING_WITH_ERRORS.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-success">${JobStatus.COMPLETE_WITH_ERRORS.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-warning">${JobStatus.PAUSED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-info">${JobStatus.PREVIEWING.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-warning">${JobStatus.RUNNING_WITH_ERRORS.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-success">${JobStatus.COMPLETE_WITH_ERRORS.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-warning">${JobStatus.PAUSED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-info">${JobStatus.PREVIEWING.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
});
it('does have disallowStatus HTML checked', function () {
const listing = this.res.text;
Expand Down Expand Up @@ -709,9 +709,9 @@ describe('Workflow UI jobs route', function () {
const netcdfToZarrRegExp = new RegExp(netcdfToZarrTd, 'g');
expect((listing.match(netcdfToZarrRegExp) || []).length).to.equal(1);

expect(listing).to.contain(`<span class="badge bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-danger">${JobStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-success">${JobStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-info">${JobStatus.RUNNING.valueOf()}</span>`);
});
it('has the appropriate HTML (un)checked', function () {
const listing = this.res.text;
Expand Down
10 changes: 5 additions & 5 deletions services/harmony/test/workflow-ui/work-items-table-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ describe('Workflow UI work items table row route', function () {
it('returns the running work item', function () {
const listing = this.res.text;
expect((listing.match(/work-item-table-row/g) || []).length).to.equal(1);
expect(listing).to.not.contain(`<span class="badge bg-danger">${WorkItemStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-secondary">${WorkItemStatus.CANCELED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-primary">${WorkItemStatus.READY.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-info">${WorkItemStatus.RUNNING.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-danger">${WorkItemStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-secondary">${WorkItemStatus.CANCELED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-primary">${WorkItemStatus.READY.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-info">${WorkItemStatus.RUNNING.valueOf()}</span>`);
});
});
});
Expand Down
30 changes: 15 additions & 15 deletions services/harmony/test/workflow-ui/work-items-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ describe('Workflow UI work items table route', function () {
});
it('returns a SUCCESSFUL work item', function () {
const listing = this.res.text;
expect(listing).to.contain(`<span class="badge bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
});
});

Expand All @@ -357,7 +357,7 @@ describe('Workflow UI work items table route', function () {
});
it('returns a QUEUED work item', function () {
const listing = this.res.text;
expect(listing).to.contain(`<span class="badge bg-warning">${WorkItemStatus.QUEUED.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-warning">${WorkItemStatus.QUEUED.valueOf()}</span>`);
});
});

Expand Down Expand Up @@ -402,7 +402,7 @@ describe('Workflow UI work items table route', function () {
});
it('returns a SUCCESSFUL work item', function () {
const listing = this.res.text;
expect(listing).to.contain(`<span class="badge bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
});
});

Expand All @@ -425,7 +425,7 @@ describe('Workflow UI work items table route', function () {
});
it('returns a SUCCESSFUL work item', function () {
const listing = this.res.text;
expect(listing).to.contain(`<span class="badge bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
});
});

Expand All @@ -442,11 +442,11 @@ describe('Workflow UI work items table route', function () {
it('returns only running work items', function () {
const listing = this.res.text;
expect((listing.match(/work-item-table-row/g) || []).length).to.equal(2);
expect(listing).to.not.contain(`<span class="badge bg-danger">${WorkItemStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-secondary">${WorkItemStatus.CANCELED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-primary">${WorkItemStatus.READY.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-info">${WorkItemStatus.RUNNING.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-danger">${WorkItemStatus.FAILED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-secondary">${WorkItemStatus.CANCELED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-primary">${WorkItemStatus.READY.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-info">${WorkItemStatus.RUNNING.valueOf()}</span>`);
});
});
});
Expand Down Expand Up @@ -542,12 +542,12 @@ describe('Workflow UI work items table route', function () {
it('returns only non-running work items', function () {
const listing = this.res.text;
expect((listing.match(/work-item-table-row/g) || []).length).to.equal(4);
expect(listing).to.not.contain(`<span class="badge bg-danger">${WorkItemStatus.FAILED.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge bg-warning">${WorkItemStatus.QUEUED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-secondary">${WorkItemStatus.CANCELED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-primary">${WorkItemStatus.READY.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge bg-info">${WorkItemStatus.RUNNING.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-danger">${WorkItemStatus.FAILED.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-success">${WorkItemStatus.SUCCESSFUL.valueOf()}</span>`);
expect(listing).to.contain(`<span class="badge rounded-pill bg-warning">${WorkItemStatus.QUEUED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-secondary">${WorkItemStatus.CANCELED.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-primary">${WorkItemStatus.READY.valueOf()}</span>`);
expect(listing).to.not.contain(`<span class="badge rounded-pill bg-info">${WorkItemStatus.RUNNING.valueOf()}</span>`);
});
});

Expand Down

0 comments on commit 9e12ec6

Please sign in to comment.