Skip to content

Commit

Permalink
Merge pull request #199 from digital-land/feat/orgFinder/routerAndCon…
Browse files Browse the repository at this point in the history
…troller

Ticket: https://github.com/orgs/digital-land/projects/7/views/12?pane=issue&itemId=71541701

this initially will be merged into staging. but we will merge into main once enough parts come together to deliver some value
  • Loading branch information
rosado authored Aug 1, 2024
2 parents ef0a438 + 0cf60a3 commit 4167d95
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const availableDatasets = Object.values(dataSubjects)
.map(dataset => dataset.value)
)

const LpaOverviewController = {
const organisationsController = {
/**
* Get LPA overview data and render the overview page
* @param {Request} req - Express request object
Expand Down Expand Up @@ -63,12 +63,16 @@ const LpaOverviewController = {
datasetsWithErrors
}

res.render('manage/lpa-overview.html', params)
res.render('organisations/overview.html', params)
} catch (error) {
logger.error(error)
next(error)
}
},

async getOrganisations (req, res, next) {
res.render('organisations/find.html')
}
}

export default LpaOverviewController
export default organisationsController
8 changes: 0 additions & 8 deletions src/routes/manage.js

This file was deleted.

10 changes: 10 additions & 0 deletions src/routes/organisations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import express from 'express'
import OrganisationsController from '../controllers/OrganisationsController.js'

const router = express.Router()

router.get('/', OrganisationsController.getOrganisations)

router.get('/:lpa/overview', OrganisationsController.getOverview)

export default router
10 changes: 6 additions & 4 deletions src/serverSetup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import endpointSubmissionFormFormWisard from '../routes/form-wizard/endpoint-sub
import accessibility from '../routes/accessibility.js'
import polling from '../routes/api.js'
import health from '../routes/health.js'
import manage from '../routes/manage.js'
import organisations from '../routes/organisations.js'
import privacy from '../routes/privacy.js'
import cookies from '../routes/cookies.js'

export function setupRoutes (app) {
app.use('/', checkFormWizard)
app.use('/submit', endpointSubmissionFormFormWisard)
app.use('/accessibility', accessibility)
app.use('/organisations', organisations)

app.use('/api', polling)
app.use('/health', health)
app.use('/manage', manage)

app.use('/accessibility', accessibility)
app.use('/privacy-notice', privacy)
app.use('/cookies', cookies)
app.use('/health', health)
}
26 changes: 26 additions & 0 deletions src/views/organisations/find.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "layouts/main.html" %}

{% from "govuk/components/breadcrumbs/macro.njk" import govukBreadcrumbs %}
{% from "govuk/components/tag/macro.njk" import govukTag %}

{% block beforeContent %}
{{ super() }}

{% endblock %}

{% block content %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

<h1 class="govuk-heading-xl">
{{ pageName }}
</h1>
</div>
</div>

<h1>Find page placeholder</h1>



{% endblock %}
File renamed without changes.
64 changes: 0 additions & 64 deletions test/unit/lpaOverviewController.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/lpaOverviewPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('LPA Overview Page', () => {
}
]
}
const html = nunjucks.render('manage/lpa-overview.html', params)
const html = nunjucks.render('organisations/overview.html', params)

const dom = new jsdom.JSDOM(html)
const document = dom.window.document
Expand Down
74 changes: 74 additions & 0 deletions test/unit/organisationsController.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { describe, it, vi, expect, beforeEach } from 'vitest'
import LpaOverviewController from '../../src/controllers/OrganisationsController.js'
import performanceDbApi from '../../src/services/performanceDbApi.js'

vi.mock('../../src/services/performanceDbApi.js')
vi.mock('../../src/utils/utils.js', () => {
return {
dataSubjects: {}
}
})

describe('OrganisationsController.js', () => {
beforeEach(() => {
vi.resetAllMocks()
})

describe('overview', () => {
it('should render the overview page', async () => {
const req = { params: { lpa: 'test-lpa' } }
const res = { render: vi.fn() }
const next = vi.fn()

const expectedResponse = {
name: 'Test LPA',
datasets: {
dataset1: { endpoint: 'https://example.com', issue: false, error: false },
dataset2: { endpoint: null, issue: true, error: false },
dataset3: { endpoint: 'https://example.com', issue: false, error: true }
}
}

performanceDbApi.getLpaOverview = vi.fn().mockResolvedValue(expectedResponse)

await LpaOverviewController.getOverview(req, res, next)

expect(res.render).toHaveBeenCalledTimes(1)
expect(res.render).toHaveBeenCalledWith('organisations/overview.html', expect.objectContaining({
organisation: { name: 'Test LPA' },
datasets: expect.arrayContaining([
{ endpoint: 'https://example.com', issue: false, error: false, slug: 'dataset1' },
{ endpoint: null, issue: true, error: false, slug: 'dataset2' },
{ endpoint: 'https://example.com', issue: false, error: true, slug: 'dataset3' }
]),
totalDatasets: 3,
datasetsWithEndpoints: 2,
datasetsWithIssues: 1,
datasetsWithErrors: 1
}))
})

it('should catch and pass errors to the next function', async () => {
const req = { params: { lpa: 'test-lpa' } }
const res = { }
const next = vi.fn()

const error = new Error('Test error')

vi.mocked(performanceDbApi.getLpaOverview).mockRejectedValue(error)

await LpaOverviewController.getOverview(req, res, next)

expect(next).toHaveBeenCalledTimes(1)
expect(next).toHaveBeenCalledWith(error)
})
})

describe('find', () => {
it.todo('should render the find page', () => {

})

it.todo('should catch errors and pass them onto the next function')
})
})

0 comments on commit 4167d95

Please sign in to comment.