2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const should = require('chai').should()
|
|
|
|
const { assert } = require('chai')
|
|
|
|
const async = require('async')
|
|
|
|
const request = require('./helpers/request')
|
|
|
|
const MockV1Api = require('./helpers/MockV1Api')
|
|
|
|
|
|
|
|
const assertResponse = (path, expectedStatusCode, expectedBody, cb) =>
|
2019-08-07 10:04:04 -04:00
|
|
|
request.get(path, (error, response) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
should.not.exist(error)
|
|
|
|
response.statusCode.should.equal(expectedStatusCode)
|
|
|
|
if (expectedBody) {
|
|
|
|
assert.deepEqual(JSON.parse(response.body), expectedBody)
|
|
|
|
}
|
|
|
|
return cb()
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('ProxyUrls', function() {
|
2019-08-06 08:20:31 -04:00
|
|
|
beforeEach(function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
return this.timeout(1000)
|
|
|
|
})
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
it('proxy static URLs', function(done) {
|
|
|
|
return async.series(
|
2019-05-29 05:21:06 -04:00
|
|
|
[
|
|
|
|
cb => assertResponse('/institutions/list', 200, [], cb),
|
|
|
|
cb => assertResponse('/institutions/domains', 200, [], cb)
|
|
|
|
],
|
|
|
|
done
|
2019-08-07 10:04:04 -04:00
|
|
|
)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
it('proxy dynamic URLs', function(done) {
|
|
|
|
return async.series(
|
2019-05-29 05:21:06 -04:00
|
|
|
[
|
|
|
|
cb =>
|
|
|
|
assertResponse(
|
|
|
|
'/institutions/list/123',
|
|
|
|
200,
|
|
|
|
{ id: 123, name: 'Institution 123' },
|
|
|
|
cb
|
|
|
|
),
|
|
|
|
cb =>
|
|
|
|
assertResponse(
|
|
|
|
'/institutions/list/456',
|
|
|
|
200,
|
|
|
|
{ id: 456, name: 'Institution 456' },
|
|
|
|
cb
|
|
|
|
)
|
|
|
|
],
|
|
|
|
done
|
2019-08-07 10:04:04 -04:00
|
|
|
)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
it('return 404 if proxy is not set', function(done) {
|
|
|
|
return async.series(
|
2019-05-29 05:21:06 -04:00
|
|
|
[cb => assertResponse('/institutions/foobar', 404, null, cb)],
|
|
|
|
done
|
2019-08-07 10:04:04 -04:00
|
|
|
)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
it('handle missing baseUrl', function(done) {
|
|
|
|
return async.series(
|
2019-05-29 05:21:06 -04:00
|
|
|
[cb => assertResponse('/proxy/missing/baseUrl', 500, null, cb)],
|
|
|
|
done
|
2019-08-07 10:04:04 -04:00
|
|
|
)
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|