Skip to content

Commit

Permalink
Merge pull request #685 from ministryofjustice/p4-1911-update-fe-to-u…
Browse files Browse the repository at this point in the history
…se-splatted-properties-on-person-object-rather-than-jsonb

chore: Support v1 and v2 person differences
  • Loading branch information
solidgoldpig authored Jul 21, 2020
2 parents c8b5042 + d5bc697 commit 5577201
Show file tree
Hide file tree
Showing 9 changed files with 960 additions and 291 deletions.
3 changes: 3 additions & 0 deletions common/lib/api-client/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ module.exports = {
jsonApi: 'hasOne',
type: 'ethnicities',
},
prison_number: '',
criminal_records_office: '',
police_national_computer: '',
profiles: {
jsonApi: 'hasMany',
type: 'profiles',
Expand Down
18 changes: 17 additions & 1 deletion common/presenters/person-to-summary-list-component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { API } = require('../../config')
const i18n = require('../../config/i18n')
const filters = require('../../config/nunjucks/filters')

// TODO: when V2, props will be splatted and no need for identifier_type prop
function mapIdentifier({ value, identifier_type: type }) {
return {
key: {
Expand All @@ -20,7 +22,6 @@ module.exports = function personToSummaryListComponent(props) {
const {
gender,
ethnicity,
identifiers = [],
date_of_birth: dateOfBirth,
gender_additional_information: genderAdditionalInformation,
} = props
Expand All @@ -29,6 +30,21 @@ module.exports = function personToSummaryListComponent(props) {
? ` — ${genderAdditionalInformation}`
: ''

let { identifiers = [] } = props

if (API.VERSION !== 1) {
identifiers = [
'police_national_computer',
'prison_number',
'criminal_records_office',
]
.filter(identifier => props[identifier])
.map(identifier => ({
value: props[identifier],
identifier_type: identifier,
}))
}

const rows = [
...identifiers.map(mapIdentifier),
{
Expand Down
62 changes: 42 additions & 20 deletions common/presenters/person-to-summary-list-component.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { API } = require('../../config')
const i18n = require('../../config/i18n')
const filters = require('../../config/nunjucks/filters')

Expand All @@ -7,7 +8,19 @@ const mockPerson = {
id: '12345',
date_of_birth: '1948-04-24',
gender_additional_information: 'Additional gender information',
identifiers: [
police_national_computer: '11009922',
prison_number: 'AA/183716',
criminal_records_office: 'JS901873',
ethnicity: {
title: 'Mixed (White and Black Caribbean)',
},
gender: {
title: 'Transexual',
},
}

if (API.VERSION === 1) {
mockPerson.identifiers = [
{
identifier_type: 'police_national_computer',
value: '11009922',
Expand All @@ -20,13 +33,7 @@ const mockPerson = {
identifier_type: 'criminal_records_office',
value: 'JS901873',
},
],
ethnicity: {
title: 'Mixed (White and Black Caribbean)',
},
gender: {
title: 'Transexual',
},
]
}

describe('Presenters', function () {
Expand Down Expand Up @@ -55,18 +62,33 @@ describe('Presenters', function () {
const row2 = transformedResponse.rows[1]
const row3 = transformedResponse.rows[2]

expect(row1).to.deep.equal({
key: { html: '__translated__' },
value: { text: mockPerson.identifiers[0].value },
})
expect(row2).to.deep.equal({
key: { html: '__translated__' },
value: { text: mockPerson.identifiers[1].value },
})
expect(row3).to.deep.equal({
key: { html: '__translated__' },
value: { text: mockPerson.identifiers[2].value },
})
if (API.VERSION === 1) {
expect(row1).to.deep.equal({
key: { html: '__translated__' },
value: { text: mockPerson.identifiers[0].value },
})
expect(row2).to.deep.equal({
key: { html: '__translated__' },
value: { text: mockPerson.identifiers[1].value },
})
expect(row3).to.deep.equal({
key: { html: '__translated__' },
value: { text: mockPerson.identifiers[2].value },
})
} else {
expect(row1).to.deep.equal({
key: { html: '__translated__' },
value: { text: mockPerson.police_national_computer },
})
expect(row2).to.deep.equal({
key: { html: '__translated__' },
value: { text: mockPerson.prison_number },
})
expect(row3).to.deep.equal({
key: { html: '__translated__' },
value: { text: mockPerson.criminal_records_office },
})
}
})

it('should contain date of birth', function () {
Expand Down
6 changes: 5 additions & 1 deletion common/services/person.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const { mapKeys, mapValues, uniqBy, omitBy, isNil } = require('lodash')

const { API } = require('../../config')
const apiClient = require('../lib/api-client')()

const unformat = require('./person/person.unformat')

const relationshipKeys = ['gender', 'ethnicity']
const identifierKeys = [

const identifierKeysV1 = [
'police_national_computer',
'criminal_records_office',
'prison_number',
'niche_reference',
'athena_reference',
]

const identifierKeys = API.VERSION === 1 ? identifierKeysV1 : []
const dateKeys = ['date_of_birth']

const personService = {
Expand Down
Loading

0 comments on commit 5577201

Please sign in to comment.