v-sight v2.3.7
Installation
sudo npm install v-sightHow it works
It uses Joi schema signature for API schemas as input and will check for test cases by making suited payloads or queries and will return result that contains unexpected responses from API calls for each route as below:
Test cases
This module supports these test cases already:
missing_one: All properties except one will be sent in request and the response status code shoud be400if missed one isrequiredand should not be400if it is one ofoptionals.fake_property: All properties added one fake property which response should be400.fake_post_query: For REST APIsPOSTmethod just accepts payloads so to test these case you can add this to your cases in options.
API
defaults(configs)
Adding default options as an object as below properties:
baseUrl: the url will be used for all tests likehttp://localhost:800.testCases: An array with test cases as items like['fake_property', 'missing_one'].
look(schemas, [options], [testCases], callback)
Will run all test cases which have been provided.
schemas: the Joi schemasoptions:testCases: astestsCasesin defaults.If not set all test cases will be applied.timeout: requests timeouts. If there is atimeoutfor any request it will be throw as an error with the url inside it, default is3000milliseconds.first_error: if set asfalseall errors will be returned, default istrue.baseUrl: You may need to change base url for a set of tests so add it here.login: As an object for all routes which need authenticationurl: the login route which will usebaseUrlas its base.auth: As an object which have all properties for login credentials.
challback(errors): will be called when there is first error fror all cases.
Examples and usage
v_sight = require('v-sight')
// Setting defaults
v_sight.defaults({ baseUrl: 'http://localhost:8080' })
// Setting options for a role
var options = {
login: {
url: '/v1/users/login',
auth: {
email: 'john.doue@mail.me',
password: 'test-password-1',
}
}
}
// User signup validations
schemas = {
'post/v1/users/buy': {
payload: {
product_id: Joi.string().required(),
description: Joi.string().optional(),
address: Joi.object().keys({
City: Joi.string().required().default('Tehran'),
Street: Joi.string().required()
}
},
defaults: {
product_id: '1234',
description: 'This is my desired one',
address: {
Street: 'Motahari'
}
}
}
}
v_sight.look(schemas, options, (errors) => {
if(errors) {
console.log(errors)
}
})Returned errors structure
All fialed tests have these two signatures:
When
first_errorhas been set astrue.default istrue.{ code: 'http status codes', url: 'baseUrl + route', flag: 'from schema or fake for fake_property test case', server_message: 'returning message from server', help: 'a message will help you to find the error' }when
first_errorhas been set asfalse.{ 'post/users/signup': [ { // as 1 } ... ] ... }
Use with Mocha and chai
When using mocha you can call done() in callback:
var should = require('chai').should();
describe('Users', () => {
it('should be validate for all requireds, optinals'), function(done) {
v_sight.look(user_Options, user_schemas, (errors) => {
should.not.exist(errors)
done()
})
});9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago