ProxyUrls.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* eslint-disable
  2. max-len,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const should = require('chai').should()
  13. const { assert } = require('chai')
  14. const async = require('async')
  15. const request = require('./helpers/request')
  16. const assertResponse = (path, expectedStatusCode, expectedBody, cb) =>
  17. request.get(path, (error, response) => {
  18. should.not.exist(error)
  19. response.statusCode.should.equal(expectedStatusCode)
  20. if (expectedBody) {
  21. assert.deepEqual(JSON.parse(response.body), expectedBody)
  22. }
  23. return cb()
  24. })
  25. describe('ProxyUrls', function() {
  26. beforeEach(function() {
  27. return this.timeout(1000)
  28. })
  29. it('proxy static URLs', function(done) {
  30. return async.series(
  31. [
  32. cb => assertResponse('/institutions/list', 200, [], cb),
  33. cb => assertResponse('/institutions/domains', 200, [], cb)
  34. ],
  35. done
  36. )
  37. })
  38. it('proxy dynamic URLs', function(done) {
  39. return async.series(
  40. [
  41. cb =>
  42. assertResponse(
  43. '/institutions/list/123',
  44. 200,
  45. { id: 123, name: 'Institution 123' },
  46. cb
  47. ),
  48. cb =>
  49. assertResponse(
  50. '/institutions/list/456',
  51. 200,
  52. { id: 456, name: 'Institution 456' },
  53. cb
  54. )
  55. ],
  56. done
  57. )
  58. })
  59. it('return 404 if proxy is not set', function(done) {
  60. return async.series(
  61. [cb => assertResponse('/institutions/foobar', 404, null, cb)],
  62. done
  63. )
  64. })
  65. it('handle missing baseUrl', function(done) {
  66. return async.series(
  67. [cb => assertResponse('/proxy/missing/baseUrl', 500, null, cb)],
  68. done
  69. )
  70. })
  71. })