Skip to content

Commit

Permalink
Merge pull request #264 from digital-land/feat/endpointError/template
Browse files Browse the repository at this point in the history
Feat/endpoint error/template
  • Loading branch information
GeorgeGoodall authored Aug 13, 2024
2 parents e78f466 + 1600060 commit 084612a
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/controllers/OrganisationsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,24 @@ const organisationsController = {
logger.warn(`getIssueDetails() failed for lpa='${lpa}', datasetId='${datasetId}', issue=${issueType}, entityNumber=${entityNumber}, resourceId=${resourceId}`, { type: types.App })
next(e)
}
},

async getEndpointError (req, res, next) {
const params = {
organisation: {
name: 'mock org'
},
dataset: {
name: 'mock dataset'
},
errorData: {
endpoint_url: 'http://fakeUrl.com',
http_status: '404',
latest_log_entry_date: '2024-08-11T00:15:32Z',
latest_200_date: '2024-08-11T00:15:32Z'
}
}
res.render('organisations/http-error.html', params)
}

}
Expand Down
3 changes: 2 additions & 1 deletion src/filters/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import prettifyColumnName from './prettifyColumnName.js'
import getFullServiceName from './getFullServiceName.js'
import { makeDatasetSlugToReadableNameFilter } from './makeDatasetSlugToReadableNameFilter.js'

const { govukMarkdown } = xGovFilters
const { govukMarkdown, govukDateTime } = xGovFilters

const addFilters = (nunjucksEnv, { datasetNameMapping }) => {
const datasetSlugToReadableName = makeDatasetSlugToReadableNameFilter(datasetNameMapping)
nunjucksEnv.addFilter('datasetSlugToReadableName', datasetSlugToReadableName)

nunjucksEnv.addFilter('govukMarkdown', govukMarkdown)
nunjucksEnv.addFilter('govukDateTime', govukDateTime)
nunjucksEnv.addFilter('getkeys', getkeys)
nunjucksEnv.addFilter('getContext', getContext)
nunjucksEnv.addFilter('validationMessageLookup', validationMessageLookup)
Expand Down
2 changes: 1 addition & 1 deletion src/routes/organisations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const router = express.Router()
router.get('/:lpa/:dataset/get-started', OrganisationsController.getGetStarted)
router.get('/:lpa/:dataset/:issue_type/:entityNumber', OrganisationsController.getIssueDetails)
router.get('/:lpa/:dataset/:issue_type', OrganisationsController.getIssueDetails)
router.get('/:lpa/:dataset', OrganisationsController.getDatasetTaskList)
router.get('/:lpa/:dataset', OrganisationsController.getEndpointError)
router.get('/:lpa', OrganisationsController.getOverview)
router.get('/', OrganisationsController.getOrganisations)

Expand Down
71 changes: 71 additions & 0 deletions src/views/organisations/http-error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %}

{% extends "layouts/main.html" %}

{% set pageName %}{{organisation.name}} - {{dataset.name}} - Task list{% endset %}
{% set serviceType = 'manage' %}

{% block content %}

<div class="govuk-grid-row">
{% include "includes/_dataset-page-header.html" %}
</div>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-l">
Error accessing data URL
</h2>

<p>There was an error accessing the data URL. Please check the URL is correct and your API is functioning correctly.
</p>

<h3 class="govuk-heading-m">Error details</h3>

{{ govukSummaryList({
rows: [
{
key: {
text: "Data URL"
},
value: {
html: '<code>' + errorData.endpoint_url + '</code>'
}
},
{
key: {
text: "HTTP status"
},
value: {
text: errorData.http_status
}
},
{
key: {
text: "Last attempted access"
},
value: {
text: errorData.latest_log_entry_date | govukDateTime
}
},
{
key: {
text: "Last successful access"
},
value: {
text: errorData.latest_200_date | govukDateTime
}
}
]
}) }}

<p>If your data URL has changed you can <a href="https://check.staging.digital-land.info/submit">resubmit your data URL</a>.</p>

<p>You should try to make sure your data URLs stay the same when you update your data so we can collect your data
each night.</p>

</div>
</div>


{% endblock %}
68 changes: 68 additions & 0 deletions test/unit/http-errorPage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { describe, it, expect } from 'vitest'
import nunjucks from 'nunjucks'
import addFilters from '../../src/filters/filters'
import { JSDOM } from 'jsdom'
import { runGenericPageTests } from './generic-page.js'

const nunjucksEnv = nunjucks.configure([
'src/views',
'src/views/check',
'src/views/submit',
'node_modules/govuk-frontend/dist/',
'node_modules/@x-govuk/govuk-prototype-components/'
], {
dev: true,
noCache: true,
watch: true
})

const datasetNameMapping = new Map()
addFilters(nunjucksEnv, { datasetNameMapping })

describe('http-error.html', () => {
const params = {
organisation: {
name: 'mock org'
},
dataset: {
name: 'mock dataset'
},
errorData: {
endpoint_url: 'https://example.com/data-url',
http_status: 404,
latest_log_entry_date: '2022-01-01T12:00:00Z',
latest_200_date: '2022-01-02T12:00:00Z'
}
}

const html = nunjucks.render('organisations/http-error.html', params)
const dom = new JSDOM(html)
const document = dom.window.document

runGenericPageTests(html, {
pageTitle: 'mock org - mock dataset - Task list - Submit and update your planning data'
})

it('Renders the correct heading', () => {
expect(document.querySelector('h2').textContent).toContain('Error accessing data URL')
})

it('Renders the error details summary list', () => {
const summaryList = document.querySelector('.govuk-summary-list')
const rows = [...summaryList.children]

expect(rows.length).toBe(4)

expect(rows[0].querySelector('.govuk-summary-list__key').textContent).toContain('Data URL')
expect(rows[0].querySelector('.govuk-summary-list__value').innerHTML).toContain(params.errorData.endpoint_url)

expect(rows[1].querySelector('.govuk-summary-list__key').textContent).toContain('HTTP status')
expect(rows[1].querySelector('.govuk-summary-list__value').textContent).toContain(String(params.errorData.http_status))

expect(rows[2].querySelector('.govuk-summary-list__key').textContent).toContain('Last attempted access')
expect(rows[2].querySelector('.govuk-summary-list__value').textContent).toMatch(/\d{1,2} [A-Za-z]{3,9} \d{4} at \d{1,2}(am|pm)/)

expect(rows[3].querySelector('.govuk-summary-list__key').textContent).toContain('Last successful access')
expect(rows[3].querySelector('.govuk-summary-list__value').textContent).toMatch(/\d{1,2} [A-Za-z]{3,9} \d{4} at \d{1,2}(am|pm)/)
})
})

0 comments on commit 084612a

Please sign in to comment.