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

Commit 4a4e9a3

Browse files
feat: removes "type" parameter from "validate" call signature
BREAKING CHANGE: Calling "gavel.validate" no longer requires the "type" parameter.
1 parent 969ab5a commit 4a4e9a3

File tree

4 files changed

+23
-51
lines changed

4 files changed

+23
-51
lines changed

bin/gavel

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,19 @@ process.stdin.on('end', function() {
2424

2525
var realHttp = curlParser.parseBack(stdin);
2626

27-
var realRequest = httpParser.parseRequest(realHttp['request']);
28-
var realResponse = httpParser.parseResponse(realHttp['response']);
27+
var realRequest = httpParser.parseRequest(realHttp.request);
28+
var realResponse = httpParser.parseResponse(realHttp.response);
2929

30-
var expectedRequest = httpParser.parseRequest(expectedHttp['request']);
31-
var expectedResponse = httpParser.parseResponse(expectedHttp['response']);
30+
var expectedRequest = httpParser.parseRequest(expectedHttp.request);
31+
var expectedResponse = httpParser.parseResponse(expectedHttp.response);
3232

3333
var requestResult = false;
3434
var responseResult = false;
3535

36-
gavel.validate(realRequest, expectedRequest, 'request', function(
37-
err,
38-
result
39-
) {
36+
gavel.validate(realRequest, expectedRequest, function(err, result) {
4037
requestResult = result;
4138

42-
gavel.validate(realResponse, expectedResponse, 'response', function(
43-
err,
44-
result
45-
) {
39+
gavel.validate(realResponse, expectedResponse, function(err, result) {
4640
responseResult = result;
4741
});
4842
});

lib/next/validate.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,9 @@ const { validateMessage } = require('./validateMessage');
55
* a legacy-compliant validation results.
66
* @param {Object} real
77
* @param {Object} expected
8-
* @param {'request'|'response'} type
98
* @param {(error: Error, result: Object) => void} callback
109
*/
11-
function validate(real, expected, type, callback) {
12-
if (type !== 'request' && type !== 'response') {
13-
throw new Error(
14-
`Can't validate: expected transaction "type" to be "request" or "response", but got: ${type}.`
15-
);
16-
}
17-
10+
function validate(real, expected, callback) {
1811
let results;
1912

2013
try {

test/cucumber/support/world.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class World {
109109
}
110110

111111
validate(callback) {
112-
return gavel.validate(this.real, this.expected, 'response', callback);
112+
return gavel.validate(this.real, this.expected, callback);
113113
}
114114

115115
parseHeaders(headersString) {

test/unit/validate-test.js

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,11 @@ describe('Gavel proxies to functions with callbacks', () => {
5050
let error = null;
5151

5252
before((done) => {
53-
validate(
54-
cloneHttpMessage,
55-
baseHttpMessage,
56-
variant,
57-
(err, result) => {
58-
error = err;
59-
results = result;
60-
done();
61-
}
62-
);
53+
validate(cloneHttpMessage, baseHttpMessage, (err, result) => {
54+
error = err;
55+
results = result;
56+
done();
57+
});
6358
});
6459

6560
it('should call the callback without any errors', () =>
@@ -72,16 +67,11 @@ describe('Gavel proxies to functions with callbacks', () => {
7267
let error = null;
7368

7469
before((done) => {
75-
validate(
76-
similarHttpMessage,
77-
baseHttpMessage,
78-
variant,
79-
(err, result) => {
80-
error = err;
81-
results = result;
82-
done();
83-
}
84-
);
70+
validate(similarHttpMessage, baseHttpMessage, (err, result) => {
71+
error = err;
72+
results = result;
73+
done();
74+
});
8575
});
8676

8777
it('should call the callback without any errors', () =>
@@ -94,16 +84,11 @@ describe('Gavel proxies to functions with callbacks', () => {
9484
let error = null;
9585

9686
before((done) => {
97-
validate(
98-
differentHttpMessage,
99-
baseHttpMessage,
100-
variant,
101-
(err, result) => {
102-
error = err;
103-
results = result;
104-
done();
105-
}
106-
);
87+
validate(differentHttpMessage, baseHttpMessage, (err, result) => {
88+
error = err;
89+
results = result;
90+
done();
91+
});
10792
});
10893

10994
it('should call the callback without any errors', () =>

0 commit comments

Comments
 (0)