Invalid reports are being considered in Utils functions
Reports in SMS workflows are validated when received, and are still accessed by Nootils when invalid. This means that a Task could be cleared by an invalid report.
Nootils functions such as isFormSubmittedInWindow were created with app workflows in mind. Reports in these workflows are XForms which are validated before submission so any submitted report is valid. We are only encountering this issue now that we are using Nools for SMS workflows as well.
This was also a problem in contact-summary.js (https://github.com/medic/medic-projects/issues/3058), but since it does not use functions from medic-nootils (it uses a local copy) all of the references to other reports were verified with something like this:
var isReportValid = function(report){
// valid XForms won't have `errors` field
// valid JSON forms will have empty array `errors:[]`
if (report && (!report.errors || (report.errors && report.errors.length === 0))) {
return true;
}
else {
return false;
}
};
reports.forEach(function(report) {
if (!isReportValid(report)) { return; }
...
Eventually we'd want contact-summary.js to use these same functions to avoid problems associated with duplicate code, but that will be a separate issue.