Skip to content

Commit

Permalink
Merge pull request #420 from DEFRA/unit-test-coverage
Browse files Browse the repository at this point in the history
Committing Unit test coverage code change
  • Loading branch information
saranyavinayagam08 authored Jan 14, 2025
2 parents 7a3ca1b + dd760aa commit eea3cf0
Show file tree
Hide file tree
Showing 27 changed files with 770 additions and 43 deletions.
14 changes: 11 additions & 3 deletions src/server/accessibility/controller.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { accessibilityHandler } from './controller'
import { accessibilityController } from './controller'

describe('Accessibility Handler', () => {
const mockRequest = {
Expand Down Expand Up @@ -26,14 +26,22 @@ describe('Accessibility Handler', () => {

it('should redirect to the Welsh version if the language is "cy"', () => {
mockRequest.query.lang = 'cy'
const result = accessibilityHandler(mockRequest, mockH, mockContent)
const result = accessibilityController.handler(
mockRequest,
mockH,
mockContent
)
expect(result).toBe('redirected')
expect(mockH.redirect).toHaveBeenCalledWith('/hygyrchedd/cy?lang=cy')
})

it('should render the accessibility page with the necessary data', () => {
mockRequest.query.lang = 'en'
const result = accessibilityHandler(mockRequest, mockH, mockContent)
const result = accessibilityController.handler(
mockRequest,
mockH,
mockContent
)
expect(result).toBe('view rendered')
expect(mockH.view).toHaveBeenCalledWith('accessibility/index', {
pageTitle: 'mock pageTitle',
Expand Down
38 changes: 35 additions & 3 deletions src/server/accessibility/cy/controller.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { accessibilityHandler } from './controller'
import { accessibilityController } from './controller'

describe('Accessibility Handler', () => {
const mockRequest = {
Expand Down Expand Up @@ -27,14 +27,46 @@ describe('Accessibility Handler', () => {

it('should redirect to the English version if the language is "en"', () => {
mockRequest.query.lang = 'en'
const result = accessibilityHandler(mockRequest, mockH, mockContent)
const result = accessibilityController.handler(
mockRequest,
mockH,
mockContent
)
expect(result).toBe('redirected')
expect(mockH.redirect).toHaveBeenCalledWith('/accessibility?lang=en')
})

it('should render the accessibility page with the necessary data', () => {
mockRequest.query.lang = 'cy'
const result = accessibilityHandler(mockRequest, mockH, mockContent)
const result = accessibilityController.handler(
mockRequest,
mockH,
mockContent
)
expect(result).toBe('view rendered')
expect(mockH.view).toHaveBeenCalledWith('accessibility/index', {
pageTitle: 'mock pageTitle',
title: 'mock title',
heading: 'mock heading',
headings: 'mock headings',
paragraphs: 'mock paragraphs',
displayBacklink: false,
phaseBanner: 'mock phaseBanner',
footerTxt: 'mock footerTxt',
serviceName: 'mock serviceName',
cookieBanner: 'mock cookieBanner',
lang: mockRequest.query.lang
})
})

it('should render the accessibility page by Default to Welsh if language is not cy and en', () => {
mockRequest.query.lang = 'test'
mockRequest.path = '/preifatrwydd/cy'
const result = accessibilityController.handler(
mockRequest,
mockH,
mockContent
)
expect(result).toBe('view rendered')
expect(mockH.view).toHaveBeenCalledWith('accessibility/index', {
pageTitle: 'mock pageTitle',
Expand Down
12 changes: 12 additions & 0 deletions src/server/accessibility/cy/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { accessibilityCy } from './index'

describe('accessibility index plugin - cy', () => {
const server = {
route: jest.fn()
}

test('should register accessibility route - cy', () => {
accessibilityCy.plugin.register(server)
expect(server.route).toHaveBeenCalled()
})
})
16 changes: 16 additions & 0 deletions src/server/accessibility/cy/routes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { routes } from './routes'
import { accessibilityController } from './controller'

jest.mock('./controller')

describe('Accessibility cy Routes', () => {
it('should define the accessibility route - cy', () => {
expect(routes).toEqual([
{
method: 'GET',
path: '/hygyrchedd/cy',
...accessibilityController
}
])
})
})
12 changes: 12 additions & 0 deletions src/server/accessibility/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { accessibility } from './index'

describe('accessibility index plugin', () => {
const server = {
route: jest.fn()
}

test('should register accessibility route', () => {
accessibility.plugin.register(server)
expect(server.route).toHaveBeenCalled()
})
})
6 changes: 3 additions & 3 deletions src/server/check-local-air-quality/controller.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { handleHomeRequest } from '~/src/server/home/controller'
import { homeController } from './controller'
import { english } from '~/src/server/data/en/en.js'

describe('Home Controller', () => {
Expand All @@ -18,14 +18,14 @@ describe('Home Controller', () => {

it('should redirect to the Welsh version if the language is "cy"', () => {
mockRequest.query.lang = 'cy'
const result = handleHomeRequest(mockRequest, mockH, mockContent)
const result = homeController.handler(mockRequest, mockH, mockContent)
expect(result).toBe('redirected')
expect(mockH.redirect).toHaveBeenCalledWith('cy')
})

it('should render the home page with the necessary data', () => {
mockRequest.query.lang = 'en'
const result = handleHomeRequest(mockRequest, mockH, mockContent)
const result = homeController.handler(mockRequest, mockH, mockContent)
expect(result).toBe('view rendered')
expect(mockH.view).toHaveBeenCalledWith('home/index', {
pageTitle: mockContent.home.pageTitle,
Expand Down
12 changes: 6 additions & 6 deletions src/server/check-local-air-quality/cy/controller.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/server/check-local-air-quality/cy/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { homeCy } from './index'

describe('homeCy index plugin - cy', () => {
const server = {
route: jest.fn()
}

test('should register homeCy route - cy', () => {
homeCy.plugin.register(server)
expect(server.route).toHaveBeenCalled()
})
})
12 changes: 12 additions & 0 deletions src/server/check-local-air-quality/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { home } from './index'

describe('home index plugin', () => {
const server = {
route: jest.fn()
}

test('should register home route', () => {
home.plugin.register(server)
expect(server.route).toHaveBeenCalled()
})
})
4 changes: 2 additions & 2 deletions src/server/check-local-air-quality/routes.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { configureRoutes } from '~/src/server/home/routes'
import { homeController } from '~/src/server/home/controller'
import { configureRoutes } from './routes'
import { homeController } from './controller'

describe('Route Configuration', () => {
it('should configure the routes correctly', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/server/cookies/controller.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cookiesHandler } from '~/src/server/cookies/controller'
import { cookiesController } from './controller'
import { welsh } from '~/src/server/data/cy/cy.js'

describe('Cookies Handler', () => {
Expand All @@ -19,14 +19,14 @@ describe('Cookies Handler', () => {

it('should redirect to the Welsh version if the language is "cy"', () => {
mockRequest.query.lang = 'cy'
const result = cookiesHandler(mockRequest, mockH, mockContent)
const result = cookiesController.handler(mockRequest, mockH, mockContent)
expect(result).toBe('redirected')
expect(mockH.redirect).toHaveBeenCalledWith('/briwsion/cy?lang=cy')
})

it('should render the cookies page with the necessary data', () => {
mockRequest.query.lang = 'en'
const result = cookiesHandler(mockRequest, mockH, mockContent)
const result = cookiesController.handler(mockRequest, mockH, mockContent)
expect(result).toBe('view rendered')
expect(mockH.view).toHaveBeenCalledWith('cookies/index', {
pageTitle: mockContent.footer.cookies.pageTitle,
Expand All @@ -41,14 +41,14 @@ describe('Cookies Handler', () => {
footerTxt: mockContent.footerTxt,
serviceName: mockContent.multipleLocations.serviceName,
cookieBanner: mockContent.cookieBanner,
lang: 'en'
lang: mockRequest.query.lang
})
})

it('should default to English if language is not "cy" or "en" and path is "/cookies"', () => {
mockRequest.query.lang = 'fr'
mockRequest.path = '/cookies'
const result = cookiesHandler(mockRequest, mockH, mockContent)
const result = cookiesController.handler(mockRequest, mockH, mockContent)
expect(result).toBe('view rendered')
expect(mockH.view).toHaveBeenCalledWith('cookies/index', {
pageTitle: mockContent.footer.cookies.pageTitle,
Expand Down
18 changes: 10 additions & 8 deletions src/server/cookies/cy/controller.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cookiesHandler } from '~/src/server/cookies/controller'
import { cookiesController } from './controller'
import { welsh } from '~/src/server/data/cy/cy.js'

describe('Cookies Handler', () => {
Expand All @@ -18,14 +18,15 @@ describe('Cookies Handler', () => {
})

it('should redirect to the English version if the language is "en"', () => {
mockRequest.query.lang = 'cy'
const result = cookiesHandler(mockRequest, mockH, mockContent)
mockRequest.query.lang = 'en'
const result = cookiesController.handler(mockRequest, mockH, mockContent)
expect(result).toBe('redirected')
expect(mockH.redirect).toHaveBeenCalledWith('/briwsion/cy?lang=cy')
expect(mockH.redirect).toHaveBeenCalledWith('/cookies?lang=en')
})

it('should render the cookies page with the necessary data', () => {
const result = cookiesHandler(mockRequest, mockH, mockContent)
mockRequest.query.lang = 'cy'
const result = cookiesController.handler(mockRequest, mockH, mockContent)
expect(result).toBe('view rendered')
expect(mockH.view).toHaveBeenCalledWith('cookies/index', {
pageTitle: mockContent.footer.cookies.pageTitle,
Expand All @@ -39,14 +40,15 @@ describe('Cookies Handler', () => {
phaseBanner: mockContent.phaseBanner,
footerTxt: mockContent.footerTxt,
serviceName: mockContent.multipleLocations.serviceName,
cookieBanner: mockContent.cookieBanner
cookieBanner: mockContent.cookieBanner,
lang: mockRequest.query.lang
})
})

it('should default to Welsh if language is not "cy" or "en" and path is "/preifatrwydd/cy"', () => {
mockRequest.query.lang = 'fr'
mockRequest.path = '/preifatrwydd/cy'
const result = cookiesHandler(mockRequest, mockH, mockContent)
const result = cookiesController.handler(mockRequest, mockH, mockContent)
expect(result).toBe('view rendered')
expect(mockH.view).toHaveBeenCalledWith('cookies/index', {
pageTitle: mockContent.footer.cookies.pageTitle,
Expand All @@ -61,7 +63,7 @@ describe('Cookies Handler', () => {
footerTxt: mockContent.footerTxt,
serviceName: mockContent.multipleLocations.serviceName,
cookieBanner: mockContent.cookieBanner,
lang: 'fr'
lang: 'cy'
})
})
})
6 changes: 3 additions & 3 deletions src/server/home/controller.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { handleHomeRequest } from '~/src/server/home/controller'
import { homeController } from './controller'
import { english } from '~/src/server/data/en/en.js'

describe('Home Controller', () => {
Expand All @@ -18,14 +18,14 @@ describe('Home Controller', () => {

it('should redirect to the Welsh version if the language is "cy"', () => {
mockRequest.query.lang = 'cy'
const result = handleHomeRequest(mockRequest, mockH, mockContent)
const result = homeController.handler(mockRequest, mockH, mockContent)
expect(result).toBe('redirected')
expect(mockH.redirect).toHaveBeenCalledWith('cy')
})

it('should render the home page with the necessary data', () => {
mockRequest.query.lang = 'en'
const result = handleHomeRequest(mockRequest, mockH, mockContent)
const result = homeController.handler(mockRequest, mockH, mockContent)
expect(result).toBe('view rendered')
expect(mockH.view).toHaveBeenCalledWith('home/index', {
pageTitle: mockContent.home.pageTitle,
Expand Down
12 changes: 6 additions & 6 deletions src/server/home/cy/controller.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eea3cf0

Please sign in to comment.