Skip to content

Commit

Permalink
Bucket ages in case upsert #2670
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Apr 25, 2022
1 parent e0ad9de commit 4055df0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
9 changes: 6 additions & 3 deletions data-serving/data-service/src/controllers/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,19 +721,22 @@ export class CasesController {
req.body.caseReference?.sourceEntryId &&
c
) {
c.set(req.body);
const update = await caseFromDTO(req.body as CaseDTO);
c.set(update);
const result = await c.save();
res.status(200).json(result);
return;
} else {
// Geocode new cases.
await this.geocode(req);
const c = new Case(req.body);
const update = await caseFromDTO(req.body as CaseDTO);
const c = new Case(update);
const result = await c.save();
res.status(201).json(result);
return;
}
} catch (err) {
} catch (e) {
const err = e as Error;
if (err instanceof GeocodeNotFoundError) {
res.status(404).json({ message: err.message });
}
Expand Down
31 changes: 31 additions & 0 deletions data-serving/data-service/test/controllers/case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,37 @@ describe('PUT', () => {
expect(res.body.notes).toEqual(newNotes);
expect(await c.collection.countDocuments()).toEqual(1);
});
it('upsert present item should update the age buckets', async () => {
const c = new Case(minimalCase);
const sourceId = '5ea86423bae6982635d2e1f8';
const entryId = 'def456';
c.set('caseReference.sourceId', sourceId);
c.set('caseReference.sourceEntryId', entryId);
await c.save();

const ageRange = {
start: 12,
end: 13,
};
await request(app)
.put('/api/cases')
.send({
caseReference: {
sourceId: sourceId,
sourceEntryId: entryId,
sourceUrl: 'cdc.gov',
},
demographics: {
ageRange,
},
...curatorMetadata,
})
.expect('Content-Type', /json/)
.expect(200);

const updatedCase = await Case.findOne({});
expect(updatedCase?.demographics.ageBuckets).toHaveLength(1);
});
it('upsert present item should result in update metadata', async () => {
const c = new Case(minimalCase);
const sourceId = '5ea86423bae6982635d2e1f8';
Expand Down

0 comments on commit 4055df0

Please sign in to comment.