-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const { assert } = require('chai'); | ||
const validateRequest = require('../../validateRequest'); | ||
const validateElement = require('../../validateElement'); | ||
|
||
describe('validateRequest', () => { | ||
describe('validateElement', () => { | ||
describe('with matching requests', () => { | ||
const request = { | ||
method: 'POST', | ||
|
@@ -10,7 +10,7 @@ describe('validateRequest', () => { | |
}, | ||
body: '{ "foo": "bar" }' | ||
}; | ||
const res = validateRequest(request, request); | ||
const res = validateElement(request, request); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
artem-zakharchenko
Author
Contributor
|
||
|
||
it('returns validation result object', () => { | ||
assert.isObject(res); | ||
|
@@ -66,7 +66,7 @@ describe('validateRequest', () => { | |
}); | ||
|
||
describe('with non-matching requests', () => { | ||
const res = validateRequest( | ||
const res = validateElement( | ||
{ | ||
method: 'POST', | ||
headers: { | ||
|
@@ -86,14 +86,17 @@ describe('validateRequest', () => { | |
}); | ||
|
||
it('contains all validatable keys', () => { | ||
assert.hasAllKeys(res, ['headers', 'body']); | ||
// Note that "headers" are not present because | ||
// Gavel demands a validatable key to be present | ||
// in both real and expected elements. | ||
assert.hasAllKeys(res, ['body']); | ||
}); | ||
|
||
describe('method', () => { | ||
it.skip('compares methods'); | ||
}); | ||
|
||
describe('headers', () => { | ||
describe.skip('headers', () => { | ||
it('has no validator set', () => { | ||
assert.propertyVal(res.headers, 'validator', null); | ||
}); | ||
|
@@ -165,4 +168,8 @@ and expected data media type | |
}); | ||
}); | ||
}); | ||
|
||
describe('with matching responses', () => { | ||
it.skip('add'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const normalize = require('./units/normalize'); | ||
const validateElement = require('./validateElement'); | ||
|
||
function validate(real, expected, type, callback) { | ||
const normalizedReal = normalize(real); | ||
const normalizedExpected = normalize(expected); | ||
|
||
if (type !== 'request' && type !== 'response') { | ||
throw new Error( | ||
`Can't validate: expected transaction "type" to be "request" or "response", but got: ${type}.` | ||
); | ||
} | ||
|
||
const results = validateElement(normalizedReal, normalizedExpected); | ||
|
||
// TODO Propagate the error. | ||
callback(null, { | ||
version: '2', | ||
...results | ||
}); | ||
} | ||
|
||
module.exports = validate; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const isset = require('../utils/isset'); | ||
const validateStatusCode = require('./units/validateStatusCode'); | ||
const validateHeaders = require('./units/validateHeaders'); | ||
const { validateBody } = require('./units/validateBody'); | ||
|
||
function validateElement(real, expected) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
honzajavorek
Contributor
|
||
const results = {}; | ||
|
||
if (real.statusCode) { | ||
results.statusCode = validateStatusCode(real, expected); | ||
} | ||
|
||
if (real.headers && expected.headers) { | ||
results.headers = validateHeaders(real, expected); | ||
} | ||
|
||
if ( | ||
isset(real.body) && | ||
This comment has been minimized.
Sorry, something went wrong.
honzajavorek
Contributor
|
||
(isset(expected.body) || isset(expected.bodySchema)) | ||
) { | ||
results.body = validateBody(real, expected); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
module.exports = validateElement; |
This file was deleted.
What is Element in this context? If you're looking for a name for "either HTTP request or HTTP response", then it's "HTTP message"