Skip to content
This repository has been archived by the owner on Sep 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1778 from 18F/jf-3845-85-test-scenarios
Browse files Browse the repository at this point in the history
[EN-3845] Create SF85 test scenarios
  • Loading branch information
christopherhuii authored Aug 9, 2019
2 parents 6db9fa4 + b05b52e commit c3ab464
Show file tree
Hide file tree
Showing 14 changed files with 12,659 additions and 54 deletions.
Binary file added api/bin/sftype
Binary file not shown.
2,242 changes: 2,242 additions & 0 deletions api/testdata/complete-scenarios/SF85/test1.json

Large diffs are not rendered by default.

5,555 changes: 5,555 additions & 0 deletions api/testdata/complete-scenarios/SF85/test2.json

Large diffs are not rendered by default.

4,694 changes: 4,694 additions & 0 deletions api/testdata/complete-scenarios/SF85/test3.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/models/__tests__/drugUse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,11 @@ describe('The drugUse model', () => {
const testData = {}
const expectedErrors = [
'UseInFuture.presence.REQUIRED',
'Explanation.presence.REQUIRED',
]

expect(validateModel(testData, drugUse, { requireUseInFuture: false }))
.not.toEqual(expect.arrayContaining(expectedErrors))
.toEqual(expect.not.arrayContaining(expectedErrors))
})

