Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCM-7465: implement backend api PT.2 #260

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8fd1458
CCM-7465: use JWT sub as owner field in ddb
bhansell1 Dec 18, 2024
1e04f87
CCM-7465: use subject for owner
bhansell1 Dec 19, 2024
33bd151
CCM-7465: remove undefined from API response
bhansell1 Dec 19, 2024
583b521
CCM-7465: implement backend api and update automated tests
bhansell1 Dec 20, 2024
e5252c3
CCM-7465: add dynamoDB to tf outputs and allow SRP auth flow. Which I…
bhansell1 Dec 20, 2024
d99ed4f
CCM-7465: update automated tests to check for logout link
bhansell1 Dec 20, 2024
9cb6154
CCM-7465: add the auth pages when in CI for automated tests
bhansell1 Dec 20, 2024
8ce2733
CCM-7465: don't build the backend
bhansell1 Dec 20, 2024
0c9b889
CCM-7465: don't deploy backend resources
bhansell1 Dec 20, 2024
6b8eeb2
CCM-7465: don't deploy backend resources
bhansell1 Dec 20, 2024
73544b6
CCM-7465: don't deploy backend resources
bhansell1 Dec 20, 2024
6be7690
CCM-7465: don't deploy backend resources
bhansell1 Dec 20, 2024
223bc6a
CCM-7465: don't deploy backend resources
bhansell1 Dec 20, 2024
c4c5cf3
CCM-7465: don't deploy backend resources
bhansell1 Dec 20, 2024
861937c
CCM-7465: add protected routes
bhansell1 Dec 20, 2024
cab3b5b
CCM-7465: add middleware
bhansell1 Dec 20, 2024
428cb83
CCM-7465: temporarily redirect back home
bhansell1 Dec 20, 2024
bbedfe9
CCM-7465: temporarily redirect back home
bhansell1 Dec 20, 2024
620f193
CCM-7465: set env vars required for amplify and next app
bhansell1 Jan 6, 2025
04cf3e6
CCM-7465: disable route protection
bhansell1 Jan 6, 2025
7cb6bb9
CCM-7465: change from bash to JS version of creating amplify outputs
bhansell1 Jan 7, 2025
3fb681c
CCM-7465: create a .env file for the CI tests
bhansell1 Jan 7, 2025
340e3ad
CCM-7465: clean up unused files
bhansell1 Jan 7, 2025
5b57282
Merge branch 'feature/CCM-7465_use-jwt-sub' of https://github.com/NHS…
bhansell1 Jan 7, 2025
5362455
CCM-7465: re-add protected routes
bhansell1 Jan 8, 2025
86eb40f
CCM-7465: add stdout logs to paywright for debugging
bhansell1 Jan 8, 2025
050dfe2
CCM-7465: add a 2 minute timeout for webserver load while debugging
bhansell1 Jan 8, 2025
49927ff
CCM-7465: remove authorization caching. Which is causing tests to fail
bhansell1 Jan 8, 2025
4c5abd4
CCM-7465: set retries to 3 to see if a retry helps with the tests.
bhansell1 Jan 9, 2025
61bd097
CCM-7465: fix automated test by creating a new page when asserting ba…
bhansell1 Jan 9, 2025
e3f8699
CCM-7465: update docs with tips. Fix linting and unit tests
bhansell1 Jan 9, 2025
1a83326
CCM-7465: pull meta from amplify_outputs in automated tests
bhansell1 Jan 9, 2025
bb724ad
CCM-7465: re-add redirect location when not signed in
bhansell1 Jan 9, 2025
5a5ec5a
CCM-7465: update token check in form-actions
bhansell1 Jan 9, 2025
c80a321
Merge branch 'main' of https://github.com/NHSDigital/nhs-notify-web-t…
bhansell1 Jan 9, 2025
b9424c8
CCM-7465: update artifacts upload to v4
bhansell1 Jan 9, 2025
2d61411
CCM-7465: force manage templates to be SSR'd
bhansell1 Jan 9, 2025
41b7cf4
CCM-7465: update common tests to assert logout link
bhansell1 Jan 10, 2025
78b44ae
Fix accessibility tests
chris-elliott-nhsd Jan 10, 2025
cfc1835
Fix deleted check
chris-elliott-nhsd Jan 10, 2025
ff5853e
CCM-7465: update ttl on api. Turn off automated tests debugging
bhansell1 Jan 10, 2025
ad03634
Merge branch 'feature/CCM-7465_use_backend-api' of https://github.com…
bhansell1 Jan 10, 2025
c4cae3d
CCM-7465: revert new'ing up page in common tests
bhansell1 Jan 10, 2025
ab3edef
empty
bhansell1 Jan 13, 2025
f627f0d
CCM-7465: change ubuntu version to 22.04 which has TF installed
bhansell1 Jan 13, 2025
8a4d509
CCM-7465: update timeouts to 30 seconds and 10 seconds for expect. Cr…
bhansell1 Jan 13, 2025
93c3969
CCM-7465: fix linting
bhansell1 Jan 13, 2025
892e12a
CCM-7465: revert change to create a new page.
bhansell1 Jan 13, 2025
f81c1dd
CCM-7465: update comment about forcing dynamically rendered page
bhansell1 Jan 13, 2025
cbf9d1c
CCM-7465: update logout link to redirect back to ~templates
bhansell1 Jan 14, 2025
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
2 changes: 1 addition & 1 deletion .github/actions/create-lines-of-code-report/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ runs:
run: zip lines-of-code-report.json.zip lines-of-code-report.json
- name: "Upload CLOC report as an artefact"
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub was failing due to V3 being depreciated.

