Skip to content

Commit

Permalink
Tests for entity-updating forms modifying dataset properties (#1034)
Browse files Browse the repository at this point in the history
* Tests for entity-updating forms modifying dataset properties

* Respond to PR comments
  • Loading branch information
ktuite authored Oct 31, 2023
1 parent 16c2660 commit 048a5b9
Showing 1 changed file with 132 additions and 0 deletions.
132 changes: 132 additions & 0 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,138 @@ describe('datasets and entities', () => {

}));

describe('uploading forms that UPDATE but do not create entities', () => {
it('should be able to add properties to datasets', testService(async (service) => {
const asAlice = await service.login('alice');
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.simpleEntity)
.set('Content-Type', 'text/xml')
.expect(200);

await asAlice.post('/v1/projects/1/forms')
.send(testData.forms.updateEntity
.replace('entities:saveto="first_name"', 'entities:saveto="nickname"'))
.set('Content-Type', 'text/xml')
.expect(200);

await asAlice.get('/v1/projects/1/forms/updateEntity/draft/dataset-diff')
.expect(200)
.then(({ body }) => {
body.should.be.eql([
{
name: 'people',
isNew: false,
properties: [
{ name: 'first_name', isNew: false, inForm: false },
{ name: 'nickname', isNew: true, inForm: true },
{ name: 'age', isNew: false, inForm: true }
]
}
]);
});

await asAlice.post('/v1/projects/1/forms/updateEntity/draft/publish');

await asAlice.get('/v1/projects/1/forms/updateEntity/dataset-diff')
.expect(200)
.then(({ body }) => {
body.should.be.eql([
{
name: 'people',
properties: [
{ name: 'first_name', inForm: false },
{ name: 'nickname', inForm: true },
{ name: 'age', inForm: true }
]
}
]);
});
}));

it('should be able to have an update entity form with no savetos', testService(async (service) => {
const asAlice = await service.login('alice');
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.simpleEntity)
.set('Content-Type', 'text/xml')
.expect(200);

await asAlice.post('/v1/projects/1/forms')
.send(testData.forms.updateEntity
.replace('entities:saveto="first_name"', '')
.replace('entities:saveto="age"', ''))
.set('Content-Type', 'text/xml')
.expect(200);

await asAlice.get('/v1/projects/1/forms/updateEntity/draft/dataset-diff')
.expect(200)
.then(({ body }) => {
body.should.be.eql([
{
name: 'people',
isNew: false,
properties: [
{ name: 'first_name', isNew: false, inForm: false },
{ name: 'age', isNew: false, inForm: false }
]
}
]);
});

await asAlice.post('/v1/projects/1/forms/updateEntity/draft/publish');

await asAlice.get('/v1/projects/1/forms/updateEntity/dataset-diff')
.expect(200)
.then(({ body }) => {
body.should.be.eql([
{
name: 'people',
properties: [
{ name: 'first_name', inForm: false },
{ name: 'age', inForm: false }
]
}
]);
});
}));

it('should create dataset if it does not exist and and log it', testService(async (service) => {
const asAlice = await service.login('alice');
await asAlice.post('/v1/projects/1/forms')
.send(testData.forms.updateEntity)
.set('Content-Type', 'text/xml')
.expect(200);

await asAlice.get('/v1/projects/1/forms/updateEntity/draft/dataset-diff')
.expect(200)
.then(({ body }) => {
body.should.be.eql([
{
name: 'people',
isNew: true, // Dataset is new
properties: [
{ name: 'first_name', isNew: true, inForm: true },
{ name: 'age', isNew: true, inForm: true }
]
}
]);
});

await asAlice.post('/v1/projects/1/forms/updateEntity/draft/publish');

await asAlice.get('/v1/projects/1/datasets/people')
.expect(200)
.then(({ body }) => {
body.name.should.be.eql('people');
body.properties.map(p => p.name).should.eql([ 'first_name', 'age' ]);
});

await asAlice.get('/v1/audits?action=dataset.create')
.expect(200)
.then(({ body: audits }) => {
audits[0].details.should.eql({ properties: ['first_name', 'age'] });
});
}));
});
});

describe('dataset property interaction with intermediate form schemas and purging uneeded drafts', () => {
Expand Down

0 comments on commit 048a5b9

Please sign in to comment.