Skip to content

Commit

Permalink
Fix caselist loading when not running on ES (#821)
Browse files Browse the repository at this point in the history
* Fix proxying of calls to /aggregated/.../cases

This fixes loading of the case list when not running on Elastic Search.

This change avoids returning jurisdicitonal details instead of case
data.

* whitespace fix

* add additional spec for non jurisdiction url

* fix typo
  • Loading branch information
banderous authored Feb 5, 2021
1 parent 2ee3f44 commit 93ac337
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
32 changes: 28 additions & 4 deletions api/amendedJurisdictions/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,36 @@ describe('Amended Jurisdiction', () => {
sandbox.restore()
})

it('should send PROBATE array', () => {
it('should filter jurisdictions for the jurisdictions endpoint', () => {
const data = [
{
id: 'PROBATE',
},
{
id: 'RANDOM',
},
]
req.url = 'aggregated/caseworkers/:uid/jurisdictions?access=read'
const response = amendedJurisdictions.getJurisdictions(proxyRes, req, res, data)
// Unknown jurisdiction should be filtered
const expected = [
{
id: 'PROBATE',
},
{
id: 'PROBATE',
},
]
expect(response).to.eql(expected)
})

it('should not filter jurisdictions for non-jurisdictions endpoint', () => {
const expected = [
{
id: 'PROBATE',
},
{
id: 'RANDOM',
},
]
req.url = '/aggregated/some/other/url'

const response = amendedJurisdictions.getJurisdictions(proxyRes, req, res, expected)
expect(response).to.eql(expected)
Expand Down
13 changes: 9 additions & 4 deletions api/amendedJurisdictions/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {getConfigValue} from '../configuration'
import { JURISDICTIONS } from '../configuration/references'

const jurisdictions = /aggregated\/.+jurisdictions\?/

/**
* Manually filtering returned jurisdictions
* to make available jurisdiction in filters array only
*/
export const getJurisdictions = (proxyRes, req, res, data: any[]) => {
if (!Array.isArray(data)) {
if (!Array.isArray(data)
|| !jurisdictions.test(req.url)) {
return data
}
const filters = getConfigValue(JURISDICTIONS)
Expand All @@ -15,8 +18,10 @@ export const getJurisdictions = (proxyRes, req, res, data: any[]) => {
}

export const checkCachedJurisdictions = (proxyReq, req, res) => {
if (req.session.jurisdictions) {
res.send(req.session.jurisdictions)
proxyReq.end()
if (jurisdictions.test(req.url)) {
if (req.session.jurisdictions) {
res.send(req.session.jurisdictions)
proxyReq.end()
}
}
}

0 comments on commit 93ac337

Please sign in to comment.