with:
name: lines-of-code-report.json.zip
path: ./lines-of-code-report.json.zip
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/scan-dependencies/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ runs:
run: zip sbom-repository-report.json.zip sbom-repository-report.json
- name: "Upload SBOM report as an artefact"
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: sbom-repository-report.json.zip
path: ./sbom-repository-report.json.zip
Expand All @@ -47,7 +47,7 @@ runs:
run: zip vulnerabilities-repository-report.json.zip vulnerabilities-repository-report.json
- name: "Upload vulnerabilities report as an artefact"
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: vulnerabilities-repository-report.json.zip
path: ./vulnerabilities-repository-report.json.zip
Expand Down
91 changes: 21 additions & 70 deletions .github/workflows/stage-4-acceptance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,9 @@ permissions:
contents: read # This is required for actions/checkout

jobs:
environment-set-up:
name: "Environment set up"
runs-on: ubuntu-latest
environment: dev
timeout-minutes: 15
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Repo setup"
run: |
npm ci
- name: "Generate dependencies"
run: |
npm run generate-dependencies --workspaces --if-present
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ASSUME_ROLE_NAME }}
role-session-name: deployInfra
aws-region: ${{ env.AWS_REGION }}
- name: "Create Amplify sandbox"
run: |
./scripts/create_amplify_sandbox.sh
- uses: actions/upload-artifact@v4
with:
name: amplify_outputs.json
path: frontend/amplify_outputs.json

sandbox-set-up:
name: "Sandbox set up"
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #259

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the above PR is merged into main I'll revert this change.

environment: dev
timeout-minutes: 15
steps:
Expand All @@ -92,11 +64,10 @@ jobs:
with:
name: sandbox_tf_outputs.json
path: sandbox_tf_outputs.json

test-security:
name: "Security test"
runs-on: ubuntu-latest
needs: [environment-set-up, sandbox-set-up]
runs-on: ubuntu-22.04
needs: [sandbox-set-up]
timeout-minutes: 10
steps:
- name: "Checkout code"
Expand All @@ -109,17 +80,19 @@ jobs:
echo "Nothing to save"
test-accessibility:
name: "Accessibility test"
runs-on: ubuntu-latest
needs: [environment-set-up, sandbox-set-up]
runs-on: ubuntu-22.04
needs: [sandbox-set-up]
environment: dev
env:
INCLUDE_AUTH_PAGES: 'true'
timeout-minutes: 10
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: amplify_outputs.json
path: frontend/
name: sandbox_tf_outputs.json
path: ./
- name: "Repo setup"
run: |
npm ci
Expand All @@ -133,25 +106,29 @@ jobs:
role-session-name: deployInfra
aws-region: eu-west-2
- name: "Run accessibility test"
run: make test-accessibility
run: |
npm run create-amplify-outputs file
make test-accessibility
- name: Archive accessibility results
uses: actions/upload-artifact@v4
with:
name: accessibility
path: ".reports/accessibility"
test-ui-component:
name: "UI Component test"
runs-on: ubuntu-latest
needs: [environment-set-up, sandbox-set-up]
runs-on: ubuntu-22.04
needs: [sandbox-set-up]
environment: dev
env:
INCLUDE_AUTH_PAGES: 'true'
timeout-minutes: 10
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: amplify_outputs.json
path: frontend/
name: sandbox_tf_outputs.json
path: ./
- name: "Repo setup"
run: |
npm ci
Expand All @@ -168,45 +145,19 @@ jobs:
aws-region: eu-west-2
- name: "Run ui component test"
run: |
npm run create-amplify-outputs file
cd tests/test-team
npm run test:local-ui
- name: Archive component test results
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: component test report
path: "tests/test-team/playwright-report"
environment-tear-down:
name: "Environment tear down"
if: success() || failure()
runs-on: ubuntu-latest
needs: [test-accessibility, test-ui-component]
environment: dev
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: amplify_outputs.json
path: frontend/
- name: "Repo setup"
run: |
npm ci
- name: "Generate dependencies"
run: |
npm run generate-dependencies --workspaces --if-present
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ASSUME_ROLE_NAME }}
role-session-name: deployInfra
aws-region: eu-west-2
- name: "Destroy Amplify sandbox"
run: |
(cd frontend && npm run destroy-sandbox -- --identifier "wf-${GITHUB_RUN_ID}")
sandbox-tear-down:
name: "Sandbox tear down"
if: success() || failure()
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
needs: [test-accessibility, test-ui-component]
environment: dev
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ sandbox_cognito_auth_token.json

