Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[O2B-719] Add range based filtering for run number #1810

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
33 changes: 25 additions & 8 deletions lib/usecases/run/GetAllRunsUseCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,33 @@

if (runNumbers) {
const runNumberList = runNumbers.split(SEARCH_ITEMS_SEPARATOR)
martinboulais marked this conversation as resolved.
Show resolved Hide resolved
.map((runNumber) => parseInt(runNumber, 10))
.filter((runNumber) => !Number.isNaN(runNumber));
.map((runNumber) => runNumber.trim())

Check warning on line 81 in lib/usecases/run/GetAllRunsUseCase.js

View check run for this annotation

Codecov / codecov/patch

lib/usecases/run/GetAllRunsUseCase.js#L81

Added line #L81 was not covered by tests
.filter(Boolean);

if (runNumberList.length) {
if (runNumberList.length > 1) {
// Multiple run numbers.
filteringQueryBuilder.where('runNumber').oneOf(...runNumberList);
const allRuns = new Set();

Check warning on line 84 in lib/usecases/run/GetAllRunsUseCase.js

View check run for this annotation

Codecov / codecov/patch

lib/usecases/run/GetAllRunsUseCase.js#L84

Added line #L84 was not covered by tests

runNumberList.forEach((runNumber) => {
if (runNumber.includes('-')) {
const [start, end] = runNumber.split('-').map((n) => parseInt(n, 10));
if (!Number.isNaN(start) && !Number.isNaN(end) && start <= end) {
martinboulais marked this conversation as resolved.
Show resolved Hide resolved
for (let i = start; i <= end; i++) {
allRuns.add(i);

Check warning on line 91 in lib/usecases/run/GetAllRunsUseCase.js

View check run for this annotation

Codecov / codecov/patch

lib/usecases/run/GetAllRunsUseCase.js#L86-L91

Added lines #L86 - L91 were not covered by tests
}
}
} else {
const parsedRunNumber = parseInt(runNumber, 10);
if (!Number.isNaN(parsedRunNumber)) {
allRuns.add(parsedRunNumber);

Check warning on line 97 in lib/usecases/run/GetAllRunsUseCase.js

View check run for this annotation

Codecov / codecov/patch

lib/usecases/run/GetAllRunsUseCase.js#L94-L97

Added lines #L94 - L97 were not covered by tests
}
}
});

const finalRunList = Array.from(allRuns);
if (finalRunList.length) {
if (finalRunList.length > 1) {
filteringQueryBuilder.where('runNumber').oneOf(...finalRunList);

Check warning on line 105 in lib/usecases/run/GetAllRunsUseCase.js

View check run for this annotation

Codecov / codecov/patch

lib/usecases/run/GetAllRunsUseCase.js#L102-L105

Added lines #L102 - L105 were not covered by tests
} else {
// One run number.
const [runNumber] = runNumberList;
const [runNumber] = finalRunList;

Check warning on line 107 in lib/usecases/run/GetAllRunsUseCase.js

View check run for this annotation

Codecov / codecov/patch

lib/usecases/run/GetAllRunsUseCase.js#L107

Added line #L107 was not covered by tests
filteringQueryBuilder.where('runNumber').substring(`${runNumber}`);
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/api/runs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ module.exports = () => {
expect(runs).to.lengthOf(2);
});

it('should successfully filter on run number range', async () => {
const response = await request(server).get('/api/runs?filter[runNumbers]=1-5,8,12,20-30');

expect(response.status).to.equal(200);
const { data: runs } = response.body;
expect(runs).to.lengthOf(18);
});

it('should return 400 if the calibration status filter is invalid', async () => {
{
const response = await request(server).get('/api/runs?filter[calibrationStatuses]=invalid');
Expand Down
Loading