-
Notifications
You must be signed in to change notification settings - Fork 10
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
Validation module #109
Merged
Merged
Validation module #109
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3028ee5
Adds validation module
mukkachaitanya b90abc3
Add validate module to encapsulate validations
mukkachaitanya e2b6b3f
Decouple the modules and refactor validation
mukkachaitanya 1961af9
Adds tests for validation module
mukkachaitanya a0ccfc5
Minor spelling correction
mukkachaitanya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const defaultPrefPath = path.join(__dirname, '../../../default-prefs.json'); | ||
const defaultPrefs = JSON.parse(fs.readFileSync(defaultPrefPath, 'utf8')); | ||
|
||
const { supportedLanguages } = defaultPrefs; | ||
|
||
const validate = (evalEvent) => { | ||
if (supportedLanguages.indexOf(evalEvent.details.lang) === -1) { | ||
return { | ||
name: 'invalid_lang', | ||
details: { | ||
supportedLanguages, | ||
}, | ||
}; | ||
} | ||
if (evalEvent.details.idNo === 'root') { | ||
return { | ||
name: 'evaluate', | ||
details: { | ||
idNo: evalEvent.details.i, | ||
lab: evalEvent.details.lab, | ||
lang: evalEvent.details.lang, | ||
commitHash: evalEvent.details.commitHash, | ||
}, | ||
}; | ||
} | ||
return { | ||
name: 'evaluate', | ||
details: { | ||
idNo: evalEvent.details.idNo, | ||
lab: evalEvent.details.lab, | ||
lang: evalEvent.details.lang, | ||
commitHash: evalEvent.details.commitHash, | ||
}, | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
validate, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
prefs
the only command to suffer from the validation problem? What about other commands. Please check again.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Top of my head, I can forsee the following invalid inputs.
123
are obviously not valid. We can look at the validity of usernames for GitLab and repeat the same logic here.We need validations for the above scenarios too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sir since we have a dual nature of input, these validations can only be done after the input it taken from the stdin when necessary. This happens in the
input/prefs
module.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now only prefs has the nested command model which is not taken care by
caporal
. No other commands have this issue right now. I made the validation module to be extensible, so can be extended if need arises in any of the other modules.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed about the validation functions feature provided by
caporal
. Is it better to leave the validation functions inside the controller modules or to havecontrollers/validators/<controller-name.js>?
Putting the non-trivial validators in
controllers/validators/<controller-name.js>
may improve the code design.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, the nested commands are all lined up in the TODO feature list. So, the
validators.js
is not just one single file; we might need a lot of them.