Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion designer/server/src/lib/metrics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config from '~/src/config.js'
import { getJson } from '~/src/lib/fetch.js'
import { getJson, postJson } from '~/src/lib/fetch.js'
import { getHeaders } from '~/src/lib/utils.js'

const metricsEndpoint = new URL('/report/', config.auditUrl)

Expand All @@ -18,6 +19,17 @@ export async function getMetrics() {
return body
}

/**
* Regenerate the full set of metrics afresh (clears the 'mertics' DB and repopulates)
* @param {string} token
*/
export async function regenerateMetrics(token) {
const requestUrl = new URL('regenerate', metricsEndpoint)
await postJson(requestUrl, {
...getHeaders(token)
})
}

/**
* @import { FormOverviewMetric, FormTotalsMetric } from '@defra/forms-model'
*/
19 changes: 17 additions & 2 deletions designer/server/src/lib/metrics.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import config from '~/src/config.js'
import {
createMockResponse,
mockedGetJson
mockedGetJson,
mockedPostJson
} from '~/src/lib/__stubs__/editor.js'
import { getMetrics } from '~/src/lib/metrics.js'
import { getMetrics, regenerateMetrics } from '~/src/lib/metrics.js'

jest.mock('~/src/lib/fetch.js')

Expand All @@ -23,4 +24,18 @@ describe('metrics.js', () => {
expect(mockedGetJson).toHaveBeenCalledWith(expectedUrl)
})
})

describe('regenerateMetrics', () => {
it('should call endpoint', async () => {
mockedPostJson.mockResolvedValueOnce({
response: createMockResponse(),
body: {}
})
const expectedUrl = new URL('/report/regenerate', auditEndpoint)
await regenerateMetrics('token')
expect(mockedPostJson).toHaveBeenCalledWith(expectedUrl, {
headers: { Authorization: 'Bearer token' }
})
})
})
})
11 changes: 6 additions & 5 deletions designer/server/src/models/admin/metrics-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ const formStructureMetricNames =
questionTypes: 'Question types per form'
})

