Logo: Relish

  1. Sign in

Project: Gavel 3.0.0

Request validation

  • @javascript
Background
Given
you call:
const gavel = require('gavel');
And
you define following HTTP request object:
const real = {
  "method": "GET",
  "uri": "/ip",
  "headers": {
    "user-agent": "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5",
    "host": "httpbin.org",
    "accept": "*/*"
  },
  "body": ""
};
And
you define following expected HTTP request object:
const expected = {
  "headers": {
    "user-agent": "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5",
    "host": "httpbin.org",
    "accept": "*/*"
  },
  "body": ""
};
Scenarios
  • @stable
validate
When
you call:
gavel.validate(expected, real);
Then
it will return:
{
  isValid: true,
  fields: {
    headers: {
      isValid: true,
      errors: [],
      realType: 'application/vnd.apiary.http-headers+json',
      expectedType: 'application/vnd.apiary.http-headers+json',
      validator: 'HeadersJsonExample',
      rawData: { length: 0 }
    },
    body: {
      isValid: true,
      errors: [],
      realType: 'text/plain',
      expectedType: 'text/plain',
      validator: 'TextDiff',
      rawData: ''
    }
  }
}

Last published about 1 month ago by honzajavorek.