Skip to content

Commit

Permalink
Add basic NIBRS util tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremia Kimelman committed Mar 3, 2017
1 parent 02ff340 commit 75d46ae
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
34 changes: 34 additions & 0 deletions test/fixtures/nibrsApiResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"offenderSexCode": [
{"count":5,"offense_name":"homicide","sex_code":"M","year":"2006"},
{"count":3,"offense_name":"homicide","sex_code":"M","year":"2008"}
],
"offenderRaceCode":[
{"count":5,"offense_name":"homicide","race_code":"B","year":"2006"},
{"count":2,"offense_name":"homicide","race_code":"B","year":"2008"}
],
"offenderAgeNum":[
{"age_num":20,"count":4,"offense_name":"homicide","year":"2006"},
{"age_num":30,"count":1,"offense_name":"homicide","year":"2006"}
],
"victimSexCode": [
{"count":5,"offense_name":"homicide","sex_code":"M","year":"2006"},
{"count":3,"offense_name":"homicide","sex_code":"M","year":"2008"}
],
"victimRaceCode":[
{"count":5,"offense_name":"homicide","race_code":"B","year":"2006"},
{"count":2,"offense_name":"homicide","race_code":"B","year":"2008"}
],
"victimAgeNum":[
{"age_num":20,"count":4,"offense_name":"homicide","year":"2006"},
{"age_num":30,"count":1,"offense_name":"homicide","year":"2006"}
],
"victimRelationship":[
{"count":1,"offender_relationship":"Victim Was Acquaintance","offense_name":"homicide","year":"2006"},
{"count":2,"offender_relationship":"Victim Was Stranger","offense_name":"homicide","year":"2006"}
],
"offenseLocationName":[
{"count":1,"location_name":"Air/Bus/Train Terminal","year":"2006"},
{"count":1,"location_name":"Air/Bus/Train Terminal","year":"2011"}
]
}
17 changes: 16 additions & 1 deletion test/util/nibrs.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint no-undef: 0 */

import { reshape, rename } from '../../src/util/nibrs'
import parseNibrs, { reshape, rename } from '../../src/util/nibrs'

import mockApiData from '../fixtures/nibrsApiResponse.json'

describe('nibrs utility', () => {
describe('reshape()', () => {
Expand Down Expand Up @@ -30,4 +32,17 @@ describe('nibrs utility', () => {
])
})
})

describe('parseNibrs()', () => {
// TODO: add more robust tests of this function, as right now it just checks
// for the titles of the sections and not the shape of the data
it('should parse the data into an array with the proper titles', () => {
const actual = parseNibrs(mockApiData)
expect(actual.length).toEqual(4)
expect(actual[0].title.toLowerCase()).toEqual('offender demographics')
expect(actual[1].title.toLowerCase()).toEqual('victim demographics')
expect(actual[2].title.toLowerCase()).toEqual('victim’s relationship to the offender')
expect(actual[3].title.toLowerCase()).toEqual('location type')
})
})
})

0 comments on commit 75d46ae

Please sign in to comment.