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

RA-210: create applications route #1

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 0 additions & 10 deletions .env.example

This file was deleted.

2 changes: 1 addition & 1 deletion integration_tests/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Page, { PageElement } from './page'

export default class IndexPage extends Page {
constructor() {
super('This site is under construction...')
super('Applications')
}

headerUserName = (): PageElement => cy.get('[data-qa=header-user-name]')
Expand Down
21 changes: 21 additions & 0 deletions server/routes/applications/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Request, Response, Router } from 'express'
import asyncMiddleware from '../../middleware/asyncMiddleware'
import AuditService, { Page } from '../../services/auditService'

export default function applicationsRoutes({ auditService }: { auditService: AuditService }): Router {
const router = Router()

router.get(
'/',
asyncMiddleware(async (req: Request, res: Response) => {
await auditService.logPageView(Page.APPLICATIONS_PAGE, {
who: res.locals.user.username,
correlationId: req.id,
})

res.render('pages/applications', { title: 'Applications' })
}),
)

return router
}
3 changes: 1 addition & 2 deletions server/routes/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ describe('GET /', () => {
.get('/')
.expect('Content-Type', /html/)
.expect(res => {
expect(res.text).toContain('This site is under construction...')
expect(auditService.logPageView).toHaveBeenCalledWith(Page.EXAMPLE_PAGE, {
expect(auditService.logPageView).toHaveBeenCalledWith(Page.APPLICATIONS_PAGE, {
who: user.username,
correlationId: expect.any(String),
})
Expand Down
13 changes: 4 additions & 9 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { type RequestHandler, Router } from 'express'
import { Router } from 'express'

import asyncMiddleware from '../middleware/asyncMiddleware'
import type { Services } from '../services'
import { Page } from '../services/auditService'

import applicationsRoutes from './applications'

export default function routes({ auditService }: Services): Router {
const router = Router()
const get = (path: string | string[], handler: RequestHandler) => router.get(path, asyncMiddleware(handler))

get('/', async (req, res, next) => {
await auditService.logPageView(Page.EXAMPLE_PAGE, { who: res.locals.user.username, correlationId: req.id })

res.render('pages/index')
})
router.use('/', applicationsRoutes({ auditService }))

return router
}
1 change: 1 addition & 0 deletions server/services/auditService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import HmppsAuditClient, { AuditEvent } from '../data/hmppsAuditClient'

export enum Page {
EXAMPLE_PAGE = 'EXAMPLE_PAGE',
APPLICATIONS_PAGE = 'APPLICATIONS_PAGE',
}

export interface PageViewEventDetails {
Expand Down
10 changes: 10 additions & 0 deletions server/views/pages/applications.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "../partials/layout.njk" %}

{% set pageTitle = applicationName + " - Applications" %}
{% set mainClasses = "app-container govuk-body" %}

{% block content %}

<h1>{{ title }}</h1>

{% endblock %}
Loading