diff --git a/src/util/api.js b/src/util/api.js index 7b1b44f8..5870908b 100644 --- a/src/util/api.js +++ b/src/util/api.js @@ -16,64 +16,10 @@ const dimensionEndpoints = { sexCode: 'sex_code', } -const stateCodes = { - alabama: 2, - alaska: 1, - arizona: 5, - arkansas: 3, - california: 6, - colorado: 7, - connecticut: 8, - delaware: 11, - 'district-of-columbia': 10, - florida: 12, - georgia: 13, - hawaii: 15, - idaho: 17, - illinois: 18, - indiana: 19, - iowa: 16, - kansas: 20, - kentucky: 21, - louisiana: 22, - maine: 25, - maryland: 24, - massachusetts: 23, - michigan: 26, - minnesota: 27, - mississippi: 29, - missouri: 28, - montana: 30, - nebraska: 31, - 'new-hampshire': 34, - 'new-jersey': 35, - 'new-mexico': 36, - 'new-york': 38, - nevada: 37, - 'north-carolina': 32, - 'north-dakota': 33, - ohio: 39, - oklahoma: 40, - oregon: 41, - pennsylvania: 42, - 'rhode-island': 44, - 'south-carolina': 45, - 'south-dakota': 46, - tennessee: 47, - texas: 48, - utah: 49, - vermont: 52, - virginia: 51, - washington: 53, - wisconsin: 54, - 'west-virginia': 55, - wyoming: 56, -} - const getNibrs = ({ crime, dim, place, type }) => { const field = dimensionEndpoints[dim] const fieldPath = `${field}/offenses` - const loc = (place === nationalKey) ? 'national' : `states/${stateCodes[place]}` + const loc = (place === nationalKey) ? 'national' : `states/${lookupUsa(place).toUpperCase()}` const url = `${API}/${type}s/count/${loc}/${fieldPath}` const params = { diff --git a/test/util/api.test.js b/test/util/api.test.js index 6e0a9060..19cac6e6 100644 --- a/test/util/api.test.js +++ b/test/util/api.test.js @@ -38,12 +38,12 @@ describe('api utility', () => { }) describe('getNibrs()', () => { - it('should call the /offenders/count/states/:id/:dim/offenses endpoint', done => { + it('should call the /offenders/count/states/:postal_abbr/:dim/offenses endpoint', done => { const spy = sandbox.stub(http, 'get', () => createPromise(success)) const args = { ...params, type: 'offender', dim: 'sexCode' } api.getNibrs(args).then(() => { const spyArgs = spy.args[0] - const expectedUrl = '/api/offenders/count/states/6/sex_code/offenses' + const expectedUrl = '/api/offenders/count/states/CA/sex_code/offenses' expect(spyArgs[0]).toEqual(expectedUrl) expect(spyArgs[1].explorer_offense).toEqual(params.crime) done()