Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 40 additions & 36 deletions test/integration/api/forms/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,50 +581,54 @@ describe('api: /projects/:id/forms (create, read, update)', () => {
});
}));

it('should reject with structure changed warning', testService(async (service) => {
const asAlice = await service.login('alice');
describe('with structure changed', () => {
const xmlWithStructureChange = testData.forms.simple.replace(/age/g, 'address');

await asAlice.post('/v1/projects/1/forms/simple/draft')
.send(testData.forms.simple.replace(/age/g, 'address'))
.set('Content-Type', 'application/xml')
.then(({ body }) => {
body.code.should.be.eql(400.16);
body.details.warnings.workflowWarnings[0].should.be.eql({ type: 'structureChanged', details: [ 'age' ] });
});
}));
it('should reject', testService(async (service) => {
const asAlice = await service.login('alice');

it('should reject with structure changed warning', testService(async (service) => {
const asAlice = await service.login('alice');
await asAlice.post('/v1/projects/1/forms/simple/draft')
.send(xmlWithStructureChange)
.set('Content-Type', 'application/xml')
.then(({ body }) => {
body.code.should.be.eql(400.16);
body.details.warnings.workflowWarnings[0].should.be.eql({ type: 'structureChanged', details: [ 'age' ] });
});
}));

await asAlice.post('/v1/projects/1/forms/simple/draft?ignoreWarnings=true')
.send(testData.forms.simple.replace(/age/g, 'address'))
.set('Content-Type', 'application/xml')
.expect(200);
it('should accept if ignoreWarnings set', testService(async (service) => {
const asAlice = await service.login('alice');

await asAlice.post('/v1/projects/1/forms/simple/draft/publish?ignoreWarnings=true&version=v2')
.expect(200);
}));
await asAlice.post('/v1/projects/1/forms/simple/draft?ignoreWarnings=true')
.send(xmlWithStructureChange)
.set('Content-Type', 'application/xml')
.expect(200);

it('should reject with xls and structure changed warnings', testService(async (service) => {
const asAlice = await service.login('alice');
await asAlice.post('/v1/projects/1/forms/simple/draft/publish?ignoreWarnings=true&version=v2')
.expect(200);
}));

await asAlice.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.simple2.replace(/age/g, 'address'))
.set('Content-Type', 'application/xml')
.expect(200);
it('should reject with xls', testService(async (service) => {
const asAlice = await service.login('alice');

global.xlsformTest = 'warning'; // set up the mock service to warn.
await asAlice.post('/v1/projects/1/forms?publish=true')
.send(xmlWithStructureChange)
.set('Content-Type', 'application/xml')
.expect(200);

await asAlice.post('/v1/projects/1/forms/simple2/draft')
.send(readFileSync(appRoot + '/test/data/simple.xlsx'))
.set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
.expect(400)
.then(({ body }) => {
body.code.should.be.eql(400.16);
body.details.warnings.xlsFormWarnings.should.be.eql(['warning 1', 'warning 2']);
body.details.warnings.workflowWarnings[0].should.be.eql({ type: 'structureChanged', details: [ 'address' ] });
});
}));
global.xlsformTest = 'warning'; // set up the mock service to warn.

await asAlice.post('/v1/projects/1/forms/simple2/draft')
.send(readFileSync(appRoot + '/test/data/simple.xlsx'))
.set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
.expect(400)
.then(({ body }) => {
body.code.should.be.eql(400.16);
body.details.warnings.xlsFormWarnings.should.be.eql(['warning 1', 'warning 2']);
body.details.warnings.workflowWarnings[0].should.be.eql({ type: 'structureChanged', details: [ 'address' ] });
});
}));
});

it('should reject form with missing meta group', testService(async (service) => {
const asAlice = await service.login('alice');
Expand Down
Loading