Last active
May 2, 2018 17:37
-
-
Save fivetanley/c4fb1a837af9febf19b7cb57e72e8df9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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