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

ProfilesComponent: Add field validation for custom profiles #623

Merged
merged 30 commits into from
Mar 12, 2021

Conversation

dingyuchen
Copy link
Contributor

@dingyuchen dingyuchen commented Mar 4, 2021

Summary

Fixes #567

The app proceeds silently if the selected profiles.json does not have a profileName or encodedText field.
(encodedText refers to the repo holding the settings.json / data.csv files)

Proposed Commit Message

ProfilesComponent: Add field validation

The app proceeds silently if the selected profiles.json does not have a profileName or encodedText field.

Let's:
* Add generic function to validate existence of keys in an object
* Validate profiles during upload and selection of profiles
* Open an error dialog if the profile object is malformed

@dingyuchen dingyuchen requested a review from a team March 4, 2021 11:28
Copy link
Contributor

@seanlowjk seanlowjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments from my side! Please have a look at the bug where the None option is slected!

src/app/shared/lib/validate.ts Outdated Show resolved Hide resolved
src/app/auth/profiles/profiles.component.ts Show resolved Hide resolved
Copy link
Contributor

@seanlowjk seanlowjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a single comment here!

Other than that, thanks for the good work! 💯

dingyuchen and others added 2 commits March 7, 2021 10:04
Co-authored-by: Low Jun Kai, Sean <42912708+seanlowjk@users.noreply.github.com>
@codecov-io
Copy link

codecov-io commented Mar 7, 2021

Codecov Report

Merging #623 (e014860) into master (ddb57c2) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #623      +/-   ##
==========================================
+ Coverage   67.71%   67.80%   +0.08%     
==========================================
  Files          73       75       +2     
  Lines        2187     2196       +9     
  Branches      201      202       +1     
==========================================
+ Hits         1481     1489       +8     
  Misses        664      664              
- Partials       42       43       +1     
Impacted Files Coverage Δ
src/environments/environment.gen.ts 80.00% <ø> (ø)
src/app/core/models/profile.model.ts 100.00% <100.00%> (ø)
src/app/shared/lib/validate.ts 100.00% <100.00%> (ø)
src/app/shared/issue-tables/issue-sorter.ts 44.00% <0.00%> (-4.00%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ddb57c2...e014860. Read the comment docs.

@dingyuchen dingyuchen requested a review from anubh-v March 8, 2021 05:44
Copy link
Contributor

@anubh-v anubh-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is on the right track, but a bit of refactoring can be done to make this more testable.

Let's :

  • Move the Profile interface, as well as the profileSchema into a new profile.model.tsmodule
  • Export a isValidProfile method from this module. This method will use the schema internally
  • Use isValidProfile in the ProfilesComponent
  • Add some tests for isValidProfile

src/app/auth/profiles/profiles.component.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@ptvrajsk ptvrajsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job with this! 👍 I like how you used the Schema interface in creating a clean way to validate our profiles.json. Just some minor discussion points.


const profileSchema: Schema = {
profileName: { required: true, validate: (value) => !!value },
encodedText: { required: true, validate: (value) => !!value }
Copy link
Contributor

@ptvrajsk ptvrajsk Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have the extra layer of validation to make sure that encoded text follows the org/repo format? So the validate function can use regex or any form of string manipulation to verify the encoded text adheres to the right format?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that's a good point. i guess we'll be matching for string/string?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! 👍

Copy link
Contributor

@anubh-v anubh-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. @CATcher-org/2021-devs any further comments?

src/app/core/models/profile.model.ts Outdated Show resolved Hide resolved
Co-authored-by: Anubhav <35621759+anubh-v@users.noreply.github.com>
@ptvrajsk ptvrajsk self-requested a review March 12, 2021 05:00
Copy link
Contributor

@ptvrajsk ptvrajsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@anubh-v anubh-v merged commit 1f9f945 into CATcher-org:master Mar 12, 2021
@anubh-v anubh-v changed the title Assert 'profiles.json' to have required fields ProfilesComponent: Add field validation for custom profiles Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Profile selection: App does not assert whether 'profiles.json' has required fields
5 participants