Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split scenario "base state (no pending weeks)" into two sub scenarios #266

Merged
merged 19 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions public/locales/en/claim-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
"description": "We need to confirm your eligibility for benefits."
},
"base-pending": {
"description": "Your payments are pending further review."
"description": "Your payments are pending further review.",
"next-step": "Check your UI Online inbox for the latest updates."
},
"base-no-pending": {
"base-no-pending-active": {
"description": "Your claim is active and there are no pending issues at this time."
},
"base-no-pending-inactive": {
"description": "There are no pending issues at this time."
},
"conditional-next-steps": {
"certify-no-pending": "<0>Keep certifying</0> as long as you need benefits.",
"certify-pending": "<0>Keep certifying</0> as long as you need benefits, so your payments are not delayed further.",
"contact-info": "Make sure we have your current phone number and email address."
rocketnova marked this conversation as resolved.
Show resolved Hide resolved
}
}
9 changes: 8 additions & 1 deletion public/locales/es/claim-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
"base-pending": {
"description": "Sus pagos están pendientes de revisión adicional."
},
"base-no-pending": {
"base-no-pending-active": {
"description": "No hay asuntos pendientes en este momento."
},
"base-no-pending-inactive": {
"description": "Su reclamo está activo y no hay problemas pendientes en este momento."
},
"conditional-next-steps": {
"certify-no-pending": "<0>Siga certificando</0> mientras necesite beneficios.",
"certify-pending": "<0>Siga certificando</0> mientras necesite beneficios, para que sus pagos no se retrasen más."
}
}
121 changes: 97 additions & 24 deletions tests/utils/getScenarioContent.test.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import getScenarioContent, { getScenario, ScenarioType } from '../../utils/getScenarioContent'
import { ScenarioContent } from '../../types/common'
import { getClaimStatusDescription, getScenario, ScenarioType } from '../../utils/getScenarioContent'

// Shared test constants for mock API gateway responses
const pendingDeterminationScenario = { pendingDetermination: ['temporary text'] }
const basePendingScenario = { hasPendingWeeks: true }
const baseNoPendingScenario = { hasPendingWeeks: false }
const baseNoPendingActiveScenario = { hasPendingWeeks: false, claimDetails: { monetaryStatus: 'active' } }
const baseNoPendingInactiveScenario = { hasPendingWeeks: false, claimDetails: { monetaryStatus: 'inactive' } }

/**
* Begin tests
*/

