Skip to content

Commit

Permalink
Write a test to ensure identical cases in batchUpsert are ignored #2670
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed May 5, 2022
1 parent 9b261e1 commit c7ec23c
Showing 1 changed file with 31 additions and 0 deletions.
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 @@ -624,6 +624,37 @@ describe('POST', () => {
const updatedCaseInDb = await Case.findById(changedCaseWithEntryId._id);
expect(updatedCaseInDb?.notes).toEqual(changedCaseWithEntryId.notes);
});
it('batch upsert with same case twice should not update anything', async () => {
const newCaseWithEntryId = new Case(minimalCase);
newCaseWithEntryId.caseReference.sourceEntryId = 'newId';

const res = await request(app)
.post('/api/cases/batchUpsert')
.send({
cases: [
newCaseWithEntryId,
],
...curatorMetadata,
})
.expect(200);

expect(res.body.numCreated).toBe(1); // Exactly one case created.
expect(res.body.numUpdated).toBe(0); // No case was updated.

const secondRes = await request(app)
.post('/api/cases/batchUpsert')
.send({
cases: [
newCaseWithEntryId, // same case again!
],
...curatorMetadata,
})
.expect(200);

expect(secondRes.body.numCreated).toBe(0); // No case created this time.
expect(res.body.numUpdated).toBe(0); // No case was updated either.
});

it('batch upsert should add uploadId to field array', async () => {
const newUploadIds = ['012301234567890123456789'];

Expand Down

0 comments on commit c7ec23c

Please sign in to comment.