Skip to content

Commit

Permalink
Update age buckets in batchUpdate #2670
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Apr 25, 2022
1 parent 42aae47 commit e0ad9de
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions data-serving/data-service/src/controllers/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,11 @@ export class CasesController {
return;
}
try {
const unrestrictedCases: CaseDocument[] = [];
const restrictedCases: CaseDocument[] = [];
const unrestrictedCases: LeanDocument<CaseDocument>[] = [];
const restrictedCases: LeanDocument<CaseDocument>[] = [];

for (const c in req.body.cases) {
const caseDoc = req.body.cases[c] as CaseDocument;
const caseDoc = await caseFromDTO(req.body.cases[c] as CaseDTO);
let aCase = await Case.findOne({ _id: caseDoc._id });
if (aCase) {
unrestrictedCases.push(caseDoc);
Expand Down
29 changes: 29 additions & 0 deletions data-serving/data-service/test/controllers/case.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,35 @@ describe('PUT', () => {
expect(cases[0].notes).toEqual(newNotes);
expect(cases[1].notes).toEqual(newNotes2);
});
it('update many items should update the age buckets', async () => {
const c = new Case(minimalCase);
await c.save();

const ageRange = {
start: 1,
end: 9,
};

const res = await request(app)
.post('/api/cases/batchUpdate')
.send({
...curatorMetadata,
cases: [
{
_id: c._id,
demographics: {
ageRange,
}
},
],
})
.expect('Content-Type', /json/)
.expect(200);

expect(res.body.numModified).toEqual(1);
const cases = await Case.find();
expect(cases[0].demographics.ageBuckets).toHaveLength(2);
});
it('update many items without locations in travel history should return 200 OK', async () => {
const c = new Case(minimalCase);
await c.save();
Expand Down

0 comments on commit e0ad9de

Please sign in to comment.