Skip to content

Commit

Permalink
fixes getodk#869: return warnings if there are any
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja committed Jan 8, 2025
1 parent 92f1186 commit 3ccd644
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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

0 comments on commit 3ccd644

Please sign in to comment.