Issue 1217 - CSV Upload Validation Checks#1579
Conversation
…ion for checking each value towards the bottom of the uploadMeters.js file as well as calling them when the submission is sent to the server
… made sure the correct data was being sent back to the client side
…ifferent caps/lowercase
…csv-validation Boolean value validations
…csv-validation Min max validation
Merge branch 'Issue1217-csv-validation' of https://github.com/SageMar/OED into Issue1217-csv-validation
…ecked, now it converts strings to ints and functions
…checked for validity before calling it to check min<max
… decimals are passing through
finished isDuplicate()
corrected isValidDate() logic
…TimeFormat, isDuplicate before PR
…imeFormat, isDuplicate
Co-authored-by: Destiny Veloz <destinyveloz@msn.com> Co-authored-by: Oscar Aviles-Saldana <oaviles-saldana@csumb.edu>
Co-authored-by: Destiny Veloz destinyveloz@msn.com Co-authored-by: Oscar Aviles-Saldana oaviles-saldana@csumb.edu
Co-authored-by: Destiny Veloz <destinyveloz@msn.com> Co-authored-by: Oscar Aviles-Saldana <oaviles-saldana@csumb.edu>
…vilSal/OED into final_checks_uploadMeters
|
@kyle-parker-1500 Thank you for this PR. I see the CLA box is checked in the description. Given this, could you help with these:
Please let me know if anything is not clear or you have thoughts. |
|
Hi @huss , |
|
@kyle-parker-1500, @DestinyVeloz & @OscarAvilSal: First I want to apologize for how long my response has taken during an usual time. Second, I have started to review the work but I need more time to do it well. Please let me know if these are an issue. |
|
@huss don't worry about it and take your time with the review! My team and I are ready and able to fix any issues you find. |
huss
left a comment
There was a problem hiding this comment.
Thanks to @kyle-parker-1500, @DestinyVeloz & @OscarAvilSal for this contribution. Again, I'm sorry my comments took so long. I've provided a number of comments to think about. Some are about code from earlier work as I reviewed this PR. Some are more general changes. Given this, if you don't want to address any of those you can leave a comment and OED can decide how to deal with them. Finally, I have yet to do careful testing of uploads (waiting for more finalized code) nor check that every index into the meter array is correct (didn't want you to wait while I do all of those and the method may change so doing that later may be bettert). Please let me know if anything is not clear, you have thoughts or I can help in any way.
| const readCsv = require('../pipeline-in-progress/readCsv'); | ||
| const Unit = require('../../models/Unit'); | ||
| const { normalizeBoolean } = require('./validateCsvUploadParams'); | ||
| const { normalizeBoolean, MeterTimeSortTypesJS, MeterTimeSortTypesJS } = require('./validateCsvUploadParams'); |
There was a problem hiding this comment.
Is MeterTimeSortTypesJS included twice?
| return { maxErrorMsg: msg, value: false }; | ||
| } | ||
| } | ||
| return { maxErrorMsg: '', value: true }; |
There was a problem hiding this comment.
I'm wondering about returning this as value: true in the case that it is a NaN above. It should be a number so should this case also fail? I think this applies to other new tests.
|
|
||
| if (areaUnit && areaUnit.toLowerCase() === 'none') { | ||
| if(!isNaN(areaValue) && areaValue !== 0) { | ||
| msg = `Invalid area value in row ${rowIndex + 1}: area="${meter[9]}". ` + `Area must be empty when area unit is 'none'.`; |
There was a problem hiding this comment.
The indenting seems off and is using spaces instead of tabs as OED wants.
I looks like the test is for a non-zero area value so I wonder if the msg should say that too.
| * @param {express.Response} res | ||
| * @param {express.Request} req | ||
| * @param {express.Response} res | ||
| * @param {express.Request} req |
There was a problem hiding this comment.
I'm wondering about listing req & res twice as params since they are once in the function. I don't think you made this change but is from the original PR. Thoughts?
| */ | ||
| function isValidTimeSort(timeSortValue) { | ||
| const validTimes = Object.values(MeterTimeSortTypesJS); | ||
| // must be one of the three values |
There was a problem hiding this comment.
(old code) This is not correct as there are currently two values. I would put "must be one of the allowed enum values."
| function validateVariation(meter, rowIndex){ | ||
| const variationValue = Number(meter[15]); | ||
| if(!isNaN(variationValue)){ | ||
| if(variationValue < 0) |
There was a problem hiding this comment.
Please format so { is on same line as if statement.
| if(!isNaN(variationValue)){ | ||
| if(variationValue < 0) | ||
| { | ||
| throw new CSVPipelineError( |
There was a problem hiding this comment.
Similar to other comment, this throws error inside check.
| { | ||
| throw new CSVPipelineError( | ||
| `Invalid variation value in row ${rowIndex + 1}: VariationValue="${meter[15]}". ` + | ||
| `Variation Value must be a number larger than 0.`, |
There was a problem hiding this comment.
Formally reading variation so should say that.
| const variationInput = meter[15]; | ||
| if (variationInput) { | ||
| if (!validateVariation(variationInput)) { | ||
| let msg = `For meter ${meter[0]} the Gap entry of ${variationInput} is invalid. Gap must be a number greater than 0.`; |
There was a problem hiding this comment.
See other function about not returning value. Also, the msg should not be referring to gap.
| */ | ||
| function validateBooleanFields(meter, rowIndex) { | ||
| // all inputs that involve a true or false all being validated together. | ||
| const booleanFields = { |
There was a problem hiding this comment.
I like defining the index via a key. I'm thinking it would be better to define them all at the start to isolate this ugly fact and to make it clearer what is being accessed since it would be by kay name. Then all the rest of the code gets rid of the index value and uses the key. This is a new change so let me know your thoughts and if you want to do this.
Description
Partly Addresses #1217
Type of change
Added validation checks for the following 6 fields within the
uploadMeters.jsfile according to the note left on PR1403:Checklist
Limitations
The branch which these changes were pushed on is around 300 commits behind the development branch. Also not all meters have checks being done on them, only those listed in PR1403 and those listed here. Destiny destinyveloz@msn.com, Oscar oaviles-saldana@csumb.edu, and I kylerparker1500@gmail.com are open to continue working on this issue.
Thank you to @SageMar and @cmatthews444 for writing the previous checks, much of our code was derived from what you wrote.