frontend/public/testing
.vscode/launch.json
auth.json
2 changes: 1 addition & 1 deletion amplify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ applications:
- nvm use 20.13.1
- npm ci --cache .npm --prefer-offline
- npm run generate-dependencies --workspaces --if-present
- npm run create-amplify-outputs env
- cd frontend
- npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
frontend:
phases:
build:
Expand Down
2 changes: 2 additions & 0 deletions frontend/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Includes auth pages when building web frontend in production mode.
INCLUDE_AUTH_PAGES=''
29 changes: 1 addition & 28 deletions frontend/amplify/backend.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
import { defineBackend } from '@aws-amplify/backend';
import { PolicyStatement, Effect } from 'aws-cdk-lib/aws-iam';
import { auth } from './auth/resource';
import { data } from './data/resource';
import { sendEmail } from './functions/send-email/resource';

const backend = defineBackend({
auth,
data,
sendEmail,
});

const sendEmailLambda = backend.sendEmail.resources.lambda;

const attachPolicy = new PolicyStatement({
sid: 'AmplifySendEmail',
effect: Effect.ALLOW,
actions: ['ses:SendRawEmail'],
resources: [`arn:aws:ses:eu-west-2:${process.env.ACCOUNT_ID}:identity/*`],
});

sendEmailLambda.addToRolePolicy(attachPolicy);

backend.data.resources.cfnResources.amplifyDynamoDbTables.TemplateStorage.timeToLiveAttribute =
{
attributeName: 'ttl',
enabled: true,
};
/* eslint-disable unicorn/no-empty-file */
8 changes: 6 additions & 2 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
/** @type {import('next').NextConfig} */

const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
const amplifyConfig = require('./amplify_outputs.json');

const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? '/templates';
const domain = process.env.NOTIFY_DOMAIN_NAME ?? 'localhost:3000';

const nextConfig = (phase) => {
const isDevServer = phase === PHASE_DEVELOPMENT_SERVER;
const includeAuthPages =
process.env.INCLUDE_AUTH_PAGES === 'true' || isDevServer;

return {
basePath,
env: {
basePath,
BACKEND_API_URL: amplifyConfig?.meta?.backend_api_url,
},

experimental: {
Expand All @@ -32,7 +36,7 @@ const nextConfig = (phase) => {
},

async rewrites() {
if (isDevServer) {
if (includeAuthPages) {
return [
{
source: '/auth/signout',
Expand All @@ -52,7 +56,7 @@ const nextConfig = (phase) => {

// pages with e.g. .dev.tsx extension are only included when running locally
pageExtensions: ['ts', 'tsx', 'js', 'jsx'].flatMap((extension) => {
return isDevServer ? [`dev.${extension}`, extension] : [extension];
return includeAuthPages ? [`dev.${extension}`, extension] : [extension];
}),
};
};
Expand Down
7 changes: 4 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint --dir .",
"lint:fix": "next lint --dir . --fix",
"test:unit": "jest",
"lint": "npm run mock-amplify-outputs && next lint --dir .",
"lint:fix": "npm run lint -- --fix",
"test:unit": "npm run mock-amplify-outputs && jest",
"app:start": "pm2 start npm -- start",
"app:wait": "wait-on -l http://localhost:3000/templates/create-and-submit-templates",
"app:stop": "pm2 kill",
Expand All @@ -29,6 +29,7 @@
"next": "14.2.13",
"nhs-notify-web-template-management-amplify": "*",
"nhs-notify-web-template-management-utils": "*",
"nhs-notify-backend-client": "*",
"nhsuk-frontend": "^8.3.0",
"nhsuk-react-components": "^4.1.1",
"path": "^0.12.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ test('calls form action and redirects', async () => {

await deleteTemplateAction(mockTemplate);

expect(mockSaveTemplate).toHaveBeenCalledWith(
{
...mockTemplate,
templateStatus: TemplateStatus.DELETED,
},
1_643_619_600
);
expect(mockSaveTemplate).toHaveBeenCalledWith({
...mockTemplate,
templateStatus: TemplateStatus.DELETED,
});

expect(mockRedirect).toHaveBeenCalledWith(
'/manage-templates',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ describe('submitTemplate', () => {

await submitTemplate('submit-route', formData);

expect(sendEmailMock).toHaveBeenCalledWith(
mockNhsAppTemplate.id,
mockNhsAppTemplate.name,
mockNhsAppTemplate.message,
null
);
expect(sendEmailMock).toHaveBeenCalledWith(mockNhsAppTemplate.id);

expect(redirectMock).toHaveBeenCalledWith('/submit-route/1', 'push');
});
Expand All @@ -120,11 +115,6 @@ describe('submitTemplate', () => {

await submitTemplate('submit-route', formData);

expect(sendEmailMock).toHaveBeenCalledWith(
mockEmailTemplate.id,
mockEmailTemplate.name,
mockEmailTemplate.message,
mockEmailTemplate.subject
);
expect(sendEmailMock).toHaveBeenCalledWith(mockEmailTemplate.id);
});
});
Loading
Loading