it('passes a valid drugUse', () => {
Expand All @@ -220,7 +221,6 @@ describe('The drugUse model', () => {
NatureOfUse: { value: 'Testing' },
UseWithClearance: { value: 'No' },
UseWhileEmployed: { value: 'Yes' },
Explanation: { value: 'testing' },
}

expect(validateModel(testData, drugUse, { requireUseInFuture: false }))
Expand Down
15 changes: 11 additions & 4 deletions src/models/__tests__/offense.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,29 @@ describe('The offense model', () => {
})

it('the InvolvedViolence field must have a valid value', () => {
const options = { requireLegalOffenseInvolvements: true }
const testData = { InvolvedViolence: { value: 'true' } }
const expectedErrors = ['InvolvedViolence.hasValue.value.inclusion.INCLUSION']

expect(validateModel(testData, offense))
expect(validateModel(testData, offense, options))
.toEqual(expect.arrayContaining(expectedErrors))
})

it('the InvolvedFirearms field must have a valid value', () => {
const options = { requireLegalOffenseInvolvements: true }
const testData = { InvolvedFirearms: { value: 'false' } }
const expectedErrors = ['InvolvedFirearms.hasValue.value.inclusion.INCLUSION']

expect(validateModel(testData, offense))
expect(validateModel(testData, offense, options))
.toEqual(expect.arrayContaining(expectedErrors))
})

it('the InvolvedSubstances field must have a valid value', () => {
const options = { requireLegalOffenseInvolvements: true }
const testData = { InvolvedSubstances: { value: 100 } }
const expectedErrors = ['InvolvedSubstances.hasValue.value.inclusion.INCLUSION']

expect(validateModel(testData, offense))
expect(validateModel(testData, offense, options))
.toEqual(expect.arrayContaining(expectedErrors))
})

Expand Down Expand Up @@ -391,6 +394,10 @@ describe('The offense model', () => {
})

it('the Sentence field must be a valid Sentence', () => {
const options = {
requireLegalOffenseSentenced: true,
requireLegalOffenseIncarcerated: true,
}
const testData = {
WasCharged: { value: 'Yes' },
WasSentenced: { value: 'Yes' },
Expand All @@ -410,7 +417,7 @@ describe('The offense model', () => {
'Sentence.model.ProbationDates.presence.REQUIRED',
]

expect(validateModel(testData, offense))
expect(validateModel(testData, offense, options))
.toEqual(expect.arrayContaining(expectedErrors))
})

Expand Down
6 changes: 5 additions & 1 deletion src/models/__tests__/otherOffense.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ describe('The offense model', () => {
})

it('the Sentence field must be a valid Sentence', () => {
const options = {
requireLegalOffenseSentenced: true,
requireLegalOffenseIncarcerated: true,
}
const testData = {
WasSentenced: { value: 'Yes' },
Sentence: {
Expand All @@ -251,7 +255,7 @@ describe('The offense model', () => {
'Sentence.model.ProbationDates.presence.REQUIRED',
]

expect(validateModel(testData, offense))
expect(validateModel(testData, offense, options))
.toEqual(expect.arrayContaining(expectedErrors))
})

Expand Down
5 changes: 4 additions & 1 deletion src/models/drugUse.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const drugUse = {
return { presence: true, date: { requireDay: false, ...dateLimits } }
},
NatureOfUse: { presence: true, hasValue: true },
Explanation: { presence: true, hasValue: true },
Explanation: (value, attributes, attributeName, options) => {
if (options && options.requireUseInFuture === false) return {}
return { presence: true, hasValue: true }
},
UseWhileEmployed: (value, attributes, attributeName, options) => {
if (options && options.requireUseWhileEmployed === false) return {}
return { presence: true, hasValue: { validator: hasYesOrNo } }
Expand Down
33 changes: 24 additions & 9 deletions src/models/offense.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,32 @@ import { offenseChargeTypes } from 'constants/enums/legalOptions'
const offense = {
Date: { presence: true, date: true },
Description: { presence: true, hasValue: true },
InvolvedViolence: {
presence: true,
hasValue: { validator: hasYesOrNo },
InvolvedViolence: (value, attributes, attributeName, options) => {
if (options.requireLegalOffenseInvolvements) {
return {
presence: true,
hasValue: { validator: hasYesOrNo },
}
}
return {}
},
InvolvedFirearms: {
presence: true,
hasValue: { validator: hasYesOrNo },
InvolvedFirearms: (value, attributes, attributeName, options) => {
if (options.requireLegalOffenseInvolvements) {
return {
presence: true,
hasValue: { validator: hasYesOrNo },
}
}
return {}
},
InvolvedSubstances: {
presence: true,
hasValue: { validator: hasYesOrNo },
InvolvedSubstances: (value, attributes, attributeName, options) => {
if (options.requireLegalOffenseInvolvements) {
return {
presence: true,
hasValue: { validator: hasYesOrNo },
}
}
return {}
},
Address: {
presence: true,
Expand Down
28 changes: 26 additions & 2 deletions src/models/shared/__tests__/sentence.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ describe('The sentence model', () => {
})

it('the ExceedsYear field must have a valid value', () => {
const options = { requireLegalOffenseSentenced: true }
const testData = { ExceedsYear: { value: 'true' } }
const expectedErrors = ['ExceedsYear.hasValue.value.inclusion.INCLUSION']

expect(validateModel(testData, sentence))
expect(validateModel(testData, sentence, options))
.toEqual(expect.arrayContaining(expectedErrors))
})

it('the Incarcerated field must have a valid value', () => {
const options = { requireLegalOffenseIncarcerated: true }
const testData = { Incarcerated: { value: 'false' } }
const expectedErrors = ['Incarcerated.hasValue.value.inclusion.INCLUSION']

expect(validateModel(testData, sentence))
expect(validateModel(testData, sentence, options))
.toEqual(expect.arrayContaining(expectedErrors))
})

Expand Down Expand Up @@ -220,4 +222,26 @@ describe('The sentence model', () => {
expect(validateModel(testData, sentence)).toEqual(true)
})
})

describe('requireLegalOffenseSentenced is false', () => {
it('the ExceedsYear is not required', () => {
const options = { requireLegalOffenseSentenced: false }
const testData = { ExceedsYear: { value: 'true' } }
const expectedErrors = ['ExceedsYear.hasValue.value.inclusion.INCLUSION']

expect(validateModel(testData, sentence, options))
.toEqual(expect.not.arrayContaining(expectedErrors))
})
})

describe('requireLegalOffenseIncarcerated is false', () => {
it('the Incarcerated field is not required', () => {
const options = { requireLegalOffenseIncarcerated: false }
const testData = { Incarcerated: { value: 'false' } }
const expectedErrors = ['Incarcerated.hasValue.value.inclusion.INCLUSION']

expect(validateModel(testData, sentence, options))
.toEqual(expect.not.arrayContaining(expectedErrors))
})
})
})
22 changes: 16 additions & 6 deletions src/models/shared/sentence.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ import { hasYesOrNo } from 'models/validate'

const sentence = {
Description: { presence: true, hasValue: true },
ExceedsYear: {
presence: true,
hasValue: { validator: hasYesOrNo },
ExceedsYear: (value, attributes, attributeName, options) => {
if (options.requireLegalOffenseSentenced) {
return {
presence: true,
hasValue: { validator: hasYesOrNo },
}
}
return {}
},
Incarcerated: {
presence: true,
hasValue: { validator: hasYesOrNo },
Incarcerated: (value, attributes, attributeName, options) => {
if (options.requireLegalOffenseIncarcerated) {
return {
presence: true,
hasValue: { validator: hasYesOrNo },
}
}
return {}
},
IncarcerationDates: (value, attributes) => {
if (attributes.IncarcerationDatesNA
Expand Down
61 changes: 40 additions & 21 deletions src/validators/offense.js
Original file line number Diff line number Diff line change
@@ -1,130 +1,149 @@
import store from 'services/store'
import { validateModel } from 'models/validate'
import offense from 'models/offense'
import {
requireLegalOffenseInvolvements,
requireLegalOffenseSentenced,
requireLegalOffenseIncarcerated,
} from 'helpers/branches'

export const validateOffense = data => validateModel(data, offense) === true
const options = formType => (
{
requireLegalOffenseInvolvements: requireLegalOffenseInvolvements(formType),
requireLegalOffenseSentenced: requireLegalOffenseSentenced(formType),
requireLegalOffenseIncarcerated: requireLegalOffenseIncarcerated(formType),
}
)

export const validateOffense = (data, formType) => (
validateModel(data, offense, options(formType)) === true
)

export default class OffenseValidator {
constructor(data = {}) {
const state = store.getState()
const { formType } = state.application.Settings
this.data = data
this.formType = formType
}

validDate() {
return validateModel(this.data, {
Date: offense.Date,
}) === true
}, options(this.formType)) === true
}

validDescription() {
return validateModel(this.data, {
Description: offense.Description,
}) === true
}, options(this.formType)) === true
}

validViolence() {
return validateModel(this.data, {
InvolvedViolence: offense.InvolvedViolence,
}) === true
}, options(this.formType)) === true
}

validFirearms() {
return validateModel(this.data, {
InvolvedFirearms: offense.InvolvedFirearms,
}) === true
}, options(this.formType)) === true
}

validSubstances() {
return validateModel(this.data, {
InvolvedSubstances: offense.InvolvedSubstances,
}) === true
}, options(this.formType)) === true
}

validAddress() {
return validateModel(this.data, {
Address: offense.Address,
}) === true
}, options(this.formType)) === true
}

validCited() {
return validateModel(this.data, {
WasCited: offense.WasCited,
}) === true
}, options(this.formType)) === true
}

validCitedBy() {
return validateModel(this.data, {
CitedBy: offense.CitedBy,
}) === true
}, options(this.formType)) === true
}

