Skip to content

Commit

Permalink
Small final test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Dec 6, 2023
1 parent 76bfdb8 commit 4b56426
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 97 deletions.
11 changes: 8 additions & 3 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,7 @@ describe('datasets and entities', () => {
}));

// c#551 issue, <entity/> tag has no children
it('should allow update where no label or no properties are updated', testService(async (service, container) => {
it('should allow update where no label or no properties are updated and entity block is childless', testService(async (service, container) => {
const asAlice = await service.login('alice');

const form = `<?xml version="1.0"?>
Expand Down Expand Up @@ -2931,7 +2931,7 @@ describe('datasets and entities', () => {
}));

// c#552 issue, can't add label to entity update form that previously didnt have label
it('should allow update where no label or no properties are updated', testService(async (service) => {
it('should allow label to be added to entity block in new version of form', testService(async (service) => {
const asAlice = await service.login('alice');

const form = `<?xml version="1.0"?>
Expand Down Expand Up @@ -2983,7 +2983,7 @@ describe('datasets and entities', () => {

// c#553 issue, forms with and without entity label show different fields
// (because entity was previously type 'unknown' instead of 'structure')
it('should allow update where no label or no properties are updated', testService(async (service) => {
it('should show same field type (structure) for meta/entity tag with and without children', testService(async (service) => {
const asAlice = await service.login('alice');

const form = `<?xml version="1.0"?>
Expand Down Expand Up @@ -3038,12 +3038,17 @@ describe('datasets and entities', () => {
.then(({ body }) => {
body[2].path.should.equal('/meta/entity');
body[2].type.should.equal('structure');

body.length.should.equal(3);
});

await asAlice.get('/v1/projects/1/forms/updateWithLabel/fields?odata=true')
.then(({ body }) => {
body[2].path.should.equal('/meta/entity');
body[2].type.should.equal('structure');

body[3].path.should.equal('/meta/entity/label');
body.length.should.equal(4);
});
}));

Expand Down
94 changes: 0 additions & 94 deletions test/integration/other/empty-entity-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,100 +77,6 @@ describe('empty entity structure field', () => {
]);
});
}));

it('should check diff when form version changes to add label', testService(async (service) => {
const form2 = emptyEntityForm
.replace('<entity dataset="people" id="" create="" update="" baseVersion="" />',
'<entity dataset="people" id="" create="" update="" baseVersion=""><label/></entity>')
.replace('orx:version="1.0"', 'orx:version="2.0"');

const sub2 = `<data xmlns:jr="http://openrosa.org/javarosa" xmlns:entities="http://www.opendatakit.org/xforms" id="emptyEntity" version="2.0">
<meta>
<deprecatedID>one</deprecatedID>
<instanceID>one2</instanceID>
<orx:instanceName>one</orx:instanceName>
<entity baseVersion="1" dataset="people" id="12345678-1234-4123-8234-123456789abc" update="1">
<label>foo</label>
<entity>
</meta>
<age>77</age>
<location>
<hometown>san francisco</hometown>
</location>
</data>`;

const sub3 = `<data xmlns:jr="http://openrosa.org/javarosa" xmlns:entities="http://www.opendatakit.org/xforms" id="emptyEntity" version="1.0">
<meta>
<deprecatedID>one2</deprecatedID>
<instanceID>one3</instanceID>
<orx:instanceName>one</orx:instanceName>
<entity baseVersion="1" dataset="people" id="12345678-1234-4123-8234-123456789abc" update="1">
<entity>
</meta>
<age>99</age>
<location>
<hometown>san francisco</hometown>
</location>
</data>`;

const asAlice = await service.login('alice');

// first version of the form
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(emptyEntityForm)
.set('Content-Type', 'application/xml')
.expect(200);

// first version of the submission
await asAlice.post('/v1/projects/1/forms/emptyEntity/submissions')
.send(emptyEntitySub)
.set('Content-Type', 'application/xml')
.expect(200);

// second version of the form with label added
await asAlice.post('/v1/projects/1/forms/emptyEntity/draft')
.send(form2)
.set('Content-Type', 'text/xml')
.expect(200);
await asAlice.post('/v1/projects/1/forms/emptyEntity/draft/publish')
.expect(200);

// edit the submission
await asAlice.put('/v1/projects/1/forms/emptyEntity/submissions/one')
.send(sub2)
.set('Content-Type', 'application/xml')
.expect(200);

// edit again using old form version
await asAlice.put('/v1/projects/1/forms/emptyEntity/submissions/one')
.send(sub3)
.set('Content-Type', 'application/xml')
.expect(200);

await asAlice.get('/v1/projects/1/forms/emptyEntity/submissions/one/diffs')
.set('X-Extended-Metadata', true)
.expect(200)
.then(({ body }) => {
// TODO: it shouldn't actually equal this
body.one2[2].should.eql({ new: '\n ', path: [ 'meta', 'entity', 'entity' ] });

//console.log(body.one2);
// not great:
// { new: 'foo', path: [ 'meta', 'entity', 'label' ] }, // entity label looks good
// { new: '\n ', path: [ 'meta', 'entity', 'entity' ] }, // entity path looks wonky
//console.log(body.one3);
// not great: entity path is wonky, label is weird - saw this when indentation in xml was off
// this whole case where we remove a structural field is also kind of weird, though
// editing a submission with an earlier form version is also weird
// {
// old: '\n ',
// new: '\n ',
// path: [ 'meta', 'entity', 'entity' ]
// },
// with indentation fixed, it looks ok, except frontend might never anticipate new being undefined.
// { old: 'foo', path: [ 'meta', 'entity', 'label' ] },
});
}));
});

describe('odata', () => {
Expand Down

0 comments on commit 4b56426

Please sign in to comment.