Skip to content

Commit

Permalink
Merge typescript-template into repo (#66)
Browse files Browse the repository at this point in the history
Merge in typescript template updates
  • Loading branch information
thomasridd authored Feb 9, 2024
1 parent 19ba19c commit 8c8d5c4
Show file tree
Hide file tree
Showing 44 changed files with 791 additions and 430 deletions.
13 changes: 8 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ parameters:

node-version:
type: string
default: 20.10-browsers
default: 20.11-browsers

jobs:
build:
Expand Down Expand Up @@ -72,9 +72,8 @@ jobs:

integration_test:
executor:
name: hmpps/node_redis
node_tag: << pipeline.parameters.node-version >>
redis_tag: "7.0"
name: hmpps/node
tag: << pipeline.parameters.node-version >>
steps:
- checkout
- attach_workspace:
Expand All @@ -86,7 +85,7 @@ jobs:
key: dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Get wiremock
command: curl -o wiremock.jar https://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-standalone/2.27.1/wiremock-standalone-2.27.1.jar
command: curl -o wiremock.jar https://repo1.maven.org/maven2/org/wiremock/wiremock-standalone/3.3.1/wiremock-standalone-3.3.1.jar
- run:
name: Run wiremock
command: java -jar wiremock.jar --port 9091
Expand Down Expand Up @@ -172,6 +171,8 @@ workflows:
# env: "preprod"
# jira_update: true
# jira_env_type: staging
# pipeline_id: <<pipeline.id>>
# pipeline_number: <<pipeline.number>>
# context:
# - hmpps-common-vars
# - hmpps-authorization-preprod
Expand All @@ -187,6 +188,8 @@ workflows:
# env: "prod"
# jira_update: true
# jira_env_type: production
# pipeline_id: <<pipeline.id>>
# pipeline_number: <<pipeline.number>>
# slack_notification: true
# slack_channel_name: << pipeline.parameters.releases-slack-channel >>
# context:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage: base image
FROM node:20.10-bullseye-slim as base
FROM node:20.11-bullseye-slim as base

ARG BUILD_NUMBER
ARG GIT_REF
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ And then, to build the assets and start the app with nodemon:

### Running integration tests

For local running, start a test db, redis, and wiremock instance by:
For local running, start a test db and wiremock instance by:

`docker compose -f docker-compose-test.yml up`

Expand Down
1 change: 1 addition & 0 deletions assets/js/mojFrontendInit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.MOJFrontend.initAll()
2 changes: 0 additions & 2 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export default defineConfig({
},
taskTimeout: 60000,
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on) {
on('task', {
reset: resetStubs,
Expand Down
8 changes: 0 additions & 8 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
version: '3.1'
services:

redis:
image: 'redis:7.2'
networks:
- hmpps_int
ports:
- '6379:6379'

wiremock:
image: wiremock/wiremock
networks:
Expand Down
20 changes: 1 addition & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ services:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- '6379:6379'

hmpps-auth:
image: quay.io/hmpps/hmpps-auth:latest
networks:
Expand All @@ -24,23 +23,6 @@ services:
- SPRING_PROFILES_ACTIVE=dev
- APPLICATION_AUTHENTICATION_UI_ALLOWLIST=0.0.0.0/0

manage-users-api:
image: quay.io/hmpps/hmpps-manage-users-api:latest
networks:
- hmpps
container_name: manage-users-api_mhaa
depends_on:
- hmpps-auth
ports:
- "9091:8080"
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:8080/health" ]
environment:
- SERVER_PORT=8080
- SPRING_PROFILES_ACTIVE=dev
- HMPPS_AUTH_ENDPOINT_URL=http://hmpps-auth:8080/auth
- EXTERNAL_USERS_ENDPOINT_URL=http://hmpps-external-users-api:8080

app:
build:
context: .
Expand All @@ -56,9 +38,9 @@ services:
environment:
- PRODUCT_ID=UNASSIGNED
- REDIS_HOST=redis
- REDIS_ENABLED=false
- HMPPS_AUTH_EXTERNAL_URL=http://localhost:9090/auth
- HMPPS_AUTH_URL=http://hmpps-auth:8080/auth
# These will need to match new creds in the seed auth service auth
- API_CLIENT_ID=client-id
- API_CLIENT_SECRET=client-secret
- SYSTEM_CLIENT_ID=system-client-id
Expand Down
1 change: 1 addition & 0 deletions feature.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ HMPPS_AUTHORIZATION_SERVER_URL=http://localhost:9091/baseClientsApi
MANAGE_USERS_API_URL=http://localhost:9091/manage-users-api
TOKEN_VERIFICATION_API_URL=http://localhost:9091/verification
TOKEN_VERIFICATION_ENABLED=true
REDIS_ENABLED=false
NODE_ENV=development
API_CLIENT_ID=clientid
API_CLIENT_SECRET=clientsecret
Expand Down
1 change: 0 additions & 1 deletion helm_deploy/values-preprod.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
# Per environment values which override defaults in hmpps-authorization/values.yaml

generic-service:
Expand Down
1 change: 0 additions & 1 deletion helm_deploy/values-prod.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
# Per environment values which override defaults in hmpps-authorization/values.yaml

generic-service:
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/e2e/add-base-client.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ context('Add client page', () => {
})

it('Expiry days input is shown if checkbox is selected', () => {
addBaseClientDetailsPage.configDoesExpireCheckbox().click()
addBaseClientDetailsPage.configDoesExpireLabel().click()
addBaseClientDetailsPage.configExpiryDaysInput().should('be.visible')
})
})
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/e2e/edit-base-client-details.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AuthSignInPage from '../pages/authSignIn'
import AuthErrorPage from '../pages/authError'

const visitEditBaseClientDetailsPage = (): EditBaseClientDetailsPage => {
cy.signIn({ failOnStatusCode: true, redirectPath: '/base-clients/base_client_id_1/edit' })
cy.signIn({ failOnStatusCode: false, redirectPath: '/base-clients/base_client_id_1/edit' })
return Page.verifyOnPage(EditBaseClientDetailsPage)
}

Expand Down Expand Up @@ -43,6 +43,7 @@ context('Edit base client details page - client-credentials flow', () => {
cy.task('stubListBaseClients')
cy.task('stubGetBaseClient', { grantType: GrantTypes.ClientCredentials })
cy.task('stubGetListClientInstancesList')
cy.task('stubAuthManageDetails')
editBaseClientDetailsPage = visitEditBaseClientDetailsPage()
})

Expand Down
13 changes: 11 additions & 2 deletions integration_tests/e2e/health.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ context('Healthcheck', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubAuthPing')
cy.task('stubManageUsersPing')
cy.task('stubTokenVerificationPing')
})

it('Health check page is visible', () => {
it('Health check page is visible and UP', () => {
cy.request('/health').its('body.status').should('equal', 'UP')
})

Expand All @@ -20,16 +21,24 @@ context('Healthcheck', () => {
})

context('Some unhealthy', () => {
it('Reports correctly when token verification down', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubAuthPing')
cy.task('stubManageUsersPing')
cy.task('stubTokenVerificationPing', 500)
})

it('Reports correctly when token verification down', () => {
cy.request({ url: '/health', method: 'GET', failOnStatusCode: false }).then(response => {
expect(response.body.components.hmppsAuth.status).to.equal('UP')
expect(response.body.components.manageUsersApi.status).to.equal('UP')
expect(response.body.components.tokenVerification.status).to.equal('DOWN')
expect(response.body.components.tokenVerification.details).to.contain({ status: 500, retries: 2 })
})
})

it('Health check page is visible and DOWN', () => {
cy.request({ url: '/health', method: 'GET', failOnStatusCode: false }).its('body.status').should('equal', 'DOWN')
})
})
})
1 change: 1 addition & 0 deletions integration_tests/e2e/login.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ context('SignIn', () => {
cy.task('stubListBaseClients')
cy.task('stubGetBaseClient', { grantType: GrantTypes.ClientCredentials })
cy.task('stubManageUser')
cy.task('stubAuthManageDetails')
})