const straplineWording = {
[FormMetricName.NewFormsCreated]: { noun: 'form', verb: 'created' },
[FormMetricName.FormsPublished]: { noun: 'form', verb: 'published' },
[FormMetricName.Submissions]: { noun: 'submission', verb: '' }
}
const straplineWording =
/** @type {Record<FormMetricName, { noun: string, verb: string}>} */ ({
[FormMetricName.NewFormsCreated]: { noun: 'form', verb: 'created' },
[FormMetricName.FormsPublished]: { noun: 'form', verb: 'published' },
[FormMetricName.Submissions]: { noun: 'submission', verb: '' }
})
/**
* @typedef PeriodName
* @property {string} ariaPeriodName - period name within aria label
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,284 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Form metrics routes GET should render form 1`] = `
exports[`Form metrics routes form-metrics should render regenerate form 1`] = `
"<!DOCTYPE html>
<html lang="en" class="govuk-template">
<head>
<meta charset="utf-8">
<title>Admin tools - Defra Form Designer metrics - Forms designer</title>
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#0b0c0c">

<link rel="icon" sizes="48x48" href="/assets/images/favicon.ico">
<link rel="icon" sizes="any" href="/assets/images/favicon.svg" type="image/svg+xml">
<link rel="mask-icon" href="/assets/images/govuk-icon-mask.svg" color="#0b0c0c">
<link rel="apple-touch-icon" href="/assets/images/govuk-icon-180.png">
<link rel="manifest" href="/assets/manifest.json">

<meta name="application-name" content="@defra/forms-designer" data-environment="local">
<meta name="robots" content="noindex, nofollow">
<link href="/stylesheets/application.scss" rel="stylesheet">

</head>
<body class="govuk-template__body">
<script>document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : '');</script>

<a href="#main-content" class="govuk-skip-link" data-module="govuk-skip-link">Skip to main content</a>


<header class="cross-service-header" role="banner" data-module="one-login-header">
<div class="one-login-header" data-one-login-header-nav>
<div class="one-login-header__container govuk-width-container app-width-container--wide">
<div class="one-login-header__logo">
<a href="/" class="one-login-header__link one-login-header__link--homepage">
<span class="one-login-header__logotype">
<!--[if gt IE 8]><!-->
<svg
aria-hidden="true"
focusable="false"
class="one-login-header__logotype-crown"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 32 30"
height="30"
width="32">
<path fill="currentColor" fill-rule="evenodd" d="M22.6 10.4c-1 .4-2-.1-2.4-1-.4-.9.1-2 1-2.4.9-.4 2 .1 2.4 1s-.1 2-1 2.4m-5.9 6.7c-.9.4-2-.1-2.4-1-.4-.9.1-2 1-2.4.9-.4 2 .1 2.4 1s-.1 2-1 2.4m10.8-3.7c-1 .4-2-.1-2.4-1-.4-.9.1-2 1-2.4.9-.4 2 .1 2.4 1s0 2-1 2.4m3.3 4.8c-1 .4-2-.1-2.4-1-.4-.9.1-2 1-2.4.9-.4 2 .1 2.4 1s-.1 2-1 2.4M17 4.7l2.3 1.2V2.5l-2.3.7-.2-.2.9-3h-3.4l.9 3-.2.2c-.1.1-2.3-.7-2.3-.7v3.4L15 4.7c.1.1.1.2.2.2l-1.3 4c-.1.2-.1.4-.1.6 0 1.1.8 2 1.9 2.2h.7c1-.2 1.9-1.1 1.9-2.1 0-.2 0-.4-.1-.6l-1.3-4c-.1-.2 0-.2.1-.3m-7.6 5.7c.9.4 2-.1 2.4-1 .4-.9-.1-2-1-2.4-.9-.4-2 .1-2.4 1s0 2 1 2.4m-5 3c.9.4 2-.1 2.4-1 .4-.9-.1-2-1-2.4-.9-.4-2 .1-2.4 1s.1 2 1 2.4m-3.2 4.8c.9.4 2-.1 2.4-1 .4-.9-.1-2-1-2.4-.9-.4-2 .1-2.4 1s0 2 1 2.4m14.8 11c4.4 0 8.6.3 12.3.8 1.1-4.5 2.4-7 3.7-8.8l-2.5-.9c.2 1.3.3 1.9 0 2.7-.4-.4-.8-1.1-1.1-2.3l-1.2 4c.7-.5 1.3-.8 2-.9-1.1 2.5-2.6 3.1-3.5 3-1.1-.2-1.7-1.2-1.5-2.1.3-1.2 1.5-1.5 2.1-.1 1.1-2.3-.8-3-2-2.3 1.9-1.9 2.1-3.5.6-5.6-2.1 1.6-2.1 3.2-1.2 5.5-1.2-1.4-3.2-.6-2.5 1.6.9-1.4 2.1-.5 1.9.8-.2 1.1-1.7 2.1-3.5 1.9-2.7-.2-2.9-2.1-2.9-3.6.7-.1 1.9.5 2.9 1.9l.4-4.3c-1.1 1.1-2.1 1.4-3.2 1.4.4-1.2 2.1-3 2.1-3h-5.4s1.7 1.9 2.1 3c-1.1 0-2.1-.2-3.2-1.4l.4 4.3c1-1.4 2.2-2 2.9-1.9-.1 1.5-.2 3.4-2.9 3.6-1.9.2-3.4-.8-3.5-1.9-.2-1.3 1-2.2 1.9-.8.7-2.3-1.2-3-2.5-1.6.9-2.2.9-3.9-1.2-5.5-1.5 2-1.3 3.7.6 5.6-1.2-.7-3.1 0-2 2.3.6-1.4 1.8-1.1 2.1.1.2.9-.3 1.9-1.5 2.1-.9.2-2.4-.5-3.5-3 .6 0 1.2.3 2 .9l-1.2-4c-.3 1.1-.7 1.9-1.1 2.3-.3-.8-.2-1.4 0-2.7l-2.9.9C1.3 23 2.6 25.5 3.7 30c3.7-.5 7.9-.8 12.3-.8"></path>
</svg>
<!--<![endif]-->
<span class="one-login-header__logotype-text">
Defra
</span>
<span class="one-login-header__product-name">
Forms Designer <strong class="govuk-tag govuk-tag--green app-tag--env">
Local
</strong>
</span>
</span>
</a>
</div>
<button type="button"
aria-controls="one-login-header__nav"
aria-label="Show account menu"
data-open-class="cross-service-header__button--open"
data-label-for-show="Show account menu"
data-label-for-hide="Hide account menu"
aria-expanded="false"
class="cross-service-header__button cross-service-header__button--one-login js-x-header-toggle">
<span class="cross-service-header__button-content">Account</span>
<span class="cross-service-header__button-icon cross-service-header__button-icon--default">
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg" focusable="false" aria-hidden="true">
<circle cx="11" cy="11" r="11" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.29297 18.8487C4.23255 15.4753 7.32741 13 11.0004 13C14.6731 13 17.7678 15.4749 18.7076 18.848C17.8058 19.7338 16.752 20.4654 15.5889 21H11.0004H6.41097C5.24819 20.4655 4.19463 19.7342 3.29297 18.8487Z" fill="#008531"/>
<circle cx="11" cy="7.75" r="3.75" fill="#008531"/>
<circle cx="11" cy="11" r="10" stroke="white" stroke-width="2"/>
</svg>
</span>
<span class="cross-service-header__button-icon cross-service-header__button-icon--focus">
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg" focusable="false" aria-hidden="true">
<circle cx="11" cy="11" r="11" fill="black"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.29297 18.8487C4.23255 15.4753 7.32741 13 11.0004 13C14.6731 13 17.7678 15.4749 18.7076 18.848C17.8058 19.7338 16.752 20.4654 15.5889 21H11.0004H6.41097C5.24819 20.4655 4.19463 19.7342 3.29297 18.8487Z" fill="white"/>
<circle cx="11" cy="7.75" r="3.75" fill="white"/>
<circle cx="11" cy="11" r="10" stroke="black" stroke-width="2"/>
</svg>
</span>
</button>
<nav aria-label="Account menu" class="one-login-header__nav" data-open-class="one-login-header__nav--open" id="one-login-header__nav">
<ul class="one-login-header__nav__list">
<li class="one-login-header__nav__list-item">
<a class="one-login-header__nav__link one-login-header__nav__link--one-login" href="/auth/account">
<span class="one-login-header__nav__link-content">
John Smith
</span>
<span class="cross-service-header__button-icon cross-service-header__button-icon--default">
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg" focusable="false" aria-hidden="true">
<circle cx="11" cy="11" r="11" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.29297 18.8487C4.23255 15.4753 7.32741 13 11.0004 13C14.6731 13 17.7678 15.4749 18.7076 18.848C17.8058 19.7338 16.752 20.4654 15.5889 21H11.0004H6.41097C5.24819 20.4655 4.19463 19.7342 3.29297 18.8487Z" fill="#008531"/>
<circle cx="11" cy="7.75" r="3.75" fill="#008531"/>
<circle cx="11" cy="11" r="10" stroke="white" stroke-width="2"/>
</svg>
</span>
<span class="cross-service-header__button-icon cross-service-header__button-icon--focus">
<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg" focusable="false" aria-hidden="true">
<circle cx="11" cy="11" r="11" fill="black"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.29297 18.8487C4.23255 15.4753 7.32741 13 11.0004 13C14.6731 13 17.7678 15.4749 18.7076 18.848C17.8058 19.7338 16.752 20.4654 15.5889 21H11.0004H6.41097C5.24819 20.4655 4.19463 19.7342 3.29297 18.8487Z" fill="white"/>
<circle cx="11" cy="7.75" r="3.75" fill="white"/>
<circle cx="11" cy="11" r="10" stroke="black" stroke-width="2"/>
</svg>
</span>
</a>
</li>
<li class="one-login-header__nav__list-item">
<a class="one-login-header__nav__link" href="/admin/index">
System admin
</a>
</li>
<li class="one-login-header__nav__list-item">
<a class="one-login-header__nav__link" href="/auth/sign-out">
Sign out
</a>
</li>
</ul>
</nav>
</div>
</div>
<!-- Start of service navigation -->
<div class="service-header" data-one-login-header-nav>
<div class="govuk-width-container app-width-container--wide">
<div class="service-header__container"> <div>
<!-- Label the toggle button appropriately (you might want to use the name of your service) to provide support for screen reader users -->
<button type="button"
aria-controls="service-header__nav"
data-open-class="cross-service-header__button--open"
aria-label="Show service navigation menu"
data-label-for-show="Show service navigation menu"
data-label-for-hide="Hide service navigation menu"
data-text-for-show="Menu"
data-text-for-hide="Close"
aria-expanded="false"
class="cross-service-header__button cross-service-header__button--service-header js-x-header-toggle">
<span class="service-header__button-content">Menu</span>
</button>
<!-- Important! Label your navigation appropriately! When there are multiple navigation landmarks on a page, additional labelling is required to provide support for screen reader users -->
<nav aria-label=" menu">
<ul class="service-header__nav-list service-header__nav" id="service-header__nav" data-open-class="service-header__nav--open"> <!-- Use the "service-header__nav-list-item--active" modifier class on the li to visually highlight the page the user is currently viewing -->
<li class="service-header__nav-list-item">
<!-- Use the aria-current="page" attribute on the anchor tag -->
<a class="service-header__nav-list-item-link" href="/auth/account">
My account
</a>
</li> <!-- Use the "service-header__nav-list-item--active" modifier class on the li to visually highlight the page the user is currently viewing -->
<li class="service-header__nav-list-item">
<!-- Use the aria-current="page" attribute on the anchor tag -->
<a class="service-header__nav-list-item-link" href="/manage/users">
Manage users
</a>
</li> <!-- Use the "service-header__nav-list-item--active" modifier class on the li to visually highlight the page the user is currently viewing -->
<li class="service-header__nav-list-item service-header__nav-list-item--active">
<!-- Use the aria-current="page" attribute on the anchor tag -->
<a class="service-header__nav-list-item-link"aria-current="page" href="/admin/index">
Admin tools
</a>
</li> <!-- Use the "service-header__nav-list-item--active" modifier class on the li to visually highlight the page the user is currently viewing -->
<li class="service-header__nav-list-item">
<!-- Use the aria-current="page" attribute on the anchor tag -->
<a class="service-header__nav-list-item-link" href="/support">
Support
</a>
</li> </ul>
</nav>
</div>
</div>
</div>
</div>
<!-- End of service navigation -->
</header>



<main class="govuk-main-wrapper govuk-main-wrapper--masthead">





<div id="main-content" class="app-masthead">
<div class="govuk-width-container app-width-container--wide">
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<a href="/admin/index" class="govuk-back-link govuk-back-link--inverse govuk-!-margin-bottom-0">Back to admin tools</a>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible back-link-hr">
</div>
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="app-masthead__heading govuk-heading-xl">
Defra Form Designer metrics
</h1>
<div class="govuk-button-group"></div>
</div>
</div>
</div>
</div>


<div class="govuk-width-container app-width-container--wide">
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">

<form method="post">
<h2 class="govuk-heading-l">Regenerating metrics</h2>
<p class="govuk-body">This will clear out the 'metrics' collection in the 'forms-audit-api' database, and regenerate a full history of metrics.</p>

<button type="submit" class="govuk-button" data-module="govuk-button">
Regenerate metrics
</button>
</form>


</div>
</div>

</div>


</main>





<footer class="govuk-footer">
<div class="govuk-width-container app-width-container--wide">
<div class="govuk-footer__meta">
<div class="govuk-footer__meta-item govuk-footer__meta-item--grow">
<h2 class="govuk-visually-hidden">Support links</h2>
<ul class="govuk-footer__inline-list">
<li class="govuk-footer__inline-list-item">
<a class="govuk-footer__link" href="/help/accessibility-statement">
Accessibility statement
</a>
</li>
</ul>
<svg
aria-hidden="true"
focusable="false"
class="govuk-footer__licence-logo"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 483.2 195.7"
height="17"
width="41"
>
<path
fill="currentColor"
d="M421.5 142.8V.1l-50.7 32.3v161.1h112.4v-50.7zm-122.3-9.6A47.12 47.12 0 0 1 221 97.8c0-26 21.1-47.1 47.1-47.1 16.7 0 31.4 8.7 39.7 21.8l42.7-27.2A97.63 97.63 0 0 0 268.1 0c-36.5 0-68.3 20.1-85.1 49.7A98 98 0 0 0 97.8 0C43.9 0 0 43.9 0 97.8s43.9 97.8 97.8 97.8c36.5 0 68.3-20.1 85.1-49.7a97.76 97.76 0 0 0 149.6 25.4l19.4 22.2h3v-87.8h-80l24.3 27.5zM97.8 145c-26 0-47.1-21.1-47.1-47.1s21.1-47.1 47.1-47.1 47.2 21 47.2 47S123.8 145 97.8 145"
/>
</svg>
<span class="govuk-footer__licence-description">
All content is available under the
<a
class="govuk-footer__link"
href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/"
rel="license"
>Open Government Licence v3.0</a>, except where otherwise stated
</span>
</div>
<div class="govuk-footer__meta-item">
<a
class="govuk-footer__link govuk-footer__copyright-logo"
href="https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/"
>
© Crown copyright
</a>
</div>
</div>
</div>
</footer>


<script type="module" src="/application.js"></script>
</body>
</html>
"
`;

exports[`Form metrics routes form-metrics should render report form 1`] = `
"<!DOCTYPE html>
<html lang="en" class="govuk-template">
<head>
Expand Down
Loading
Loading