validAgencyAddress() {
return validateModel(this.data, {
AgencyAddress: offense.AgencyAddress,
}) === true
}, options(this.formType)) === true
}

validCharged() {
return validateModel(this.data, {
WasCharged: offense.WasCharged,
}) === true
}, options(this.formType)) === true
}

validExplanation() {
return validateModel(this.data, {
Explanation: offense.Explanation,
}) === true
}, options(this.formType)) === true
}

validCourtName() {
return validateModel(this.data, {
CourtName: offense.CourtName,
}) === true
}, options(this.formType)) === true
}

validCourtAddress() {
return validateModel(this.data, {
CourtAddress: offense.CourtAddress,
}) === true
}, options(this.formType)) === true
}

validChargeType() {
return validateModel(this.data, {
ChargeType: offense.ChargeType,
}) === true
}, options(this.formType)) === true
}

validCourtCharge() {
return validateModel(this.data, {
CourtCharge: offense.CourtCharge,
}) === true
}, options(this.formType)) === true
}

validCourtOutcome() {
return validateModel(this.data, {
CourtOutcome: offense.CourtOutcome,
}) === true
}, options(this.formType)) === true
}

validCourtDate() {
return validateModel(this.data, {
CourtDate: offense.CourtDate,
}) === true
}, options(this.formType)) === true
}

validSentenced() {
return validateModel(this.data, {
WasSentenced: offense.WasSentenced,
Sentence: offense.Sentence,
}) === true
}, options(this.formType)) === true
}

validAwaitingTrial() {
return validateModel(this.data, {
AwaitingTrial: offense.AwaitingTrial,
AwaitingTrialExplanation: offense.AwaitingTrialExplanation,
}) === true
}, options(this.formType)) === true
}

isValid() {
return validateOffense(this.data)
return validateOffense(this.data, this.formType)
}
}
Loading

0 comments on commit c3ab464

Please sign in to comment.