it('Unauthenticated user directed to auth', () => {
Expand Down
76 changes: 76 additions & 0 deletions integration_tests/e2e/signIn.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import IndexPage from '../pages/index'
import AuthSignInPage from '../pages/authSignIn'
import Page from '../pages/page'
import AuthManageDetailsPage from '../pages/authManageDetails'

context('Sign In', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubManageUser')
cy.task('stubListBaseClients')
})

it('Unauthenticated user directed to auth', () => {
cy.visit('/')
Page.verifyOnPage(AuthSignInPage)
})

it('Unauthenticated user navigating to sign in page directed to auth', () => {
cy.visit('/sign-in')
Page.verifyOnPage(AuthSignInPage)
})

it('User name visible in header', () => {
cy.signIn()
const indexPage = Page.verifyOnPage(IndexPage)
indexPage.headerUserName().should('contain.text', 'J. Smith')
})

it('Phase banner visible in header', () => {
cy.signIn()
const indexPage = Page.verifyOnPage(IndexPage)
indexPage.headerPhaseBanner().should('contain.text', 'dev')
})

it('User can sign out', () => {
cy.signIn()
const indexPage = Page.verifyOnPage(IndexPage)
indexPage.signOut().click()
Page.verifyOnPage(AuthSignInPage)
})

it('User can manage their details', () => {
cy.signIn()
cy.task('stubAuthManageDetails')
const indexPage = Page.verifyOnPage(IndexPage)

indexPage.manageDetails().get('a').invoke('removeAttr', 'target')
indexPage.manageDetails().click()
Page.verifyOnPage(AuthManageDetailsPage)
})

it('Token verification failure takes user to sign in page', () => {
cy.signIn()
Page.verifyOnPage(IndexPage)
cy.task('stubVerifyToken', false)

// can't do a visit here as cypress requires only one domain
cy.request('/').its('body').should('contain', 'Sign in')
})

it('Token verification failure clears user session', () => {
cy.signIn()
const indexPage = Page.verifyOnPage(IndexPage)
cy.task('stubVerifyToken', false)

// can't do a visit here as cypress requires only one domain
cy.request('/').its('body').should('contain', 'Sign in')

cy.task('stubVerifyToken', true)
cy.task('stubManageUser', 'bobby brown')
cy.signIn()

indexPage.headerUserName().contains('B. Brown')
})
})
11 changes: 5 additions & 6 deletions integration_tests/mockApis/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const redirect = () =>
'Content-Type': 'text/html',
Location: 'http://localhost:3007/sign-in/callback?code=codexxxx&state=stateyyyy',
},
body: '<html><body>SignIn page<h1>Sign in</h1></body></html>',
body: '<html><body>Sign in page<h1>Sign in</h1></body></html>',
},
})