// Test getScenarioContent()
describe('Retrieving the scenario content', () => {
it('returns the correct status description for the scenario', () => {
const pendingDetermination: ScenarioContent = getScenarioContent(pendingDeterminationScenario)
expect(pendingDetermination.statusContent.statusDescription).toBe('claim-status:pending-determination.description')

const basePending: ScenarioContent = getScenarioContent(basePendingScenario)
expect(basePending.statusContent.statusDescription).toBe('claim-status:base-pending.description')
// Test getClaimStatusDescripton()
describe('Getting the Claim Status description', () => {
it('returns the correct description for the scenario', () => {
const pendingDetermination = getClaimStatusDescription(ScenarioType.PendingDetermination)
expect(pendingDetermination).toBe('claim-status:pending-determination.description')

const baseNoPending: ScenarioContent = getScenarioContent(baseNoPendingScenario)
expect(baseNoPending.statusContent.statusDescription).toBe('claim-status:base-no-pending.description')
const basePending = getClaimStatusDescription(ScenarioType.BasePending)
expect(basePending).toBe('claim-status:base-pending.description')

const baseNoPendingActive = getClaimStatusDescription(ScenarioType.BaseNoPendingActive)
expect(baseNoPendingActive).toBe('claim-status:base-no-pending-active.description')

const baseNoPendingInactive = getClaimStatusDescription(ScenarioType.BaseNoPendingInactive)
expect(baseNoPendingInactive).toBe('claim-status:base-no-pending-inactive.description')
})

it('throws an error if given an unknown scenario', () => {
expect(() => {
getClaimStatusDescription('unknown')
}).toThrowError('Unknown Scenario Type')
})
})

Expand Down Expand Up @@ -68,23 +79,85 @@ describe('The base state (with pending weeks) scenario', () => {
})
})

// Test getScenario(): base state with no pending weeks scenario
describe('The base state (with no pending weeks) scenario', () => {
it('is returned when there are no pending weeks', () => {
const scenarioType: ScenarioType = getScenario(baseNoPendingScenario)
expect(scenarioType).toBe(ScenarioType.BaseNoPending)
// Test getScenario(): base state with no pending weeks; active claim scenario
describe('The base state (with no pending weeks); active claim scenario', () => {
it('is returned when there are no pending weeks and there is an active claim', () => {
const scenarioType: ScenarioType = getScenario(baseNoPendingActiveScenario)
expect(scenarioType).toBe(ScenarioType.BaseNoPendingActive)
})

it('is returned when there are no pending weeks and pendingDetermination is null', () => {
const baseNoPendingScenarioNull = { hasPendingWeeks: false, pendingDetermination: null }
const scenarioType: ScenarioType = getScenario(baseNoPendingScenarioNull)
expect(scenarioType).toBe(ScenarioType.BaseNoPending)
it('is returned when there are no pending weeks and there is an active claim and pendingDetermination is null', () => {
const baseNoPendingActiveScenarioNull = {
hasPendingWeeks: false,
claimDetails: { monetaryStatus: 'active' },
pendingDetermination: null,
}
lomky marked this conversation as resolved.
Show resolved Hide resolved
const scenarioType: ScenarioType = getScenario(baseNoPendingActiveScenarioNull)
expect(scenarioType).toBe(ScenarioType.BaseNoPendingActive)
})

it('is returned when there are no pending weeks and pendingDetermination is an empty array', () => {
const baseNoPendingScenarioEmpty = { hasPendingWeeks: false, pendingDetermination: [] }
const scenarioType: ScenarioType = getScenario(baseNoPendingScenarioEmpty)
expect(scenarioType).toBe(ScenarioType.BaseNoPending)
it('is returned when there are no pending weeks and there is an active claim and pendingDetermination is an empty array', () => {
const baseNoPendingActiveScenarioEmpty = {
hasPendingWeeks: false,
claimDetails: { monetaryStatus: 'active' },
pendingDetermination: [],
}
const scenarioType: ScenarioType = getScenario(baseNoPendingActiveScenarioEmpty)
expect(scenarioType).toBe(ScenarioType.BaseNoPendingActive)
})
})

// Test getScenario(): base state with no pending weeks; Inactive claim scenario
describe('The base state (with no pending weeks); Inactive claim scenario', () => {
it('is returned when there are no pending weeks and monetaryStatus is set to "inactive"', () => {
const scenarioType: ScenarioType = getScenario(baseNoPendingInactiveScenario)
expect(scenarioType).toBe(ScenarioType.BaseNoPendingInactive)
})

it('is returned when there are no pending weeks and monetaryStatus is set to null', () => {
const inactiveScenario = {
hasPendingWeeks: false,
pendingDetermination: null,
claimDetails: {
monetaryStatus: null,
},
}
const scenarioType: ScenarioType = getScenario(inactiveScenario)
expect(scenarioType).toBe(ScenarioType.BaseNoPendingInactive)
})

it('is returned when there are no pending weeks and monetaryStatus is set to undefined', () => {
const inactiveScenario = {
hasPendingWeeks: false,
pendingDetermination: null,
claimDetails: {
monetaryStatus: undefined,
},
}
const scenarioType: ScenarioType = getScenario(inactiveScenario)
expect(scenarioType).toBe(ScenarioType.BaseNoPendingInactive)
})

it('is returned when there are no pending weeks and monetaryStatus is not set', () => {
const inactiveScenario = {
hasPendingWeeks: false,
pendingDetermination: null,
claimDetails: {
programType: 'UI',
},
}
const scenarioType: ScenarioType = getScenario(inactiveScenario)
expect(scenarioType).toBe(ScenarioType.BaseNoPendingInactive)
})

it.skip('errors if there is no claimDetails object', () => {
const baseNoPendingActiveScenarioNull = {
hasPendingWeeks: false,
pendingDetermination: null,
}
expect(() => {
getScenario(baseNoPendingActiveScenarioNull)
}).toThrowError('Missing claim details')
})
})

Expand Down
1 change: 1 addition & 0 deletions types/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ClaimDetailsResult {
export interface Claim {
ClaimType?: null | undefined | string
hasPendingWeeks?: null | undefined | boolean
hasCertificationWeeksAvailable?: null | undefined | boolean
pendingDetermination?: null | [PendingDetermination]
claimDetails?: ClaimDetailsResult
}
Expand Down
102 changes: 64 additions & 38 deletions utils/getScenarioContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import { Claim, ClaimDetailsContent, ClaimStatusContent, ScenarioContent } from
export enum ScenarioType {
PendingDetermination = 'Pending determination scenario',
BasePending = 'Base state with pending weeks',
BaseNoPending = 'Base state with no pending weeks',
BaseNoPendingActive = 'Base state with no pending weeks; Active claim',
BaseNoPendingInactive = 'Base state with no pending weeks; Inactive claim',
rocketnova marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Identify the correct scenario to display.
*
* @param {Qbject} claim
* @returns {Object}
*/
export function getScenario(claimData: Claim): ScenarioType {
// The pending determination scenario: if claimData contains any pendingDetermination
Expand All @@ -19,55 +17,83 @@ export function getScenario(claimData: Claim): ScenarioType {
if (claimData.pendingDetermination && claimData.pendingDetermination.length > 0) {
return ScenarioType.PendingDetermination
}
// The generic pending scenario: if there are no pendingDetermination objects
// AND hasPendingWeeks is true
// The base state (with pending weeks) scenario:
// - there are no pendingDetermination objects AND
// - hasPendingWeeks is true
else if (claimData.hasPendingWeeks === true) {
return ScenarioType.BasePending
} else if (claimData.hasPendingWeeks === false) {
if (claimData.claimDetails) {
// The base state (with no pending weeks); active claim scenario:
// - there are no pendingDetermination objects AND
// - hasPendingWeeks is false AND
// - monetaryStatus is "active"
if (claimData.claimDetails.monetaryStatus && claimData.claimDetails.monetaryStatus.toLowerCase() === 'active') {
return ScenarioType.BaseNoPendingActive
}
// The base state (with no pending weeks); Inactive claim scenario:
// - there are no pendingDetermination objects AND
// - hasPendingWeeks is false AND
// - monetaryStatus is not "active"
else {
return ScenarioType.BaseNoPendingInactive
}
} else {
// @TODO: This should throw an error
// throw new Error('Missing claim details')
return ScenarioType.BaseNoPendingInactive
}
} else {
// @TODO: This should throw an error
// throw new Error('Unknown Scenario')
return ScenarioType.BaseNoPendingInactive
}
// The generic "all clear"/base state scenario: if there are no pendingDetermination objects
// and hasPendingWeeks is false
else if (claimData.hasPendingWeeks === false) {
return ScenarioType.BaseNoPending
}

/**
* Get Claim Status description content.
* This returns an i18n string.
*/
export function getClaimStatusDescription(scenarioType: ScenarioType): string {
switch (scenarioType) {
case ScenarioType.PendingDetermination:
return 'claim-status:pending-determination.description'
case ScenarioType.BasePending:
return 'claim-status:base-pending.description'
case ScenarioType.BaseNoPendingActive:
return 'claim-status:base-no-pending-active.description'
case ScenarioType.BaseNoPendingInactive:
return 'claim-status:base-no-pending-inactive.description'
}
// This is unexpected
// @TODO: Log the scenario and display 500
else {
// throw new Error('Unexpected scenario')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The new logic I went over with Nicole and Diana shouldn't leave an opportunity for an unknown scenario. We will also have an additional layer of API gateway response validation (#150) that will make unexpected response values not possible.

return ScenarioType.BaseNoPending

// If an unknown Scenario Type is given, throw an error.
throw new Error('Unknown Scenario Type')
}

/**
* Get Claim Status content.
*/
export function buildClaimStatusContent(scenarioType: ScenarioType): ClaimStatusContent {
const statusContent: ClaimStatusContent = {
statusDescription: getClaimStatusDescription(scenarioType),
nextSteps: [
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
],
}

return statusContent
}

/**
* Return scenario content.
*
* @param {Object} claim
* @param {enum} scenarioType
* @returns {Object}
*/
export default function getScenarioContent(claimData: Claim): ScenarioContent {
// Get the scenario type.
const scenarioType = getScenario(claimData)

// Construct claim status content.
// This sets an i18n string.
let statusDescription = ''
if (scenarioType === ScenarioType.PendingDetermination) {
statusDescription = 'claim-status:pending-determination.description'
} else if (scenarioType === ScenarioType.BasePending) {
statusDescription = 'claim-status:base-pending.description'
} else {
statusDescription = 'claim-status:base-no-pending.description'
}

const nextSteps = [
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
]

const statusContent: ClaimStatusContent = {
statusDescription: statusDescription,
nextSteps: nextSteps,
}
const statusContent = buildClaimStatusContent(scenarioType)

// Construct claim details content.
// @TODO: Remove placeholder default content
Expand Down