Skip to content

Commit

Permalink
Merge branch 'main' into update-api-types-1700648959
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcharnley authored Nov 24, 2023
2 parents 9c3393b + 1aa6484 commit c6a27b9
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 22 deletions.
1 change: 1 addition & 0 deletions server/@types/shared/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,6 @@ export type { User } from './models/User';
export type { UserQualification } from './models/UserQualification';
export type { UserRolesAndQualifications } from './models/UserRolesAndQualifications';
export type { UserSortField } from './models/UserSortField';
export type { UserWithWorkload } from './models/UserWithWorkload';
export type { ValidationError } from './models/ValidationError';
export type { WithdrawalReason } from './models/WithdrawalReason';
2 changes: 2 additions & 0 deletions server/@types/shared/models/ExternalUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
export type ExternalUser = {
id: string;
username: string;
name: string;
email: string;
origin?: string;
};

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { PremisesSummary } from './PremisesSummary';

export type TemporaryAccommodationPremisesSummary = (PremisesSummary & {
pdu?: string;
localAuthorityAreaName?: string;
} & {
pdu: string;
});
Expand Down
17 changes: 17 additions & 0 deletions server/@types/shared/models/UserWithWorkload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { ApprovedPremisesUserRole } from './ApprovedPremisesUserRole';
import type { User } from './User';
import type { UserQualification } from './UserQualification';

export type UserWithWorkload = (User & {
numAssessmentsPending?: number;
numAssessmentsCompleted7Days?: number;
numAssessmentsCompleted30Days?: number;
qualifications?: Array<UserQualification>;
roles?: Array<ApprovedPremisesUserRole>;
});

3 changes: 1 addition & 2 deletions server/controllers/landingController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { userFactory } from '../testutils/factories'
import { UnauthorizedError } from '../utils/errors'
import { isApplyEnabledForUser } from '../utils/userUtils'
import LandingController from './landingController'
import { TemporaryAccommodationUserRole } from '../@types/shared'

