Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
feat: adds new validation algorithm, release preparations
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed May 20, 2019
1 parent 98a9e6a commit 20ec986
Show file tree
Hide file tree
Showing 25 changed files with 25 additions and 8 deletions.
8 changes: 5 additions & 3 deletions lib/gavel.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const { HttpRequest, ExpectedHttpRequest } = require('./model/http-request');
const { HttpResponse, ExpectedHttpResponse } = require('./model/http-response');

const { isValid, isValidatable } = require('./validate');
const validate = require('./api/validate');
const validate = require('./next/validate');

module.exports = {
// next
validate,

// legacy
HttpRequest,
HttpResponse,
ExpectedHttpRequest,
ExpectedHttpResponse,
validate,
isValid,
isValidatable
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions lib/api/validate.js → lib/next/validate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const { validateMessage } = require('./validateMessage');

/**
* Validates the given HTTP messages pair and returns
* a legacy-compliant validation results.
* @param {Object} real
* @param {Object} expected
* @param {'request'|'response'} type
* @param {(error: Error, result: Object) => void} callback
*/
function validate(real, expected, type, callback) {
if (type !== 'request' && type !== 'response') {
throw new Error(
Expand Down
File renamed without changes.
11 changes: 9 additions & 2 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@ function proxy(validatableObject, method, cb) {
* @param {'request'|'response'} type
*/
function getValidatableObject(real, expected, type) {
let request;
let response;

switch (type) {
case 'request':
const request = new HttpRequest(real);
request = new HttpRequest(real);
request.expected = new ExpectedHttpRequest(expected);
return request;
case 'response':
const response = new HttpResponse(real);
response = new HttpResponse(real);
response.expected = new ExpectedHttpResponse(expected);
return response;
default:
throw new Error(
`Can't validate: expected HTTP message type to be "request" or "response", but got: ${type}.`
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
},
"scripts": {
"lint": "eslint lib/**/*.js test/**/*.js",
"test": "npm run test:new && npm run test:server && npm run test:browser && npm run test:features",
"test:new": "mocha \"lib/api/test/**/*.test.js\"",
"test": "npm run test:next && npm run test:server && npm run test:browser && npm run test:features",
"test:next": "mocha \"lib/next/test/**/*.test.js\"",
"test:server": "mocha \"test/unit/**/*-test.js\"",
"test:server:coverage": "nyc npm run test:server",
"test:browser": "mochify \"test/unit/**/*.js\"",
"test:features": "node scripts/cucumber.js",
"coveralls": "nyc --reporter=text-lcov npm run test:server | coveralls",
"ci:lint": "npm run lint",
"ci:test": "npm run coveralls && npm run test:new && npm run test:browser && npm run test:features",
"ci:test": "npm run coveralls && npm run test:next && npm run test:browser && npm run test:features",
"ci:release": "semantic-release",
"precommit": "lint-staged"
},
Expand Down

0 comments on commit 20ec986

Please sign in to comment.