ProxyUrls.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 MockV1Api = require('./helpers/MockV1Api')
  17. const assertResponse = (path, expectedStatusCode, expectedBody, cb) =>
  18. request.get(path, (error, response) => {
  19. should.not.exist(error)
  20. response.statusCode.should.equal(expectedStatusCode)
  21. if (expectedBody) {
  22. assert.deepEqual(JSON.parse(response.body), expectedBody)
  23. }
  24. return cb()
  25. })
  26. describe('ProxyUrls', function() {
  27. beforeEach(function() {
  28. return this.timeout(1000)
  29. })
  30. it('proxy static URLs', function(done) {
  31. return async.series(
  32. [
  33. cb => assertResponse('/institutions/list', 200, [], cb),
  34. cb => assertResponse('/institutions/domains', 200, [], cb)
  35. ],
  36. done
  37. )
  38. })
  39. it('proxy dynamic URLs', function(done) {
  40. return async.series(
  41. [
  42. cb =>
  43. assertResponse(
  44. '/institutions/list/123',
  45. 200,
  46. { id: 123, name: 'Institution 123' },
  47. cb
  48. ),
  49. cb =>
  50. assertResponse(
  51. '/institutions/list/456',
  52. 200,
  53. { id: 456, name: 'Institution 456' },
  54. cb
  55. )
  56. ],
  57. done
  58. )
  59. })
  60. it('return 404 if proxy is not set', function(done) {
  61. return async.series(
  62. [cb => assertResponse('/institutions/foobar', 404, null, cb)],
  63. done
  64. )
  65. })
  66. it('handle missing baseUrl', function(done) {
  67. return async.series(
  68. [cb => assertResponse('/proxy/missing/baseUrl', 500, null, cb)],
  69. done
  70. )
  71. })
  72. })