jest.mock('../utils/userUtils', () => {
const module = jest.requireActual('../utils/userUtils')
Expand Down Expand Up @@ -97,7 +96,7 @@ describe('LandingController', () => {
const response: DeepMocked<Response> = createMock<Response>({
locals: {
user: userFactory.build({
roles: ['reporter' as TemporaryAccommodationUserRole],
roles: ['reporter'],
}),
},
})
Expand Down
9 changes: 9 additions & 0 deletions server/controllers/staticController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ describe('StaticController', () => {
})
})

describe('accessibility statement', () => {
it('should render the page', () => {
const requestHandler = staticController.accessibilityStatement()
requestHandler(request, response, next)

expect(response.render).toHaveBeenCalledWith('temporary-accommodation/static/accessibilityStatement')
})
})

describe('useNDelius', () => {
it('should render the disabled-region page', () => {
const requestHandler = staticController.useNDelius()
Expand Down
6 changes: 6 additions & 0 deletions server/controllers/staticController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export default class StaticController {
}
}

accessibilityStatement(): RequestHandler {
return (_req: Request, res: Response) => {
res.render('temporary-accommodation/static/accessibilityStatement')
}
}

useNDelius(): RequestHandler {
return (_req: Request, res: Response) => {
res.render('temporary-accommodation/static/useNDelius')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import extractCallConfig from '../../../utils/restUtils'
import { filterProbationRegions } from '../../../utils/userUtils'
import { getYearsSince, monthsArr } from '../../../utils/dateUtils'
import { catchValidationErrorOrPropogate, fetchErrorsAndUserInput, insertGenericError } from '../../../utils/validation'
import { TemporaryAccommodationUserRole } from '../../../@types/shared'

jest.mock('../../../utils/validation')
jest.mock('../../../utils/restUtils')
Expand Down Expand Up @@ -108,7 +107,7 @@ describe('ReportsController', () => {
;(getYearsSince as jest.Mock).mockReturnValue([])

response = createMock<Response>({
locals: { user: userFactory.build({ roles: ['reporter' as TemporaryAccommodationUserRole] }) },
locals: { user: userFactory.build({ roles: ['reporter'] }) },
})

await requestHandler(request, response, next)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApprovedPremisesApplication as Application } from '@approved-premises/api'
import { TemporaryAccommodationApplication as Application } from '@approved-premises/api'
import type { TaskListErrors } from '@approved-premises/ui'
import { Page } from '../../../utils/decorators'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApprovedPremisesApplication as Application } from '@approved-premises/api'
import { TemporaryAccommodationApplication as Application } from '@approved-premises/api'
import type { TaskListErrors } from '@approved-premises/ui'
import { Page } from '../../../utils/decorators'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApprovedPremisesApplication as Application } from '@approved-premises/api'
import { TemporaryAccommodationApplication as Application } from '@approved-premises/api'
import type { TaskListErrors } from '@approved-premises/ui'
import { Page } from '../../../utils/decorators'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ApprovedPremisesApplication, PersonAcctAlert } from '@approved-premises/api'
import type { TemporaryAccommodationApplication as Application, PersonAcctAlert } from '@approved-premises/api'
import type { DataServices, PageResponse } from '@approved-premises/ui'
import { CallConfig } from '../../../../data/restClient'
import { DateFormats } from '../../../../utils/dateUtils'
Expand Down Expand Up @@ -32,12 +32,12 @@ export default class AcctAlerts implements TasklistPage {

constructor(
readonly body: Partial<AcctAlertsBody>,
readonly application: ApprovedPremisesApplication,
readonly application: Application,
) {}

static async initialize(
_: Record<string, unknown>,
application: ApprovedPremisesApplication,
application: Application,
callConfig: CallConfig,
dataServices: DataServices,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Adjudication, ApprovedPremisesApplication } from '@approved-premises/api'
import type { Adjudication, TemporaryAccommodationApplication as Application } from '@approved-premises/api'
import type { DataServices, PageResponse } from '@approved-premises/ui'
import { CallConfig } from '../../../../data/restClient'
import { DateFormats } from '../../../../utils/dateUtils'
Expand Down Expand Up @@ -34,12 +34,12 @@ export default class Adjudications implements TasklistPage {

constructor(
readonly body: Partial<AdjudicationsBody>,
readonly application: ApprovedPremisesApplication,
readonly application: Application,
) {}

static async initialize(
_: Record<string, unknown>,
application: ApprovedPremisesApplication,
application: Application,
callConfig: CallConfig,
dataServices: DataServices,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApprovedPremisesApplication as Application } from '@approved-premises/api'
import { TemporaryAccommodationApplication as Application } from '@approved-premises/api'
import type { TaskListErrors } from '@approved-premises/ui'
import { Page } from '../../../utils/decorators'

Expand Down
8 changes: 4 additions & 4 deletions server/middleware/userCheckMiddleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createMock } from '@golevelup/ts-jest'
import { Request, Response } from 'express'
import { userFactory } from '../testutils/factories'
import { UnauthorizedError } from '../utils/errors'
import { TemporaryAccommodationUserRole, TemporaryAccommodationUser as User } from '../@types/shared'
import { TemporaryAccommodationUser as User } from '../@types/shared'
import { createUserCheckMiddleware, userIsAuthorisedForManage } from './userCheckMiddleware'
import paths from '../paths/temporary-accommodation/manage'

Expand Down Expand Up @@ -91,7 +91,7 @@ describe('createUserCheckMiddleware', () => {
const request = createMock<Request>({ path: paths.reports.new({}) })
const response = createMock<Response>({
locals: {
user: userFactory.build({ roles: ['reporter' as TemporaryAccommodationUserRole] }),
user: userFactory.build({ roles: ['reporter'] }),
},
})
const next = jest.fn()
Expand All @@ -108,7 +108,7 @@ describe('createUserCheckMiddleware', () => {
const request = createMock<Request>({ path: paths.reports.create({}) })
const response = createMock<Response>({
locals: {
user: userFactory.build({ roles: ['reporter' as TemporaryAccommodationUserRole] }),
user: userFactory.build({ roles: ['reporter'] }),
},
})
const next = jest.fn()
Expand All @@ -125,7 +125,7 @@ describe('createUserCheckMiddleware', () => {
const request = createMock<Request>({ path: paths.assessments.index({}) })
const response = createMock<Response>({
locals: {
user: userFactory.build({ roles: ['reporter' as TemporaryAccommodationUserRole] }),
user: userFactory.build({ roles: ['reporter'] }),
},
})
const next = jest.fn()
Expand Down
2 changes: 2 additions & 0 deletions server/paths/temporary-accommodation/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { temporaryAccommodationPath } from '../service'
const cookiesPath = temporaryAccommodationPath.path('cookies')
const useNDeliusPath = temporaryAccommodationPath.path('use-ndelius')
const notAuthorisedPath = temporaryAccommodationPath.path('not-authorised')
const accessibilityStatementPath = temporaryAccommodationPath.path('accessibility-statement')

const paths = {
static: {
cookies: cookiesPath,
accessibilityStatement: accessibilityStatementPath,
useNDelius: useNDeliusPath,
notAuthorised: notAuthorisedPath,
},
Expand Down
3 changes: 3 additions & 0 deletions server/routes/temporary-accommodation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default function routes(controllers: Controllers, services: Services): Ro

get('/', landingController.index(), { auditEvent: 'VIEW_LANDING' })
get(paths.static.cookies.pattern, staticController.cookies(), { auditEvent: 'VIEW_COOKIES' })
get(paths.static.accessibilityStatement.pattern, staticController.accessibilityStatement(), {
auditEvent: 'VIEW_ACCESSIBILITY_STATEMENT',
})
get(paths.static.useNDelius.pattern, staticController.useNDelius(), { auditEvent: 'VIEW_USE_NDELIUS' })
get(paths.static.notAuthorised.pattern, staticController.notAuthorised(), { auditEvent: 'VIEW_NOT_AUTHORISED' })

Expand Down
4 changes: 2 additions & 2 deletions server/utils/userUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
userHasReferrerRoleAndIsApplyEnabled,
userHasReporterRole,
} from './userUtils'
import { TemporaryAccommodationUserRole as Role, TemporaryAccommodationUserRole } from '../@types/shared'
import { TemporaryAccommodationUserRole as Role } from '../@types/shared'
import config from '../config'

jest.mock('./enabledRegions', () => {
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('userHasAssessorRole', () => {

describe('userHasReporterRole', () => {
it('returns true when user has got the role "reporter"', () => {
const user = userFactory.build({ roles: ['reporter' as TemporaryAccommodationUserRole] })
const user = userFactory.build({ roles: ['reporter'] })
expect(userHasReporterRole(user)).toBe(true)
})

Expand Down
4 changes: 2 additions & 2 deletions server/utils/userUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request } from 'express'
import { ProbationRegion, TemporaryAccommodationUserRole, TemporaryAccommodationUser as User } from '../@types/shared'
import { ProbationRegion, TemporaryAccommodationUser as User } from '../@types/shared'
import enabledRegions from './enabledRegions'
import config from '../config'

Expand All @@ -20,7 +20,7 @@ export function userHasAssessorRole(user: User): boolean {
}

export function userHasReporterRole(user: User): boolean {
return user.roles.includes('reporter' as TemporaryAccommodationUserRole)
return user.roles.includes('reporter')
}

export function userHasReferrerRoleAndIsApplyEnabled(user: User): boolean {
Expand Down
4 changes: 4 additions & 0 deletions server/views/partials/layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
{
href: paths.static.cookies({}),
text: "Cookies"
},
{
href: paths.static.accessibilityStatement({}),
text: "Accessibility statement"
}
]
},
Expand Down
Loading

0 comments on commit c6a27b9

Please sign in to comment.