Skip to content

Commit

Permalink
Updated tests a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Aug 21, 2023
1 parent 66cd13c commit 7481d57
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 144 deletions.
95 changes: 0 additions & 95 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2080,98 +2080,6 @@ describe('datasets and entities', () => {
});
}));

it.skip('should not break when a saveto/bind is on a field inside a repeat group', testService(async (service, container) => {
// Entities made from repeat groups are not yet supported. pyxform throws an error but central does not.
// When parsing the corresponding submission, it will pick the last item in the repeat group.
const form = `<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:entities="http://www.opendatakit.org/xforms/entities" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<h:head>
<h:title>Repeat Children Entities</h:title>
<model entities:entities-version="2022.1.0" odk:xforms-version="1.0.0">
<instance>
<data id="repeat_entity" version="2">
<num_children/>
<child jr:template="">
<child_name/>
</child>
<child>
<child_name/>
</child>
<meta>
<instanceID/>
<instanceName/>
<entity create="1" dataset="children" id="">
<label/>
</entity>
</meta>
</data>
</instance>
<bind entities:saveto="num_children" nodeset="/data/num_children" type="int"/>
<bind entities:saveto="child_name" nodeset="/data/child/child_name" type="string"/>
<bind jr:preload="uid" nodeset="/data/meta/instanceID" readonly="true()" type="string"/>
<bind calculate=" /data/num_children " nodeset="/data/meta/instanceName" type="string"/>
<bind calculate="1" nodeset="/data/meta/entity/@create" readonly="true()" type="string"/>
<bind nodeset="/data/meta/entity/@id" readonly="true()" type="string"/>
<setvalue event="odk-instance-first-load" readonly="true()" ref="/data/meta/entity/@id" type="string" value="uuid()"/>
<bind calculate="concat(&quot;Num children:&quot;, /data/num_children )" nodeset="/data/meta/entity/label" readonly="true()" type="string"/>
</model>
</h:head>
<h:body>
<input ref="/data/num_children">
<label>Num Children</label>
</input>
<group ref="/data/child">
<label>Child</label>
<repeat nodeset="/data/child">
<input ref="/data/child/child_name">
<label>Child Name</label>
</input>
</repeat>
</group>
</h:body>
</h:html>
`;
const sub = `<data xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms" id="repeat_entity" version="2">
<num_children>3</num_children>
<child>
<child_name>abby</child_name>
</child>
<child>
<child_name>benny</child_name>
</child>
<child>
<child_name>chelsea</child_name>
</child>
<meta>
<instanceID>uuid:05bba3e0-fd3b-415c-9123-0e22f010de80</instanceID>
<instanceName>instance name</instanceName>
<entity create="1" dataset="children" id="a930397c-9f27-4f52-aed0-bb2d5bf4b018">
<label>Num children:3</label>
</entity>
</meta>
</data>`;
const alice = await service.login('alice');
await alice.post('/v1/projects/1/forms?publish=true')
.send(form)
.set('Content-Type', 'application/xml')
.expect(200);
await alice.post('/v1/projects/1/forms/repeat_entity/submissions')
.send(sub)
.set('Content-Type', 'application/xml')
.expect(200);
await exhaust(container);
await alice.get('/v1/projects/1/datasets/children/entities/a930397c-9f27-4f52-aed0-bb2d5bf4b018')
.expect(200)
.then(({ body }) => {
body.should.be.an.Entity();
body.should.have.property('currentVersion').which.is.an.EntityDef();
body.currentVersion.should.have.property('data').which.is.eql({
num_children: '3',
child_name: 'chelsea'
});
});
}));

