Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #869: return warnings if there are any #1350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions lib/model/query/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,16 @@ const createVersion = (partial, form, publish, duplicating = false) => async ({
// skip checking for structural change if duplicating because user has already
// been warning at the time of form definition upload
if (!duplicating) {
await Forms.checkStructuralChange(prevFields, fields)
.then(Forms.rejectIfWarnings);
await Forms.checkStructuralChange(prevFields, fields);
}
// If we haven't been rejected or warned yet, make a new schema id
schemaId = await Forms._newSchema();
}
}

// Let's check for warnings before pushing to Enketo or to DB
await Forms.rejectIfWarnings();

// If not publishing, check whether there is an existing draft that we have access to.
// If not, generate a draft token and enketoId.
let { draftToken, enketoId } = form.def;
Expand Down
19 changes: 19 additions & 0 deletions test/integration/api/forms/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,25 @@ describe('api: /projects/:id/forms (create, read, update)', () => {
}));
}));

it('should fail on warnings even for valid xlsx files', testService(async (service) => {
await service.login('alice', (asAlice) =>
asAlice.post('/v1/projects/1/forms')
.send(readFileSync(appRoot + '/test/data/simple.xlsx'))
.set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
.expect(200));

global.xlsformTest = 'warning'; // set up the mock service to warn.
return service.login('alice', (asAlice) =>
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.equal(400.16);
body.details.warnings.xlsFormWarnings.should.eql([ 'warning 1', 'warning 2' ]);
}));
}));

it('should create the form for xlsx files with warnings given ignoreWarnings', testService((service) => {
global.xlsformTest = 'warning'; // set up the mock service to warn.
return service.login('alice', (asAlice) =>
Expand Down
Loading