From db3c4fd29ac1712bc65df88583eaf48e9fd27bc7 Mon Sep 17 00:00:00 2001 From: Bob Meredith Date: Tue, 24 Dec 2024 10:51:42 +0000 Subject: [PATCH] Review changes --- integration_tests/pages/manage/occupancyView.ts | 13 ++++++++++--- integration_tests/tests/manage/occupancyView.cy.ts | 11 ++++++++++- .../premises/apOccupancyViewController.test.ts | 1 + .../manage/premises/apOccupancyViewController.ts | 1 + server/routes/manage.ts | 5 ++++- server/views/manage/premises/occupancy/view.njk | 4 ++-- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/integration_tests/pages/manage/occupancyView.ts b/integration_tests/pages/manage/occupancyView.ts index b96b4cd08..c7995163e 100644 --- a/integration_tests/pages/manage/occupancyView.ts +++ b/integration_tests/pages/manage/occupancyView.ts @@ -4,13 +4,20 @@ import { DateFormats, daysToWeeksAndDays } from '../../../server/utils/dateUtils import paths from '../../../server/paths/manage' export default class OccupancyViewPage extends Page { - constructor(private readonly premises: Cas1PremisesSummary) { - super(`View spaces in ${premises.name}`) + constructor(private pageTitle: string) { + super(pageTitle) } static visit(premises: Cas1PremisesSummary): OccupancyViewPage { cy.visit(paths.premises.occupancy.view({ premisesId: premises.id })) - return new OccupancyViewPage(premises) + return new OccupancyViewPage(`View spaces in ${premises.name}`) + } + + static visitUnauthorised(premises: Cas1PremisesSummary): OccupancyViewPage { + cy.visit(paths.premises.occupancy.view({ premisesId: premises.id }), { + failOnStatusCode: false, + }) + return new OccupancyViewPage(`Authorisation Error`) } shouldShowCalendarHeading(startDate: string, durationDays: number): void { diff --git a/integration_tests/tests/manage/occupancyView.cy.ts b/integration_tests/tests/manage/occupancyView.cy.ts index 6bca7f857..1bbac11ea 100644 --- a/integration_tests/tests/manage/occupancyView.cy.ts +++ b/integration_tests/tests/manage/occupancyView.cy.ts @@ -51,7 +51,7 @@ context('Premises occupancy', () => { // And I click the action link view spaces page.clickAction('View spaces') // Then I should navigate to the occupancy view - const occPage = Page.verifyOnPage(OccupancyViewPage, premises) + const occPage = Page.verifyOnPage(OccupancyViewPage, `View spaces in ${premises.name}`) occPage.shouldShowCalendarHeading(startDate, DateFormats.differenceInDays(endDateObj, startDateObj).number) occPage.shouldShowCalendar(premisesCapacity) }) @@ -148,5 +148,14 @@ context('Premises occupancy', () => { page.actionShouldNotExist('View spaces') }) }) + describe('Without premises view permission', () => { + it('should not be availble if the user lacks premises_view permission', () => { + // Given I am logged in as a future manager without premises_view permission + signIn(['future_manager']) + // When I navigate to the view premises occupancy page + // Then I should see an error + OccupancyViewPage.visitUnauthorised(premises) + }) + }) }) }) diff --git a/server/controllers/manage/premises/apOccupancyViewController.test.ts b/server/controllers/manage/premises/apOccupancyViewController.test.ts index fc0faac24..d34426cc2 100644 --- a/server/controllers/manage/premises/apOccupancyViewController.test.ts +++ b/server/controllers/manage/premises/apOccupancyViewController.test.ts @@ -55,6 +55,7 @@ describe('AP occupancyViewController', () => { expect(response.render).toHaveBeenCalledWith( 'manage/premises/occupancy/view', expect.objectContaining({ + pageHeading: `View spaces in ${premisesSummary.name}`, calendarHeading: 'Showing 12 weeks from 1 Jan 2024', premises: premisesSummary, backLink: paths.premises.show({ premisesId }), diff --git a/server/controllers/manage/premises/apOccupancyViewController.ts b/server/controllers/manage/premises/apOccupancyViewController.ts index 6cbed3502..6a4b25921 100644 --- a/server/controllers/manage/premises/apOccupancyViewController.ts +++ b/server/controllers/manage/premises/apOccupancyViewController.ts @@ -47,6 +47,7 @@ export default class ApOccupancyViewController { } const calendarHeading = `Showing ${DateFormats.formatDuration(daysToWeeksAndDays(String(durationDays)))} from ${DateFormats.isoDateToUIDate(startDate, { format: 'short' })}` return res.render('manage/premises/occupancy/view', { + pageHeading: `View spaces in ${premises.name}`, premises, calendar, backLink: paths.premises.show({ premisesId }), diff --git a/server/routes/manage.ts b/server/routes/manage.ts index baa468bed..010b0a165 100644 --- a/server/routes/manage.ts +++ b/server/routes/manage.ts @@ -241,7 +241,10 @@ export default function routes(controllers: Controllers, router: Router, service }) // Occupancy - get(paths.premises.occupancy.view.pattern, apOccupancyViewController.view()) + get(paths.premises.occupancy.view.pattern, apOccupancyViewController.view(), { + auditEvent: 'VIEW_OCCUPANCY', + allowedPermissions: ['cas1_premises_view'], + }) // Bookings get(paths.bookings.show.pattern, bookingsController.show(), { diff --git a/server/views/manage/premises/occupancy/view.njk b/server/views/manage/premises/occupancy/view.njk index 2be27ab70..0430bcb51 100644 --- a/server/views/manage/premises/occupancy/view.njk +++ b/server/views/manage/premises/occupancy/view.njk @@ -11,7 +11,7 @@ {% extends "../../../partials/layout.njk" %} -{% set pageTitle = applicationName + " - " + premises.name %} +{% set pageTitle = applicationName + " - " + pageHeading %} {% set mainClasses = "app-container govuk-body" %} {% block beforeContent %} @@ -28,7 +28,7 @@ {% block content %} {{ showErrorSummary(errorSummary) }} {{ premises.name }} -

View spaces in {{ premises.name }}

+

{{ pageHeading }}