Skip to content

Commit

Permalink
Standardize URL queries: use same URL components for querying by 'not…
Browse files Browse the repository at this point in the history
… accomplished step' and writing back 'accomplished step'
  • Loading branch information
callunity committed Oct 20, 2023
1 parent bc3137a commit 12db61c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 68 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project attempts to adhere to Semantic Versioning.

* Ability to request Vidarr metadata for a case

### Changed

* Standardized URLs: used same URL components for querying by "not completed a step" as "write back to indicate step is complete"

### Fixed

* Can now query by optional "not" steps in `/cases` endpoint
Expand Down
9 changes: 5 additions & 4 deletions components/case/caseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
ConflictingDataError,
} = require('../../utils/controllerUtils');
const logger = require('../../utils/logger').logger;
const urls = require('../../utils/urlSlugs');

function arraysEquals (array1, array2) {
return (
Expand Down Expand Up @@ -41,16 +42,16 @@ const allCaseArchives = async (req, res, next) => {
const query = req.query.not;
let cases;
if (query) {
if (query == 'copied-to-staging') {
if (query == urls.filesCopiedToOffsiteStagingDir) {
cases = await caseDao.getByFilesNotCopiedToOffsiteStagingDir();
res.status(200).send(cases);
} else if (query == 'sent-offsite') {
} else if (query == urls.filesSentOffsite) {
cases = await caseDao.getByFilesNotSentOffsite();
res.status(200).send(cases);
} else if (query == 'sent-to-vidarr-archival') {
} else if (query == urls.filesLoadedIntoVidarrArchival) {
cases = await caseDao.getByFilesNotLoadedIntoVidarrArchival();
res.status(200).send(cases);
} else if (query == 'unloaded') {
} else if (query == urls.caseFilesUnloaded) {
cases = await caseDao.getByFilesNotUnloaded();
res.status(200).send(cases);
}
Expand Down
10 changes: 5 additions & 5 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"schema": {
"type": "string"
},
"description": "Optional parameter to filter by outstanding case archiving work. Permitted values are: 'copied-to-staging', 'sent-offsite', 'sent-to-vidarr-archival', 'unloaded'"
"description": "Optional parameter to filter by outstanding case archiving work. Permitted values are: 'copied-to-offsite-staging', 'sent-offsite', 'sent-to-vidarr-archival', 'unloaded'"
}],
"responses": {
"200": {
Expand Down Expand Up @@ -335,7 +335,7 @@
}
}
},
"/case/{caseIdentifier}/files-copied-to-offsite-staging-dir": {
"/case/{caseIdentifier}/copied-to-offsite-staging": {
"put": {
"summary": "Case archive files moved to offsite staging directory",
"description": "Indicate that this case archive's files have been moved to the offfsite staging directory",
Expand Down Expand Up @@ -379,7 +379,7 @@
}
}
},
"/case/{caseIdentifier}/files-sent-offsite": {
"/case/{caseIdentifier}/sent-offsite": {
"put": {
"summary": "Case archive files were sent offsite",
"description": "Indicate that this case archive's files have been archived offsite",
Expand Down Expand Up @@ -427,7 +427,7 @@
}
}
},
"/case/{caseIdentifier}/files-loaded-into-vidarr-archival": {
"/case/{caseIdentifier}/sent-to-vidarr-archival": {
"put": {
"summary": "Case archive files loaded into vidarr-archival",
"description": "Indicate that this case archive's files have been loaded into vidarr-archival",
Expand Down Expand Up @@ -470,7 +470,7 @@
}
}
},
"/case/{caseIdentifier}/case-files-unloaded": {
"/case/{caseIdentifier}/unloaded": {
"put": {
"summary": "Case archive files deleted from production vidarr",
"description": "Record that this case archive's files have been deleted from production vidarr",
Expand Down
121 changes: 66 additions & 55 deletions test/archiveTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ describe('case archive tracking', () => {
});
it('it should return data for cases that have not been copied to the archiving staging directory', (done) => {
let caseIdentifier = 'R12_TEST_1212_Ab_C';
getCasesByMissing(server, 'copied-to-staging').end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.length).to.equal(1);
expect(res.body[0].caseIdentifier).to.equal(caseIdentifier);
done();
});
getCasesByMissing(server, urls.filesCopiedToOffsiteStagingDir).end(
(err, res) => {
expect(res.status).to.equal(200);
expect(res.body.length).to.equal(1);
expect(res.body[0].caseIdentifier).to.equal(caseIdentifier);
done();
}
);
});
it('it should create a case + archive entry', (done) => {
let reqBody = {
Expand Down Expand Up @@ -190,33 +192,39 @@ describe('case archive tracking', () => {
expect(res.status).to.equal(200);
expect(res.body.filesCopiedToOffsiteArchiveStagingDir).to.be.a('null');

getCasesByMissing(server, 'copied-to-staging').end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);

updateCaseArchives(
server,
caseIdentifier,
urls.filesCopiedToOffsiteStagingDir,
unloadFile
).end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.filesCopiedToOffsiteArchiveStagingDir).not.to.be.a(
'null'
);
expect(isValidDate(res.body.filesCopiedToOffsiteArchiveStagingDir))
.to.be.true;
expect(res.body.filesLoadedIntoVidarrArchival).to.be.a('null');
getCasesByMissing(server, urls.filesCopiedToOffsiteStagingDir).end(
(err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);

getCasesByMissing(server, 'copied-to-staging').end((err, res) => {
updateCaseArchives(
server,
caseIdentifier,
urls.filesCopiedToOffsiteStagingDir,
unloadFile
).end((err, res) => {
expect(res.status).to.equal(200);
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier)
.length
).to.equal(0);
res.body.filesCopiedToOffsiteArchiveStagingDir
).not.to.be.a('null');
expect(
isValidDate(res.body.filesCopiedToOffsiteArchiveStagingDir)
).to.be.true;
expect(res.body.filesLoadedIntoVidarrArchival).to.be.a('null');

getCasesByMissing(
server,
urls.filesCopiedToOffsiteStagingDir
).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier)
.length
).to.equal(0);
});
});
});
});
}
);
done();
});
});
Expand Down Expand Up @@ -290,7 +298,7 @@ describe('case archive tracking', () => {
commvaultBackupJobId: 'CJ1212',
};

getCasesByMissing(server, 'sent-offsite').end((err, res) => {
getCasesByMissing(server, urls.filesSentOffsite).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);
Expand All @@ -307,7 +315,7 @@ describe('case archive tracking', () => {
reqBody.commvaultBackupJobId
);

getCasesByMissing(server, 'sent-offsite').end((err, res) => {
getCasesByMissing(server, urls.filesSentOffsite).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(0);
Expand Down Expand Up @@ -352,30 +360,33 @@ describe('case archive tracking', () => {
{ name: 'crosscheckFingerprintsCollector_bam', values: 'lots' },
],
};
getCasesByMissing(server, 'sent-to-vidarr-archival').end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);
getCasesByMissing(server, urls.filesLoadedIntoVidarrArchival).end(
(err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);

updateCaseArchives(
server,
caseIdentifier,
urls.filesLoadedIntoVidarrArchival,
loadFile
).end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.filesLoadedIntoVidarrArchival).not.to.be.a('null');
expect(isValidDate(res.body.filesLoadedIntoVidarrArchival)).to.be
.true;
updateCaseArchives(
server,
caseIdentifier,
urls.filesLoadedIntoVidarrArchival,
loadFile
).end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.filesLoadedIntoVidarrArchival).not.to.be.a('null');
expect(isValidDate(res.body.filesLoadedIntoVidarrArchival)).to.be
.true;

getCasesByMissing(server, 'sent-offsite').end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(0);
getCasesByMissing(server, urls.filesSentOffsite).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier)
.length
).to.equal(0);
});
});
});
done();
});
done();
}
);
});
it('it should update the "files have been sent to vidarr-archival" time', (done) => {
let caseIdentifier = 'R11_TEST_1000_Xy_Z';
Expand Down Expand Up @@ -430,7 +441,7 @@ describe('case archive tracking', () => {
it('it should update a case to indicate that the case files have been unloaded from production vidarr', (done) => {
let caseIdentifier = 'R12_TEST_1212_Ab_C';

getCasesByMissing(server, 'unloaded').end((err, res) => {
getCasesByMissing(server, urls.caseFilesUnloaded).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);
Expand All @@ -441,7 +452,7 @@ describe('case archive tracking', () => {
expect(res.body.caseFilesUnloaded).not.to.be.a('null');
expect(isValidDate(res.body.caseFilesUnloaded)).to.be.true;

getCasesByMissing(server, 'sent-offsite').end((err, res) => {
getCasesByMissing(server, urls.filesSentOffsite).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier)
.length
Expand Down
8 changes: 4 additions & 4 deletions utils/urlSlugs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

module.exports = {
caseFilesUnloaded: 'case-files-unloaded',
filesCopiedToOffsiteStagingDir: 'files-copied-to-offsite-staging-dir',
filesLoadedIntoVidarrArchival: 'files-loaded-into-vidarr-archival',
filesSentOffsite: 'files-sent-offsite',
caseFilesUnloaded: 'unloaded',
filesCopiedToOffsiteStagingDir: 'copied-to-offsite-staging',
filesLoadedIntoVidarrArchival: 'sent-to-vidarr-archival',
filesSentOffsite: 'sent-offsite',
};

0 comments on commit 12db61c

Please sign in to comment.