Skip to content

Commit

Permalink
APS-965: Show CRN for LAO's on the Task List
Browse files Browse the repository at this point in the history
  • Loading branch information
vubalasu committed Jul 15, 2024
1 parent fbb97f7 commit da94595
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 34 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ assets
cypress.json
reporter-config.json
dist/
playwright-report
50 changes: 27 additions & 23 deletions integration_tests/tests/tasks/list.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import ListPage from '../../pages/tasks/listPage'

import { apAreaFactory, assessmentTaskFactory, taskFactory, userFactory } from '../../../server/testutils/factories'
import { apAreaFactory, userFactory } from '../../../server/testutils/factories'
import { restrictedPersonSummaryTaskFactory } from '../../../server/testutils/factories/task'
import { restrictedPersonSummaryAssessmentTaskFactory } from '../../../server/testutils/factories/assessmentTask'

context('Task Allocation', () => {
const users = userFactory.buildList(5)
Expand All @@ -19,9 +21,9 @@ context('Task Allocation', () => {
// Given I am logged in
cy.signIn()

const allocatedTasks = taskFactory.buildList(5)
const unallocatedTasks = taskFactory.buildList(5, { allocatedToStaffMember: undefined })
const completedTasks = assessmentTaskFactory.buildList(5)
const allocatedTasks = restrictedPersonSummaryTaskFactory.buildList(5)
const unallocatedTasks = restrictedPersonSummaryTaskFactory.buildList(5, { allocatedToStaffMember: undefined })
const completedTasks = restrictedPersonSummaryAssessmentTaskFactory.buildList(5)

cy.task('stubGetAllTasks', {
tasks: allocatedTasks,
Expand Down Expand Up @@ -73,10 +75,10 @@ context('Task Allocation', () => {
// Given I am logged in
cy.signIn()

const allocatedTasksPage1 = taskFactory.buildList(10)
const allocatedTasksPage2 = taskFactory.buildList(10)
const allocatedTasksPage9 = taskFactory.buildList(10)
const unallocatedTasks = taskFactory.buildList(1, { allocatedToStaffMember: undefined })
const allocatedTasksPage1 = restrictedPersonSummaryTaskFactory.buildList(10)
const allocatedTasksPage2 = restrictedPersonSummaryTaskFactory.buildList(10)
const allocatedTasksPage9 = restrictedPersonSummaryTaskFactory.buildList(10)
const unallocatedTasks = restrictedPersonSummaryTaskFactory.buildList(1, { allocatedToStaffMember: undefined })

cy.task('stubGetAllTasks', {
tasks: allocatedTasksPage1,
Expand Down Expand Up @@ -133,7 +135,7 @@ context('Task Allocation', () => {
// Given I am logged in
cy.signIn()

const tasks = taskFactory.buildList(10)
const tasks = restrictedPersonSummaryTaskFactory.buildList(10)

cy.task('stubGetAllTasks', {
tasks,
Expand Down Expand Up @@ -219,9 +221,9 @@ context('Task Allocation', () => {
// Given I am logged in
cy.signIn()

const allocatedTasks = taskFactory.buildList(10)
const allocatedTasksFiltered = taskFactory.buildList(1)
const unallocatedTasks = taskFactory.buildList(1, { allocatedToStaffMember: undefined })
const allocatedTasks = restrictedPersonSummaryTaskFactory.buildList(10)
const allocatedTasksFiltered = restrictedPersonSummaryTaskFactory.buildList(1)
const unallocatedTasks = restrictedPersonSummaryTaskFactory.buildList(1, { allocatedToStaffMember: undefined })

cy.task('stubGetAllTasks', {
tasks: allocatedTasks,
Expand Down Expand Up @@ -263,9 +265,9 @@ context('Task Allocation', () => {
// Given I am logged in
cy.signIn()

const allocatedTasks = taskFactory.buildList(10)
const allocatedTasksFiltered = taskFactory.buildList(1)
const unallocatedTasks = taskFactory.buildList(1, { allocatedToStaffMember: undefined })
const allocatedTasks = restrictedPersonSummaryTaskFactory.buildList(10)
const allocatedTasksFiltered = restrictedPersonSummaryTaskFactory.buildList(1)
const unallocatedTasks = restrictedPersonSummaryTaskFactory.buildList(1, { allocatedToStaffMember: undefined })

cy.task('stubGetAllTasks', { tasks: allocatedTasks, allocatedFilter: 'allocated', page: '1', apAreaId: apArea.id })

Expand Down Expand Up @@ -309,9 +311,11 @@ context('Task Allocation', () => {
// Given I am logged in
cy.signIn()

const allocatedTasks = taskFactory.buildList(10)
const unallocatedTasks = taskFactory.buildList(10, { allocatedToStaffMember: undefined })
const unallocatedTasksFiltered = taskFactory.buildList(1, { allocatedToStaffMember: undefined })
const allocatedTasks = restrictedPersonSummaryTaskFactory.buildList(10)
const unallocatedTasks = restrictedPersonSummaryTaskFactory.buildList(10, { allocatedToStaffMember: undefined })
const unallocatedTasksFiltered = restrictedPersonSummaryTaskFactory.buildList(1, {
allocatedToStaffMember: undefined,
})

cy.task('stubGetAllTasks', {
tasks: unallocatedTasks,
Expand Down Expand Up @@ -352,10 +356,10 @@ context('Task Allocation', () => {
// Given I am signed in
cy.signIn()

const allocatedTasks = taskFactory.buildList(1)
const allocatedTasksFiltered = taskFactory.buildList(10)
const allocatedTasksFilteredPage2 = taskFactory.buildList(10)
const unallocatedTasks = taskFactory.buildList(1, { allocatedToStaffMember: undefined })
const allocatedTasks = restrictedPersonSummaryTaskFactory.buildList(1)
const allocatedTasksFiltered = restrictedPersonSummaryTaskFactory.buildList(10)
const allocatedTasksFilteredPage2 = restrictedPersonSummaryTaskFactory.buildList(10)
const unallocatedTasks = restrictedPersonSummaryTaskFactory.buildList(1, { allocatedToStaffMember: undefined })

cy.task('stubGetAllTasks', {
tasks: allocatedTasks,
Expand Down Expand Up @@ -431,7 +435,7 @@ context('Task Allocation', () => {
sortDirection: 'asc',
apAreaId: apArea.id,
})
const completedTasks = assessmentTaskFactory.buildList(5)
const completedTasks = restrictedPersonSummaryAssessmentTaskFactory.buildList(5)
cy.task('stubGetAllTasks', {
tasks: [...completedTasks],
allocatedFilter: 'allocated',
Expand Down
9 changes: 8 additions & 1 deletion server/testutils/factories/assessmentTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import { Factory } from 'fishery'
import type { AssessmentTask } from '@approved-premises/api'

import { faker } from '@faker-js/faker/locale/en_GB'
import taskFactory from './task'
import taskFactory, { restrictedPersonSummaryTaskFactory } from './task'

export default Factory.define<AssessmentTask>(() => ({
...taskFactory.build(),
taskType: 'Assessment',
createdFromAppeal: false,
outcome: faker.helpers.arrayElement(['accepted', 'rejected']),
}))

export const restrictedPersonSummaryAssessmentTaskFactory = Factory.define<AssessmentTask>(() => ({
...restrictedPersonSummaryTaskFactory.build(),
taskType: 'Assessment',
createdFromAppeal: false,
outcome: faker.helpers.arrayElement(['accepted', 'rejected']),
}))
19 changes: 16 additions & 3 deletions server/testutils/factories/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { Factory } from 'fishery'
import { faker } from '@faker-js/faker/locale/en_GB'

import type { FullPerson, PersonSummary, RestrictedPerson } from '@approved-premises/api'
import { FullPersonSummary } from '@approved-premises/api'
import { DateFormats } from '../../utils/dateUtils'

export const getCrn = () => `C${faker.number.int({ min: 100000, max: 999999 })}`
export const fullPersonFactory = Factory.define<FullPerson>(() => ({
crn: `C${faker.number.int({ min: 100000, max: 999999 })}`,
crn: getCrn(),
name: faker.person.fullName(),
dateOfBirth: DateFormats.dateObjToIsoDate(faker.date.past()),
sex: faker.helpers.arrayElement(['Male', 'Female', 'Other', 'Prefer not to say']),
Expand All @@ -19,11 +21,22 @@ export const fullPersonFactory = Factory.define<FullPerson>(() => ({
}))

export const restrictedPersonFactory = Factory.define<RestrictedPerson>(() => ({
crn: `C${faker.number.int({ min: 100000, max: 999999 })}`,
crn: getCrn(),
type: 'RestrictedPerson',
}))

export const personSummaryFactory = Factory.define<PersonSummary>(() => ({
crn: `C${faker.number.int({ min: 100000, max: 999999 })}`,
crn: getCrn(),
personType: faker.helpers.arrayElement(['FullPersonSummary', 'RestrictedPersonSummary', 'UnknownPersonSummary']),
}))

export const restrictedPersonSummaryFactory = Factory.define<PersonSummary>(() => ({
crn: getCrn(),
personType: 'RestrictedPersonSummary',
}))

export const fullPersonSummaryFactory = Factory.define<FullPersonSummary>(() => ({
crn: getCrn(),
personType: 'FullPersonSummary',
name: faker.person.fullName(),
}))
3 changes: 2 additions & 1 deletion server/testutils/factories/risks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { faker } from '@faker-js/faker/locale/en_GB'
import type { PersonRisks, RiskEnvelopeStatus, RiskTierLevel } from '@approved-premises/api'
import { RiskLevel, TierLetter, TierNumber } from '@approved-premises/ui'
import { DateFormats } from '../../utils/dateUtils'
import { getCrn } from './person'

const riskLevels: Array<RiskLevel> = ['Low', 'Medium', 'High', 'Very High']
const riskEnvelopeStatuses: Array<RiskEnvelopeStatus> = ['retrieved', 'not_found', 'error']

export default Factory.define<PersonRisks>(() => ({
crn: `C${faker.number.int({ min: 100000, max: 999999 })}`,
crn: getCrn(),
roshRisks: roshRisksFactory.build(),
mappa: mappaFactory.build(),
flags: flagsFactory.build(),
Expand Down
19 changes: 17 additions & 2 deletions server/testutils/factories/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DateFormats } from '../../utils/dateUtils'

import UserFactory from './user'
import { apAreaFactory } from './referenceData'
import { personSummaryFactory } from './person'
import { getCrn, personSummaryFactory, restrictedPersonSummaryFactory } from './person'

export default Factory.define<Task>(() => ({
id: faker.string.uuid(),
Expand All @@ -17,8 +17,23 @@ export default Factory.define<Task>(() => ({
status: faker.helpers.arrayElement(['not_started', 'in_progress', 'complete']),
taskType: faker.helpers.arrayElement(['Assessment', 'PlacementRequest', 'BookingAppeal']),
personName: faker.person.fullName(),
crn: `C${faker.number.int({ min: 100000, max: 999999 })}`,
crn: getCrn(),
apArea: apAreaFactory.build(),
outcomeRecordedAt: DateFormats.dateObjToIsoDateTime(faker.date.past()),
personSummary: personSummaryFactory.build(),
}))

export const restrictedPersonSummaryTaskFactory = Factory.define<Task>(() => ({
id: faker.string.uuid(),
allocatedToStaffMember: UserFactory.build(),
applicationId: faker.string.uuid(),
dueDate: DateFormats.dateObjToIsoDate(faker.date.future()),
dueAt: DateFormats.dateObjToIsoDateTime(faker.date.future()),
status: faker.helpers.arrayElement(['not_started', 'in_progress', 'complete']),
taskType: faker.helpers.arrayElement(['Assessment', 'PlacementRequest', 'BookingAppeal']),
personName: faker.person.fullName(),
crn: getCrn(),
apArea: apAreaFactory.build(),
outcomeRecordedAt: DateFormats.dateObjToIsoDateTime(faker.date.past()),
personSummary: restrictedPersonSummaryFactory.build(),
}))
41 changes: 39 additions & 2 deletions server/utils/tasks/listTable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { TaskSortField } from '../../@types/shared'
import paths from '../../paths/tasks'
import { daysUntilDueCell } from '../tableUtils'
import { TaskStatusTag } from './statusTag'
import { fullPersonSummaryFactory } from '../../testutils/factories/person'

describe('table', () => {
beforeEach(() => {
Expand Down Expand Up @@ -197,16 +198,52 @@ describe('table', () => {
})

describe('nameAnchorCell', () => {
it('returns the cell when there is a person present in the task', () => {
it('returns the name when the person summary is FullPersonSummary in the task', () => {
const personSummary = fullPersonSummaryFactory.build()
const task = taskFactory.build({
taskType: 'Assessment',
personSummary,
})
expect(nameAnchorCell(task)).toEqual({
html: linkTo(
paths.tasks.show,
{ id: task.id, taskType: kebabCase(task.taskType) },
{
text: task.personName,
text: personSummary.name,
attributes: { 'data-cy-taskId': task.id, 'data-cy-applicationId': task.applicationId },
},
),
})
})
it('returns the Limited Access Offender (LAO) CRN when the person summary is RestrictedPersonSummary in the task', () => {
const personSummary = fullPersonSummaryFactory.build({ personType: 'RestrictedPersonSummary' })
const task = taskFactory.build({
taskType: 'Assessment',
personSummary,
})
expect(nameAnchorCell(task)).toEqual({
html: linkTo(
paths.tasks.show,
{ id: task.id, taskType: kebabCase(task.taskType) },
{
text: `LAO CRN: ${personSummary.crn}`,
attributes: { 'data-cy-taskId': task.id, 'data-cy-applicationId': task.applicationId },
},
),
})
})
it('returns the not found CRN when the person summary is UnknownPersonSummary in the task', () => {
const personSummary = fullPersonSummaryFactory.build({ personType: 'UnknownPersonSummary' })
const task = taskFactory.build({
taskType: 'Assessment',
personSummary,
})
expect(nameAnchorCell(task)).toEqual({
html: linkTo(
paths.tasks.show,
{ id: task.id, taskType: kebabCase(task.taskType) },
{
text: `Not Found CRN: ${personSummary.crn}`,
attributes: { 'data-cy-taskId': task.id, 'data-cy-applicationId': task.applicationId },
},
),
Expand Down
18 changes: 16 additions & 2 deletions server/utils/tasks/listTable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isAssessmentTask, isPlacementApplicationTask, isPlacementRequestTask } from './assertions'
import {
AssessmentDecision,
FullPersonSummary,
PersonSummary,
PlacementApplicationDecision,
PlacementRequestTaskOutcome,
SortDirection,
Expand Down Expand Up @@ -89,9 +91,22 @@ const allocationCell = (task: Task): TableCell => ({
text: task.allocatedToStaffMember?.name,
})

const getPersonName = (personSummary: PersonSummary): string => {
switch (personSummary.personType) {
case 'FullPersonSummary':
return (personSummary as FullPersonSummary).name
case 'RestrictedPersonSummary':
return `LAO CRN: ${personSummary.crn}`
case 'UnknownPersonSummary':
return `Not Found CRN: ${personSummary.crn}`
default:
return ''
}
}

const nameAnchorCell = (task: Task): TableCell => ({
html: linkTo(paths.tasks.show, taskParams(task), {
text: task.personName,
text: getPersonName(task.personSummary),
attributes: { 'data-cy-taskId': task.id, 'data-cy-applicationId': task.applicationId },
}),
})
Expand All @@ -102,7 +117,6 @@ const apAreaCell = (task: Task): TableCell => ({

const allocatedTableRows = (tasks: Array<Task>): Array<TableRow> => {
const rows: Array<TableRow> = []

tasks.forEach(task => {
rows.push([
nameAnchorCell(task),
Expand Down

0 comments on commit da94595

Please sign in to comment.