Skip to content

Commit

Permalink
Change entity update uuid not found to be more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Oct 17, 2023
1 parent fdd5718 commit 9f59dea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/model/query/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const { equals, extender, unjoiner, page, markDeleted } = require('../../util/db
const { map, mergeRight, pickAll } = require('ramda');
const { blankStringToNull, construct } = require('../../util/util');
const { QueryOptions } = require('../../util/db');
const { getOrNotFound } = require('../../util/promise');
const { odataFilter } = require('../../data/odata-filter');
const { odataToColumnMap, parseSubmissionXml, getDiffProp, ConflictType } = require('../../data/entity');
const { isTrue } = require('../../util/http');
Expand Down Expand Up @@ -177,7 +176,8 @@ const _updateEntity = (dataset, entityData, submissionId, submissionDef, submiss
const clientEntity = await Entity.fromParseEntityData(entityData); // validation happens here

// Get version of entity on the server
const serverEntity = await Entities.getById(dataset.id, clientEntity.uuid).then(getOrNotFound);
const serverEntity = (await Entities.getById(dataset.id, clientEntity.uuid))
.orThrow(Problem.user.entityNotFound({ entityUuid: clientEntity.uuid, datasetName: dataset.name }));

let { conflict } = serverEntity;
let conflictingProperties; // Maybe we don't need to persist this??? just compute at the read time
Expand Down
3 changes: 3 additions & 0 deletions lib/util/problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ const problems = {
// dataset in submission does not exist
datasetNotFound: problem(404.7, ({ datasetName }) => `The dataset (${datasetName}) specified in the submission does not exist.`),

// entity in submission does not exist
entityNotFound: problem(404.8, ({ entityUuid, datasetName }) => `The entity with UUID (${entityUuid}) specified in the submission does not exist in the dataset (${datasetName}).`),

// { allowed: [ acceptable formats ], got }
unacceptableFormat: problem(406.1, ({ allowed }) => `Requested format not acceptable; this resource allows: ${allowed.join()}.`),

Expand Down
4 changes: 2 additions & 2 deletions test/integration/worker/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ describe('worker: entity', () => {
const event = await container.Audits.getLatestByAction('entity.error').then((o) => o.get());
event.actorId.should.equal(5); // Alice
event.details.submissionId.should.equal(subEvent.details.submissionId);
event.details.errorMessage.should.equal('Could not find the resource you were looking for.');
event.details.problem.problemCode.should.equal(404.1);
event.details.problem.problemCode.should.equal(404.8);
event.details.errorMessage.should.equal('The entity with UUID (12345678-1234-4123-8234-123456789abc) specified in the submission does not exist in the dataset (people).');
}));

it('should fail for other constraint errors like dataset name does not exist', testService(async (service, container) => {
Expand Down

0 comments on commit 9f59dea

Please sign in to comment.