it('should throw an error when a saveto is on a field inside a repeat group', testService(async (service) => {
// Entities made from repeat groups are not yet supported. pyxform also throws an error about this.
const form = `<?xml version="1.0"?>
Expand All @@ -2182,9 +2090,6 @@ describe('datasets and entities', () => {
<instance>
<data id="repeat_entity" version="2">
<num_children/>
<child jr:template="">
<child_name/>
</child>
<child>
<child_name/>
</child>
Expand Down
111 changes: 62 additions & 49 deletions test/unit/data/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ describe('form schema', () => {
});
});

it.skip('should allow binds on fields in repeats even if functionality is not correct', () => { // gh cb#670
it('should reject binds on fields in repeats', () => { // gh cb#670
const xml = `
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa">
Expand Down Expand Up @@ -615,64 +615,77 @@ describe('form schema', () => {
</group>
</h:body>
</h:html>`;
return getFormFields(xml).then((schema) => {
schema.should.eql([
{ name: 'name', path: '/name', type: 'string', order: 0, propertyName: 'parent_name' },
{ name: 'children', path: '/children', type: 'structure', order: 1 },
{ name: 'child', path: '/children/child', type: 'repeat', order: 2 },
{ name: 'name', path: '/children/child/name', type: 'string', order: 3, propertyName: 'child_name' },
{ name: 'toy', path: '/children/child/toy', type: 'repeat', order: 4 },
{ name: 'name', path: '/children/child/toy/name', type: 'string', order: 5 }
]);
});
return getFormFields(xml).should.be.rejected().then((p) => p.problemCode.should.equal(400.25));
});

it('should allow binds on fields in repeats even if functionality is not correct', () => { // gh cb#670
it('should reject binds on fields in nested repeats inside groups', () => { // gh cb#670
const xml = `
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa">
<h:head>
<model>
<instance>
<data id="form">
<name/>
<children>
<child>
<name/>
<toy>
<name/>
</toy>
</child>
</children>
</data>
</instance>
<bind nodeset="/data/name" type="string" entities:saveto="parent_name"/>
<bind nodeset="/data/children/child/name" type="string" entities:saveto="child_name"/>
<bind nodeset="/data/children/child/toy/name" type="string"/>
</model>
</h:head>
<h:body>
<input ref="/data/name">
<label>What is your name?</label>
</input>
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:entities="http://www.opendatakit.org/xforms/entities" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<h:head>
<h:title>Repeat Children Entities</h:title>
<model entities:entities-version="2022.1.0" odk:xforms-version="1.0.0">
<instance>
<data id="repeat_entity" version="1">
<num_children/>
<children>
<child jr:template="">
<child_name/>
<possessions>
<toys jr:template="">
<toy/>
</toys>
</possessions>
</child>
</children>
<meta>
<instanceID/>
<instanceName/>
<entity create="1" dataset="children" id="">
<label/>
</entity>
</meta>
</data>
</instance>
<bind nodeset="/data/num_children" type="int"/>
<bind nodeset="/data/children/child/child_name" type="string"/>
<bind entities:saveto="toy_name" nodeset="/data/children/child/possessions/toys/toy" type="string"/>
<bind jr:preload="uid" nodeset="/data/meta/instanceID" readonly="true()" type="string"/>
<bind calculate=" /data/num_children " nodeset="/data/meta/instanceName" type="string"/>
<bind calculate="1" nodeset="/data/meta/entity/@create" readonly="true()" type="string"/>
<bind nodeset="/data/meta/entity/@id" readonly="true()" type="string"/>
<setvalue event="odk-instance-first-load" readonly="true()" ref="/data/meta/entity/@id" type="string" value="uuid()"/>
<bind calculate="concat(&quot;Num children:&quot;, /data/num_children )" nodeset="/data/meta/entity/label" readonly="true()" type="string"/>
</model>
</h:head>
<h:body>
<input ref="/data/num_children">
<label>Num Children</label>
</input>
<group ref="/data/children">
<label>Children</label>
<group ref="/data/children/child">
<label>Child</label>
<repeat nodeset="/data/children/child">
<input ref="/data/children/child/name">
<label>What is the child's name?</label>
<input ref="/data/children/child/child_name">
<label>Child Name</label>
</input>
<group ref="/data/children/child/toy">
<label>Child</label>
<repeat nodeset="/data/children/child/toy">
<input ref="/data/children/child/toy/name">
<label>What is the toy's name?</label>
</input>
</repeat>
<group ref="/data/children/child/possessions">
<label>Posessions</label>
<group ref="/data/children/child/possessions/toys">
<label>Toys</label>
<repeat nodeset="/data/children/child/possessions/toys">
<input ref="/data/children/child/possessions/toys/toy">
<label>Toy</label>
</input>
</repeat>
</group>
</group>
</repeat>
</group>
</h:body>
</h:html>`;
</group>
</h:body>
</h:html>`;
return getFormFields(xml).should.be.rejected().then((p) => p.problemCode.should.equal(400.25));
});
});
Expand Down

0 comments on commit 7481d57

Please sign in to comment.