Skip to content

Commit

Permalink
Merge f61846a into a39dbce
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed May 22, 2019
2 parents a39dbce + f61846a commit 4417530
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/next/test/integration/validateMessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ describe('validateMessage', () => {
});

it('contains all validatable keys', () => {
assert.hasAllKeys(result, ['headers', 'body']);
assert.hasAllKeys(result, ['isValid', 'headers', 'body']);
});

it('has "isValid" set to true', () => {
assert.propertyVal(result, 'isValid', true);
});

describe('headers', () => {
Expand Down Expand Up @@ -86,7 +90,11 @@ describe('validateMessage', () => {
});

it('contains all validatable keys', () => {
assert.hasAllKeys(result, ['headers', 'body']);
assert.hasAllKeys(result, ['isValid', 'headers', 'body']);
});

it('has "isValid" set to false', () => {
assert.propertyVal(result, 'isValid', false);
});

describe('method', () => {
Expand Down Expand Up @@ -168,7 +176,11 @@ describe('validateMessage', () => {
});

it('contains all validatable keys', () => {
assert.hasAllKeys(result, ['statusCode', 'headers', 'body']);
assert.hasAllKeys(result, ['isValid', 'statusCode', 'headers', 'body']);
});

it('sets "isValid" to true', () => {
assert.propertyVal(result, 'isValid', true);
});

describe('statusCode', () => {
Expand Down Expand Up @@ -262,7 +274,11 @@ describe('validateMessage', () => {
});

it('contains all validatable keys', () => {
assert.hasAllKeys(result, ['statusCode', 'headers']);
assert.hasAllKeys(result, ['isValid', 'statusCode', 'headers']);
});

it('has "isValid" as false', () => {
assert.propertyVal(result, 'isValid', false);
});

describe('statusCode', () => {
Expand Down
4 changes: 4 additions & 0 deletions lib/next/validateMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function validateMessage(realMessage, expectedMessage) {
results.body = validateBody(real, expected);
}

results.isValid = !Object.values(results).some((resultGroup) => {
return resultGroup.results.some((result) => result.severity === 'error');
});

return results;
}

Expand Down
10 changes: 10 additions & 0 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ function getValidatableObject(real, expected, type) {
}

function isValid(real, expected, type, cb) {
console.warn(`\
Usage of "isValid" is deprecated and will be removed in the future releases of Gavel.
Use "isValid" property of the validation result instead:
const { validate } = require('gavel');
const result = validate(real, expected, 'request');
const { isValid } = result;\
`);

return proxy(getValidatableObject(real, expected, type), 'isValid', cb);
}

Expand Down

0 comments on commit 4417530

Please sign in to comment.