Skip to content

Commit

Permalink
MIA-85: Key Worker homepage RBAC (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
JackReeveMoJ authored Jan 21, 2025
1 parent c3f8774 commit 8734cbc
Show file tree
Hide file tree
Showing 16 changed files with 376 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,6 @@ integration_tests/screenshots/
*/*.iml
**/Chart.lock
**/.DS_Store

# wiremock
wiremock.jar
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ Or run tests with the cypress UI:

`npm run int-test-ui`

## Syncing API types with swagger

Run `npm run swagger` to pull the latest typedefs from the api backend.

## Change log

A changelog for the service is available [here](./CHANGELOG.md)
2 changes: 1 addition & 1 deletion integration_tests/e2e/signIn.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ context('Sign In', () => {
cy.task('stubVerifyToken', true)
cy.task('stubSignIn', { name: 'bobby brown' })

cy.signIn()
cy.signIn({ failOnStatusCode: false })

indexPage.headerUserName().contains('B. Brown')
})
Expand Down
5 changes: 4 additions & 1 deletion integration_tests/mockApis/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Response } from 'superagent'

import { stubFor, getMatchingRequests } from './wiremock'
import tokenVerification from './tokenVerification'
import AuthorisedRoles from '../../server/authentication/authorisedRoles'

interface UserToken {
name?: string
Expand Down Expand Up @@ -158,7 +159,9 @@ export default {
getSignInUrl,
stubAuthPing: ping,
stubAuthManageDetails: manageDetails,
stubSignIn: (userToken: UserToken = {}): Promise<[Response, Response, Response, Response, Response, Response]> =>
stubSignIn: (
userToken: UserToken = { roles: [AuthorisedRoles.KEYWORKER_MONITOR] },
): Promise<[Response, Response, Response, Response, Response, Response]> =>
Promise.all([
favicon(),
redirect(),
Expand Down
29 changes: 29 additions & 0 deletions integration_tests/mockApis/keyworkerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,35 @@ const stubKeyworkerApiHealth = () =>
},
})

const stubKeyworkerApiStatusIsKeyworker = (isKeyworker: boolean) =>
stubFor({
request: {
method: 'GET',
urlPattern: '/keyworker-api/prisons/LEI/key-workers/USER1/status',
},
response: {
status: 200,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: { isKeyworker },
},
})

const stubKeyworkerApiStatusFail = () =>
stubFor({
request: {
method: 'GET',
urlPattern: '/keyworker-api/prisons/LEI/key-workers/USER1/status',
},
response: {
status: 500,
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: {},
},
})

export default {
stubKeyworkerApiHealth,
stubKeyworkerApiStatusIsKeyworker: () => stubKeyworkerApiStatusIsKeyworker(true),
stubKeyworkerApiStatusIsNotKeyworker: () => stubKeyworkerApiStatusIsKeyworker(false),
stubKeyworkerApiStatusFail: () => stubKeyworkerApiStatusFail(),
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"int-test": "cypress run --config video=false",
"int-test-ui": "cypress open --e2e --browser chrome",
"clean": "rm -rf dist node_modules",
"rebuild": "npm run clean && npm i && npm run build"
"rebuild": "npm run clean && npm i && npm run build",
"swagger": "npx openapi-typescript https://keyworker-api-dev.prison.service.justice.gov.uk/v3/api-docs > ./server/@types/keyWorker/index.d.ts"
},
"engines": {
"node": "^22",
Expand Down
Loading

0 comments on commit 8734cbc

Please sign in to comment.