Data Validation
Learn how to test an ecto schema as a data validator.
We'll cover the following
It’s very common in web applications to do some basic validation of user input in the controller. If easy-to-detect issues are present, the application doesn’t spend time doing work (or calling the database) when there isn’t a chance of success.
The code that we’ve already written in the previous lesson takes input and casts it to the appropriate value, returning errors for any data that can’t be cast or any required missing parameters. This is exactly the kind of basic validation that we’re talking about. We’ll update our code to serve as a validator with some very minor changes. After that, we’ll update our refactored tests to reflect the changes.
Note: We’ve created a playground at the end of this lesson where you can perform your updates as we move along with the lesson.
Get hands-on with 1200+ tech skills courses.