-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Service Status holding page (#7)
DEFRA/water-abstraction-team#54 Here we have the addition of a status page to the service repo. This allows us to see the different status of the service extensions (virus checker, database etc). This change just creates the initial holding page. We will add the additional functionality in separate PRs
- Loading branch information
1 parent
83b6fa1
commit ce5c536
Showing
5 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
'use strict' | ||
|
||
const ServiceStatusService = require('../services/service_status.service') | ||
|
||
class RootController { | ||
static async index (_req, _h) { | ||
return { status: 'alive' } | ||
} | ||
|
||
static async helloWorld (_req, h) { | ||
static helloWorld (_req, h) { | ||
return h.view('home.njk', { | ||
title: 'Hello', | ||
message: 'World', | ||
pageTitle: 'Hello World!' | ||
}) | ||
} | ||
|
||
static async serviceStatus (_req, h) { | ||
const pageData = await ServiceStatusService.go() | ||
|
||
return h.view('service_status.njk', { | ||
pageTitle: 'Service Status', | ||
...pageData | ||
}) | ||
} | ||
} | ||
|
||
module.exports = RootController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
'use strict' | ||
|
||
/** | ||
* @module ServiceStatusService | ||
*/ | ||
|
||
/** | ||
* Returns data required to populate our `/service-status` page, eg. task activity status, virus checker status, service | ||
* version numbers, etc. | ||
* | ||
* Each data set is returned in the format needed to populate the gov.uk table elements ie. an array containing one | ||
* array per row, where each row array contains multiple `{ text: '...' }` elements, one for each cell in the row. | ||
*/ | ||
class ServiceStatusService { | ||
static async go () { | ||
const importData = await this._getImportData() | ||
const virusScannerData = await this._getVirusScannerData() | ||
const cacheConnectivityData = await this._getCacheConnectivityData() | ||
const serviceVersionsData = await this._getServiceVersionsData() | ||
|
||
return { | ||
importRows: this._mapArrayToTextCells(importData), | ||
virusScannerRows: this._mapArrayToStatusCells(virusScannerData), | ||
cacheConnectivityRows: this._mapArrayToStatusCells(cacheConnectivityData), | ||
serviceVersionsRows: this._mapArrayToStatusCells(serviceVersionsData) | ||
} | ||
} | ||
|
||
/** | ||
* Receives an array and returns it in the format required by the nunjucks template in the view. | ||
*/ | ||
static _mapArrayToTextCells (rows) { | ||
return rows.map(row => { | ||
return row.map(cell => { | ||
return { text: cell } | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* Receives an array of statuses and returns it in the format required by the nunjucks template in the view. | ||
*/ | ||
static _mapArrayToStatusCells (rows) { | ||
// Map each row in the array we've received | ||
return rows.map(row => { | ||
// A status row has only two elements: | ||
// * The thing having its status reported, which is a standard text cell; | ||
// * Its status, which is formatted numeric so that it's right justified on its row. | ||
return [ | ||
{ text: row[0] }, | ||
{ text: row[1], format: 'numeric' } | ||
] | ||
}) | ||
} | ||
|
||
static async _getImportData () { | ||
return [ | ||
[ | ||
'Cell 1.1', | ||
'Cell 1.2', | ||
'Cell 1.3', | ||
'Cell 1.4', | ||
'Cell 1.5' | ||
], | ||
[ | ||
'Cell 2.1', | ||
'Cell 2.2', | ||
'Cell 2.3', | ||
'Cell 2.4', | ||
'Cell 2.5' | ||
] | ||
] | ||
} | ||
|
||
static async _getVirusScannerData () { | ||
return [ | ||
[ | ||
'Status', | ||
'OK' | ||
] | ||
] | ||
} | ||
|
||
static async _getCacheConnectivityData () { | ||
return [ | ||
[ | ||
'Status', | ||
'Connected' | ||
] | ||
] | ||
} | ||
|
||
static async _getServiceVersionsData () { | ||
return [ | ||
[ | ||
'Water service', | ||
'3.0.1' | ||
], | ||
[ | ||
'IDM', | ||
'2.25.1' | ||
] | ||
] | ||
} | ||
} | ||
|
||
module.exports = ServiceStatusService |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{% extends 'layout.njk' %} | ||
|
||
{% from "govuk/components/table/macro.njk" import govukTable %} | ||
|
||
{% block content %} | ||
<div class="govuk-body"> | ||
<h1 class="govuk-heading-l">Service Status</h1> | ||
|
||
{{ govukTable({ | ||
caption: "Imports", | ||
captionClasses: "govuk-table__caption--m", | ||
firstCellIsHeader: true, | ||
head: [ | ||
{ | ||
text: "Import task name" | ||
}, | ||
{ | ||
text: "Success rate (last 3 days)" | ||
}, | ||
{ | ||
text: "Active" | ||
}, | ||
{ | ||
text: "Last updated" | ||
}, | ||
{ | ||
text: "Last checked" | ||
} | ||
], | ||
rows: importRows | ||
}) }} | ||
|
||
{{ govukTable({ | ||
caption: "Virus scanner", | ||
captionClasses: "govuk-table__caption--m", | ||
firstCellIsHeader: true, | ||
rows: virusScannerRows | ||
}) }} | ||
|
||
{{ govukTable({ | ||
caption: "Cache connectivity", | ||
captionClasses: "govuk-table__caption--m", | ||
firstCellIsHeader: true, | ||
rows: cacheConnectivityRows | ||
}) }} | ||
|
||
{{ govukTable({ | ||
caption: "Service versions", | ||
captionClasses: "govuk-table__caption--m", | ||
firstCellIsHeader: true, | ||
rows: serviceVersionsRows | ||
}) }} | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
|
||
// Test framework dependencies | ||
const Lab = require('@hapi/lab') | ||
const Code = require('@hapi/code') | ||
|
||
const { describe, it } = exports.lab = Lab.script() | ||
const { expect } = Code | ||
|
||
// Thing under test | ||
const ServiceStatusService = require('../../app/services/service_status.service.js') | ||
|
||
const firstRow = [ | ||
{ text: 'Cell 1.1' }, | ||
{ text: 'Cell 1.2' }, | ||
{ text: 'Cell 1.3' }, | ||
{ text: 'Cell 1.4' }, | ||
{ text: 'Cell 1.5' } | ||
] | ||
|
||
const secondRow = [ | ||
{ text: 'Cell 2.1' }, | ||
{ text: 'Cell 2.2' }, | ||
{ text: 'Cell 2.3' }, | ||
{ text: 'Cell 2.4' }, | ||
{ text: 'Cell 2.5' } | ||
] | ||
|
||
describe('Service Status service', () => { | ||
describe('importRows data', () => { | ||
it('returns data in the expected format', async () => { | ||
const { importRows } = await ServiceStatusService.go() | ||
|
||
expect(importRows).to.equal([ | ||
firstRow, | ||
secondRow | ||
]) | ||
}) | ||
}) | ||
}) |