Skip to content

Commit

Permalink
Warn about old entity spec version in form draft update
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Dec 3, 2024
1 parent 911739b commit 111b262
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/model/query/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ const createVersion = (partial, form, publish, duplicating = false) => async ({
// Parse form fields and dataset/entity definition from form XML
const [fields, parsedDataset] = await _parseFormXml(partial);

// Check entities spec version
await Forms.checkDatasetWarnings(parsedDataset);
await Forms.rejectIfWarnings();

// Compute the intermediate schema ID
let schemaId;
let match;
Expand All @@ -242,8 +246,8 @@ const createVersion = (partial, form, publish, duplicating = false) => async ({
// skip checking for structural change if duplicating because user has already
// been warning at the time of form definition upload
if (!duplicating) {
await Forms.checkStructuralChange(prevFields, fields)
.then(Forms.rejectIfWarnings);
await Forms.checkStructuralChange(prevFields, fields);
await Forms.rejectIfWarnings();
}
// If we haven't been rejected or warned yet, make a new schema id
schemaId = await Forms._newSchema();
Expand Down
28 changes: 28 additions & 0 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3483,9 +3483,37 @@ describe('datasets and entities', () => {
});

await asAlice.post('/v1/projects/1/forms?ignoreWarnings=true')
.send(testData.forms.updateEntity2023)
.set('Content-Type', 'application/xml')
.expect(200);
}));

it('should warn if the entities-version is earlier than 2024.1.0 when uploading a version of an existing form', testService(async (service) => {
const asAlice = await service.login('alice');

// Post version of form that has good 2024.1.0 version
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.updateEntity)
.set('Content-Type', 'application/xml')
.expect(200);

await asAlice.post('/v1/projects/1/forms/updateEntity/draft')
.send(testData.forms.updateEntity2023)
.set('Content-Type', 'application/xml')
.expect(400)
.then(({ body }) => {
body.code.should.be.eql(400.16);
body.details.warnings.workflowWarnings[0].should.be.eql({
type: 'oldEntityVersion',
details: { version: '2023.1.0' },
reason: 'Entities specification version [2023.1.0] is not compatible with Offline Entities. Please use version 2024.1.0 or later.'
});
});

await asAlice.post('/v1/projects/1/forms/updateEntity/draft?ignoreWarnings=true')
.send(testData.forms.updateEntity2023)
.set('Content-Type', 'application/xml')
.expect(200);
}));
});

Expand Down

0 comments on commit 111b262

Please sign in to comment.