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

Commit 807a879

Browse files
feat: stops using "isValid" internally
1 parent f0960fe commit 807a879

File tree

6 files changed

+15
-119
lines changed

6 files changed

+15
-119
lines changed

bin/gavel

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
/* eslint-disable */
23

34
var cmd = require('commander');
45
var httpParser = require('http-string-parser');
@@ -32,20 +33,21 @@ process.stdin.on('end', function() {
3233
var requestResult = false;
3334
var responseResult = false;
3435

35-
gavel.isValid(realRequest, expectedRequest, 'request', function(
36+
gavel.validate(realRequest, expectedRequest, 'request', function(
3637
err,
3738
result
3839
) {
3940
requestResult = result;
40-
gavel.isValid(realResponse, expectedResponse, 'response', function(
41+
42+
gavel.validate(realResponse, expectedResponse, 'response', function(
4143
err,
4244
result
4345
) {
4446
responseResult = result;
4547
});
4648
});
4749

48-
if (requestResult && responseResult) {
50+
if (requestResult.isValid && responseResult.isValid) {
4951
process.exit(0);
5052
} else {
5153
process.exit(1);

test/cucumber/step_definitions/validation_errors_thens.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
module.exports = function() {
23
this.Then(/^Gavel will set some error for "([^"]*)"$/, function(
34
component,
@@ -56,7 +57,7 @@ module.exports = function() {
5657
});
5758

5859
this.Then(/^Request or Response is NOT valid$/, function(callback) {
59-
return this.isValid((error, result) => {
60+
return this.validate((error, result) => {
6061
if (result) {
6162
callback(
6263
new Error('Request or Response is valid and should NOT be valid.')
@@ -67,7 +68,7 @@ module.exports = function() {
6768
});
6869

6970
return this.Then(/^Request or Response is valid$/, function(callback) {
70-
return this.isValid((error, result) => {
71+
return this.validate((error, result) => {
7172
if (!result) {
7273
callback(
7374
new Error('Request or Response is NOT valid and should be valid.')

test/cucumber/step_definitions/validators_steps.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
const tv4 = require('tv4');
23
const { assert } = require('chai');
34
const deepEqual = require('deep-equal');
@@ -31,7 +32,7 @@ module.exports = function() {
3132
}
3233
this.results = JSON.parse(JSON.stringify(result));
3334

34-
return this.isValid((error, result) => {
35+
return this.validate((error, result) => {
3536
if (error) {
3637
callback(new Error(error));
3738
}

test/cucumber/support/world.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* DS102: Remove unnecessary code created because of implicit returns
55
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
66
*/
7+
/* eslint-disable */
78
const gavel = require('../../../lib/gavel');
89
const vm = require('vm');
910
const util = require('util');
@@ -107,10 +108,6 @@ class World {
107108
}
108109
}
109110

110-
isValid(callback) {
111-
return gavel.isValid(this.real, this.expected, 'response', callback);
112-
}
113-
114111
validate(callback) {
115112
return gavel.validate(this.real, this.expected, 'response', callback);
116113
}

test/unit/mixins/validatable-http-message-test.js

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -198,39 +198,6 @@ describe('Http validatable mixin', () => {
198198
});
199199
});
200200

201-
describe('#isValid()', () => {
202-
before(() => {
203-
instance = new HttpResponse(response);
204-
sinon.spy(instance, 'validate');
205-
});
206-
describe('validation property is empty', () => {
207-
it('should perform validation', () => {
208-
instance.isValid();
209-
assert.isTrue(instance.validate.called);
210-
});
211-
});
212-
213-
it('should return boolean', () => {
214-
assert.isBoolean(instance.isValid());
215-
});
216-
217-
describe('when any HTTP component contains error message', () => {
218-
let instance = null;
219-
before(() => {
220-
instance = new HttpResponse({});
221-
instance.validation = {
222-
headers: {
223-
results: [{ severity: 'error' }]
224-
}
225-
};
226-
});
227-
228-
it('should return false', () => {
229-
assert.isFalse(instance.isValid());
230-
});
231-
});
232-
});
233-
234201
describe('#validationResults()', () => {
235202
describe('when HTTP message validation property is empty', () => {
236203
before(() => {
@@ -1415,6 +1382,9 @@ Unexpected token '\\'' at 1:22
14151382
});
14161383

14171384
it('should return false boolean result', () => {
1385+
// TODO Remove/rewrite this.
1386+
// I am not sure what exactly is being asserted.
1387+
// There is a high chance this entire functionality has been deprecated.
14181388
assert.isFalse(instance.isValid());
14191389
});
14201390

test/unit/validate-test.js

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { assert } = require('chai');
22
const clone = require('clone');
3-
const { validate, isValid } = require('../../lib/gavel');
3+
const { validate } = require('../../lib/gavel');
44

55
describe('Gavel proxies to functions with callbacks', () => {
66
// Examples from README.md
@@ -42,81 +42,6 @@ describe('Gavel proxies to functions with callbacks', () => {
4242
body: '{"origin":"1.2.3.4"}'
4343
};
4444

45-
describe('isValid', () => {
46-
describe('when I provide data', () => {
47-
['response', 'request'].forEach((variant) => {
48-
describe(`for two cloned ${variant}s`, () => {
49-
let results = null;
50-
let error = null;
51-
52-
before((done) => {
53-
isValid(
54-
cloneHttpMessage,
55-
baseHttpMessage,
56-
variant,
57-
(err, result) => {
58-
error = err;
59-
results = result;
60-
done();
61-
}
62-
);
63-
});
64-
65-
it('should call the callback without any errors', () =>
66-
assert.isNull(error));
67-
it('should be true as a result of isValid', () =>
68-
assert.isTrue(results));
69-
});
70-
71-
describe(`for similar ${variant}s`, () => {
72-
let results = null;
73-
let error = null;
74-
75-
before((done) => {
76-
isValid(
77-
similarHttpMessage,
78-
baseHttpMessage,
79-
variant,
80-
(err, result) => {
81-
error = err;
82-
results = result;
83-
done();
84-
}
85-
);
86-
});
87-
88-
it('should call the callback without any errors', () =>
89-
assert.isNull(error));
90-
it('should be ok as a result of isValid', () =>
91-
assert.isTrue(results));
92-
});
93-
94-
describe(`for different ${variant}s`, () => {
95-
let results = null;
96-
let error = null;
97-
98-
before((done) => {
99-
isValid(
100-
differentHttpMessage,
101-
baseHttpMessage,
102-
variant,
103-
(err, result) => {
104-
error = err;
105-
results = result;
106-
done();
107-
}
108-
);
109-
});
110-
111-
it('should call the callback without any errors', () =>
112-
assert.isNull(error));
113-
it('should be false as a result of isValid', () =>
114-
assert.isFalse(results));
115-
});
116-
});
117-
});
118-
});
119-
12045
describe('validate', () => {
12146
describe('when I provide data', () => {
12247
['response', 'request'].forEach((variant) => {

0 commit comments

Comments
 (0)