Expand All @@ -78,7 +78,7 @@ const signOut = () =>
headers: {
'Content-Type': 'text/html',
},
body: '<html><body>SignIn page<h1>Sign in</h1></body></html>',
body: '<html><body>Sign in page<h1>Sign in</h1></body></html>',
},
})

Expand Down Expand Up @@ -122,8 +122,7 @@ const token = (roles: string[] = []) =>
export default {
getSignInUrl,
stubAuthPing: ping,
stubSignIn: (
roles: string[] = ['ROLE_OAUTH_ADMIN'],
): Promise<[Response, Response, Response, Response, Response, Response]> =>
Promise.all([favicon(), redirect(), signOut(), manageDetails(), token(roles), tokenVerification.stubVerifyToken()]),
stubSignIn: (roles: string[] = ['ROLE_OAUTH_ADMIN']): Promise<[Response, Response, Response, Response, Response]> =>
Promise.all([favicon(), redirect(), signOut(), token(roles), tokenVerification.stubVerifyToken()]),
stubAuthManageDetails: manageDetails,
}
2 changes: 2 additions & 0 deletions integration_tests/pages/addBaseClientDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default class AddBaseClientDetailsPage extends Page {

configDoesExpireCheckbox = (): PageElement => cy.get('[data-qa="config-does-expire-checkbox"]')

configDoesExpireLabel = (): PageElement => cy.get('[data-qa="config-does-expire-label"]')

configExpiryDaysInput = (): PageElement => cy.get('[data-qa="config-expiry-days-input"]')

configAllowedIpsInput = (): PageElement => cy.get('[data-qa="config-allowed-ips-input"]')
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/pages/editBaseClientDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default class EditBaseClientDetailsPage extends Page {

configExpiryDaysInput = (): PageElement => cy.get('[data-qa="config-expiry-days-input"]')

configDoesExpireLabel = (): PageElement => cy.get('[data-qa="config-does-expire-label"]')

configAllowedIpsInput = (): PageElement => cy.get('[data-qa="config-allowed-ips-input"]')

saveButton = (): PageElement => cy.get('[data-qa="save-button"]')
Expand Down
Loading

0 comments on commit 8c8d5c4

Please sign in to comment.