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

test: validating JSON files #85

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

johnmcguin
Copy link
Contributor

@johnmcguin johnmcguin commented Aug 30, 2024

Why is this change being made?

resolves #78

How is this being accomplished?

  1. A module to use, providing Ecto schemaless types for each JSON file
  2. assert that each object in the file is a valid?: true Ecto changeset.

Some caveats I wanted to note:

  • casting will not catch a typo like "names" instead of "name". It simply won't include those properties in the changes.
  • You can perform required validations through the required argument when useing the module. This is the main validation I included and consulted the schemas as to what fields should be required.
  • If needed, you can override the validate/1 function in a test file. For example, if you needed or wanted to perform additional validations on the changeset for that particular test file.

Comment on lines 12 to 16
describe "frameworks JSON validation" do
test "validates priv/repo/data/frameworks.json file", %{frameworks: frameworks} do
assert Enum.all?(frameworks, &valid/1)
end
end
Copy link
Owner

Choose a reason for hiding this comment

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

Looks very clean! I like this approach 🔥

Adds a basic schema validation module based around Ecto changesets. Implements the pattern across current JSON files
@johnmcguin johnmcguin marked this pull request as ready for review September 1, 2024 14:28
@johnmcguin johnmcguin changed the title test: PoC validating JSON files test: validating JSON files Sep 1, 2024
@danielbergholz danielbergholz added the enhancement New feature or request label Sep 5, 2024
Copy link
Owner

@danielbergholz danielbergholz left a comment

Choose a reason for hiding this comment

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

This is impressive work @johnmcguin, thanks a lot! Now I'm much more confident when adding any new data on the JSON files 🚀

@danielbergholz danielbergholz merged commit 9eb2100 into danielbergholz:main Sep 5, 2024
2 checks passed
@johnmcguin
Copy link
Contributor Author

woohoo, thanks @danielbergholz ! Happy to find such a cool project to contribute to!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write tests to validate JSON files
2 participants