Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/DEVSU-2524-reorder-graphkb-evidenc…
Browse files Browse the repository at this point in the history
…e-levels
  • Loading branch information
bnguyen-bcgsc authored Dec 3, 2024
2 parents 6075fd9 + 6941ebb commit 5c4926c
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/models/reports/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ module.exports = (sequelize, Sq) => {
field: 'hrdetect_score',
type: Sq.FLOAT,
},
intersectTmbScore: {
name: 'intersectTmbScore',
field: 'intersect_tmb_score',
genomeTmb: {
name: 'genomeTmb',
field: 'genome_tmb',
type: Sq.FLOAT,
},
alternateIdentifier: {
Expand Down
29 changes: 28 additions & 1 deletion app/routes/report/gene.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ const router = express.Router({mergeParams: true});

const schemaGenerator = require('../../schemas/schemaGenerator');
const validateAgainstSchema = require('../../libs/validateAgainstSchema');
const {REPORT_UPDATE_BASE_URI} = require('../../constants');
const {REPORT_CREATE_BASE_URI, REPORT_UPDATE_BASE_URI} = require('../../constants');

// Generate schemas
const createSchema = schemaGenerator(db.models.genes, {
baseUri: REPORT_CREATE_BASE_URI,
});
const updateSchema = schemaGenerator(db.models.genes, {
baseUri: REPORT_UPDATE_BASE_URI, nothingRequired: true,
});
Expand Down Expand Up @@ -138,6 +141,30 @@ router.route('/')
error: {message: 'Unable to retrieve genes'},
});
}
})
.post(async (req, res) => {
// Validate request against schema
try {
validateAgainstSchema(createSchema, req.body);
} catch (error) {
const message = `Error while validating gene create request ${error}`;
logger.error(message);
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message}});
}

// Create new entry in db
try {
const result = await db.models.genes.create({
...req.body,
reportId: req.report.id,
});
return res.status(HTTP_STATUS.CREATED).json(result.view('public'));
} catch (error) {
logger.error(`Unable to create gene ${error}`);
return res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({
error: {message: 'Unable to create gene'},
});
}
});

module.exports = router;
2 changes: 1 addition & 1 deletion app/routes/report/tmburMutationBurden.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ router.route('/')
.post(async (req, res) => {
// Validate request against schema
try {
await validateAgainstSchema(createSchema, req.body);
validateAgainstSchema(createSchema, req.body);
} catch (error) {
const message = `Error while validating tmbur mutation burden create request ${error}`;
logger.error(message);
Expand Down
15 changes: 15 additions & 0 deletions migrations/20241129212739-DEVSU-2513-rename-tbm-score.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const TABLE = 'reports';

module.exports = {
up: (queryInterface) => {
return queryInterface.sequelize.transaction(async (transaction) => {
return Promise.all([
queryInterface.renameColumn(TABLE, 'intersect_tmb_score', 'genome_tmb', {transaction}),
]);
});
},

down: () => {
throw new Error('Not Implemented!');
},
};
46 changes: 45 additions & 1 deletion test/routes/report/gene.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('/reports/{report}/genes', () => {
afterEach(async () => {
return db.models.genes.destroy({
where: {ident: getGene.ident},
force: true,
// force: true,
});
});

Expand Down Expand Up @@ -162,6 +162,50 @@ describe('/reports/{report}/genes', () => {
});
});

describe('POST', () => {
test('/ - 201 Created', async () => {
const res = await request
.post(`/api/reports/${report.ident}/genes`)
.send(GENE_DATA)
.auth(username, password)
.type('json')
.expect(HTTP_STATUS.CREATED);

checkGene(res.body);
expect(res.body).toEqual(expect.objectContaining(GENE_DATA));

// Check that record was created in the db
const result = await db.models.genes.findOne({
where: {ident: res.body.ident},
});
expect(result).not.toBeNull();

// Delete entry
await result.destroy({force: true});
});

test('/ - 400 Bad Request - Additional Property', async () => {
await request
.post(`/api/reports/${report.ident}/genes`)
.send({
...GENE_UPDATE_DATA,
additionalProperty: 'ADDITIONAL_PROPERTY',
})
.auth(username, password)
.type('json')
.expect(HTTP_STATUS.BAD_REQUEST);
});

test('/ - 400 Bad Request - Gene name is required', async () => {
await request
.post(`/api/reports/${report.ident}/genes`)
.send({})
.auth(username, password)
.type('json')
.expect(HTTP_STATUS.BAD_REQUEST);
});
});

describe('PUT', () => {
let putGene;

Expand Down
2 changes: 1 addition & 1 deletion test/routes/report/report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const checkReport = (report) => {
'biopsyDate', 'biopsyName', 'presentationDate', 'kbDiseaseMatch',
'kbUrl', 'pediatricIds', 'captiv8Score', 'appendix', 'hrdetectScore',
'legacyReportFilepath', 'legacyPresentationFilepath', 'signatures',
'intersectTmbScore',
'genomeTmb',
].forEach((element) => {
expect(report).toHaveProperty(element);
});
Expand Down
2 changes: 1 addition & 1 deletion test/routes/report/reportAsync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const checkReport = (report) => {
'state', 'expression_matrix', 'alternateIdentifier', 'ageOfConsent',
'biopsyDate', 'biopsyName', 'presentationDate', 'kbDiseaseMatch',
'kbUrl', 'pediatricIds', 'captiv8Score', 'hrdetectScore', 'appendix',
'intersectTmbScore',
'genomeTmb',
].forEach((element) => {
expect(report).toHaveProperty(element);
});
Expand Down
2 changes: 1 addition & 1 deletion test/testData/mockReportData.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"template": "genomic",
"captiv8Score": 20,
"hrdetectScore": 10.5,
"intersectTmbScore": 9.75,
"genomeTmb": 9.75,
"appendix": "this is an example of an appendix",
"sampleInfo": [
{
Expand Down

0 comments on commit 5c4926c

Please sign in to comment.