From 0775659b89a12dcac65bbc040b71a4c50a88ebd3 Mon Sep 17 00:00:00 2001 From: George Goodall Date: Mon, 12 Aug 2024 15:07:55 +0100 Subject: [PATCH 1/5] add basic template --- src/controllers/OrganisationsController.js | 18 ++++++ src/filters/filters.js | 3 +- src/routes/organisations.js | 2 +- src/views/organisations/http-error.html | 71 ++++++++++++++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 src/views/organisations/http-error.html diff --git a/src/controllers/OrganisationsController.js b/src/controllers/OrganisationsController.js index 9ff6adeb..b93fb2ab 100644 --- a/src/controllers/OrganisationsController.js +++ b/src/controllers/OrganisationsController.js @@ -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) } } diff --git a/src/filters/filters.js b/src/filters/filters.js index c2c462d6..2ce7bdb5 100644 --- a/src/filters/filters.js +++ b/src/filters/filters.js @@ -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) diff --git a/src/routes/organisations.js b/src/routes/organisations.js index 5a015fff..3dbec578 100644 --- a/src/routes/organisations.js +++ b/src/routes/organisations.js @@ -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) diff --git a/src/views/organisations/http-error.html b/src/views/organisations/http-error.html new file mode 100644 index 00000000..173aabdb --- /dev/null +++ b/src/views/organisations/http-error.html @@ -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 %} + +{% block content %} + +
+ {% include "includes/_dataset-page-header.html" %} +
+ +
+
+

+ Error accessing data URL +

+ +

There was an error accessing the data URL. Please check the URL is correct and your API is functioning correctly. +

+ +

Error details

+ + {{ govukSummaryList({ + rows: [ + { + key: { + text: "Data URL" + }, + value: { + html: '' + errorData.endpoint_url + '' + } + }, + { + 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 + } + } + ] + }) }} + +

If your data URL has changed you can resubmit your + data URL.

+ +

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.

+ +
+
+ + +{% endblock %} \ No newline at end of file From 7ac5582891a98ca2cad57bb0b79a9329e9f52a5c Mon Sep 17 00:00:00 2001 From: George Goodall Date: Mon, 12 Aug 2024 15:19:08 +0100 Subject: [PATCH 2/5] update template for correct title --- src/views/organisations/http-error.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/views/organisations/http-error.html b/src/views/organisations/http-error.html index 173aabdb..d574f590 100644 --- a/src/views/organisations/http-error.html +++ b/src/views/organisations/http-error.html @@ -2,7 +2,8 @@ {% extends "layouts/main.html" %} -{% set pageName %}{{organisation.name}} — {{dataset.name}} — Task list{% endset %} +{% set pageName %}{{organisation.name}} - {{dataset.name}} - Task list{% endset %} +{% set serviceType = 'manage' %} {% block content %} @@ -58,8 +59,7 @@

Error details

] }) }} -

If your data URL has changed you can resubmit your - data URL.

+

If your data URL has changed you can resubmit your data URL.

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.

From a0656e8e23bdf8b7e7035eed5873c8568ab4cbbf Mon Sep 17 00:00:00 2001 From: George Goodall Date: Mon, 12 Aug 2024 15:19:18 +0100 Subject: [PATCH 3/5] add template test file --- test/unit/http-errorPage.test.js | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/unit/http-errorPage.test.js diff --git a/test/unit/http-errorPage.test.js b/test/unit/http-errorPage.test.js new file mode 100644 index 00000000..b2e4febb --- /dev/null +++ b/test/unit/http-errorPage.test.js @@ -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).toContain('1 January 2022 at 1pm') + + expect(rows[3].querySelector('.govuk-summary-list__key').textContent).toContain('Last successful access') + expect(rows[3].querySelector('.govuk-summary-list__value').textContent).toContain('2 January 2022 at 1pm') + }) +}) From 29fe324f2aee2f87134fdcea6351f3508982dd15 Mon Sep 17 00:00:00 2001 From: George Goodall Date: Mon, 12 Aug 2024 16:08:58 +0100 Subject: [PATCH 4/5] fix test for different timezones --- test/unit/http-errorPage.test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/unit/http-errorPage.test.js b/test/unit/http-errorPage.test.js index b2e4febb..4a8d812a 100644 --- a/test/unit/http-errorPage.test.js +++ b/test/unit/http-errorPage.test.js @@ -60,9 +60,12 @@ describe('http-error.html', () => { 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).toContain('1 January 2022 at 1pm') + 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)/) - expect(rows[3].querySelector('.govuk-summary-list__key').textContent).toContain('Last successful access') - expect(rows[3].querySelector('.govuk-summary-list__value').textContent).toContain('2 January 2022 at 1pm') }) }) From db4d05a96e4dd87f5af86aed7ca23692a005374f Mon Sep 17 00:00:00 2001 From: George Goodall Date: Mon, 12 Aug 2024 16:09:07 +0100 Subject: [PATCH 5/5] linting --- test/unit/http-errorPage.test.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/unit/http-errorPage.test.js b/test/unit/http-errorPage.test.js index 4a8d812a..bc25be06 100644 --- a/test/unit/http-errorPage.test.js +++ b/test/unit/http-errorPage.test.js @@ -62,10 +62,7 @@ describe('http-error.html', () => { 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)/) - + 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)/) }) })