Skip to content

Instantly share code, notes, and snippets.

@fivetanley
Last active May 2, 2018 17:37
Show Gist options
  • Save fivetanley/c4fb1a837af9febf19b7cb57e72e8df9 to your computer and use it in GitHub Desktop.
Save fivetanley/c4fb1a837af9febf19b7cb57e72e8df9 to your computer and use it in GitHub Desktop.
// vget: like `get` but ensures the response body matches the schema for an endpoint. e.g. `validated get`
this.vget = (path, callback) => {
this.get(path, (schema, request) => {
request.__validationPath__ = `/${path}`;
return Promise.resolve().then(async () => {
await ensureSchemaLoaded(request.requestHeaders.Accept);
return callback.call(this, schema, request);
});
});
};
const _handledRequest = this.pretender.handledRequest;
this.pretender.handledRequest = (verb, path, request) => {
_handledRequest.call(this.pretender, verb, path, request);
if (request.__validationPath__) {
try {
validateRequest(request.__validationPath__, request.requestHeaders.Accept, JSON.parse(request.responseText));
} catch(e) {
mocha.throwError(e);
}
}
};
// dashboard.heroku.com itself (or whatever origin your app is on)
this.get('/latest-version', () => config.APP_VERSION);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment