Skip to content

Commit

Permalink
Allow 2024.1 entity xform spec version (offline entities) (#1163)
Browse files Browse the repository at this point in the history
* Allow 2024.1 entity xform spec version (offline entities)

* Use semver to check entity xform spec
  • Loading branch information
ktuite authored Jul 16, 2024
1 parent 0cd5694 commit beea5c8
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 22 deletions.
4 changes: 3 additions & 1 deletion lib/data/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// about datasets and mappings from form fields to
// dataset properties.

const semverSatisfies = require('semver/functions/satisfies');

const Option = require('../util/option');
const Problem = require('../util/problem');
const { traverseXml, findOne, root, node, attr, stripNamespacesFromPath } = require('../util/xml');
Expand Down Expand Up @@ -77,7 +79,7 @@ const getDataset = (xml) =>

if (version.isEmpty())
throw Problem.user.invalidEntityForm({ reason: 'Entities specification version is missing.' });
else if (!(version.get().startsWith('2022.1.') || version.get().startsWith('2023.1.')))
else if (!semverSatisfies(version.get(), '2022.1.0 - 2024.1.x'))
throw Problem.user.invalidEntityForm({ reason: `Entities specification version [${version.get()}] is not supported.` });

const strippedAttrs = Object.create(null);
Expand Down
76 changes: 59 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"prompt": "~1",
"ramda": "~0",
"sanitize-filename": "~1",
"semver": "^7.6.2",
"slonik": "npm:@getodk/[email protected]",
"slonik-sql-tag-raw": "npm:@getodk/[email protected]",
"tmp-promise": "~3",
Expand All @@ -64,7 +65,6 @@
"nodemon": "~3",
"nyc": "~15",
"oidc-provider": "^8.4.5",
"semver": "^7.5.3",
"should": "~13",
"streamtest": "~1.2",
"supertest": "^6.3.3",
Expand Down
2 changes: 1 addition & 1 deletion test/data/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ module.exports = {
offlineEntity: `<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:entities="http://www.opendatakit.org/xforms">
<h:head>
<model entities:entities-version="2023.1.0">
<model entities:entities-version="2024.1.0">
<instance>
<data id="offlineEntity" orx:version="1.0">
<name/>
Expand Down
14 changes: 12 additions & 2 deletions test/unit/data/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@ describe('parsing dataset from entity block', () => {
.replace('2022.1.0', '2022.1.123'))
.should.be.fulfilled());

it('should validate a version between major releases, e.g. 2023.2.0', () =>
getDataset(testData.forms.updateEntity
.replace('2023.1.0', '2023.2.0'))
.should.be.fulfilled());

it('should validate any version that starts with 2023.1.', () =>
getDataset(testData.forms.updateEntity
.replace('2023.1.0', '2023.1.123'))
.should.be.fulfilled());

it('should validate any version that starts with 2024.1.', () =>
getDataset(testData.forms.offlineEntity
.replace('2024.1.0', '2024.1.123'))
.should.be.fulfilled());

it('should reject probable future version', () =>
getDataset(testData.forms.simpleEntity
.replace('2022.1.0', '2024.1.0'))
.replace('2022.1.0', '2025.1.0'))
.should.be.rejectedWith(Problem, { problemCode: 400.25,
message: 'The entity definition within the form is invalid. Entities specification version [2024.1.0] is not supported.' }));
message: 'The entity definition within the form is invalid. Entities specification version [2025.1.0] is not supported.' }));

it('should complain if version is wrong', () =>
getDataset(testData.forms.simpleEntity
Expand Down

0 comments on commit beea5c8

Please sign in to comment.