POC using Joi to test contracts. Using Open api Pokeapi.
JOI is a library made by the Hapi team that is a Framework for developing applications and services. JOI allows you to create plans or schemas for JavaScript objects and perform validation on them with JOI-Assert.
validations | example |
---|---|
Joi.string().required() | String and Required |
Joi.number().integer().positive() | Inteiro, Positivo |
Joi.string().valid(‘English’) | String, where we will only accept the value 'English' |
oi.string().valid([‘movie’, ‘series’, ‘cartoon’]) | String, where we will only accept the value informed in the list |
Joi.any().allow('Test-1', 'Test-2') | Please be informed that we will only accept Test-1 and Test-2 |
Joi.string().optional().allow(”, null) | Please be informed that the property is optional and empty and null is allowed |
Joi.boolean().required() | Boolean option, in which we will only accept true or false values |
Joi.date().min('1-1-1974') | We inform a minimum date for that amount |
Joi.string().required() | String and Required |
For more validations access joi-git
clone the project and run the command below.
npm install
Create a file at the root of the project with the name .env
.env var | value |
---|---|
HOST | https://pokeapi.co/api/v2 |
commands | tests that are going to run |
---|---|
npm test |
runs the only test |