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

CDPS-387: Remove local mock data #329

Merged
merged 10 commits into from
Nov 2, 2023
2 changes: 2 additions & 0 deletions integration_tests/e2e/addAlertPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const visitAlertsPage = (): AlertsPage => {
context('Add Alert Page', () => {
beforeEach(() => {
cy.task('reset')
cy.setupBannerStubs({ prisonerNumber: 'G6123VU' })
cy.setupUserAuth({ roles: [Role.GlobalSearch, Role.UpdateAlert] })
})

Expand All @@ -21,6 +22,7 @@ context('Add Alert Page', () => {
let addAlertPage: AddAlertPage

beforeEach(() => {
cy.setupBannerStubs({ prisonerNumber: 'G6123VU' })
cy.setupAlertsPageStubs({ prisonerNumber: 'G6123VU', bookingId: 1102484 })
cy.task('stubGetAlertTypes')
cy.task('stubCreateAlert')
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/e2e/addCaseNotePage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ context('Add Case Note Page', () => {
beforeEach(() => {
cy.task('reset')
cy.setupUserAuth()
cy.task('stubGetCaseNotes', 'G6123VU')
cy.task('stubGetCaseNotesUsage', 'G6123VU')
cy.task('stubGetCaseNoteTypes')
cy.task('stubGetCaseNoteTypesForUser')
cy.task('stubAddCaseNote')
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/e2e/alertsPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const visitEmptyAlertsPage = () => {
context('Alerts Page - Permissions', () => {
context('Active alerts', () => {
const visitPage = prisonerDataOverrides => {
cy.setupBannerStubs({ prisonerNumber: 'G6123VU' })
cy.setupAlertsPageStubs({ prisonerNumber: 'G6123VU', bookingId: 1102484, prisonerDataOverrides })
visitActiveAlertsPage({ failOnStatusCode: false })
}
Expand All @@ -35,6 +36,7 @@ context('Alerts Page - User does not have Update Alerts role', () => {
beforeEach(() => {
cy.task('reset')
cy.setupUserAuth()
cy.setupBannerStubs({ prisonerNumber: 'G6123VU' })
})

context('Active Alerts', () => {
Expand Down Expand Up @@ -119,6 +121,7 @@ context('Alerts Page - User does not have Update Alerts role', () => {

beforeEach(() => {
cy.setupAlertsPageStubs({ prisonerNumber: 'A1234BC', bookingId: 1234567 })
cy.setupBannerStubs({ prisonerNumber: 'G6123VU', bookingId: 1234567 })
visitEmptyAlertsPage()
alertsPage = Page.verifyOnPageWithTitle(AlertsPage, 'Active alerts')
})
Expand Down Expand Up @@ -209,6 +212,7 @@ context('Alerts Page - User has Update Alert role', () => {
roles: [Role.PrisonUser, Role.UpdateAlert],
caseLoads: [{ caseloadFunction: '', caseLoadId: 'MDI', currentlyActive: true, description: '', type: '' }],
})
cy.setupBannerStubs({ prisonerNumber: 'G6123VU' })
cy.setupAlertsPageStubs({ prisonerNumber: 'G6123VU', bookingId: 1102484 })
visitActiveAlertsPage()
alertsPage = Page.verifyOnPageWithTitle(AlertsPage, 'Active alerts')
Expand Down
1 change: 1 addition & 0 deletions integration_tests/e2e/personalPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ context('When signed in', () => {
cy.task('stubHealthTreatmentReferenceDomain')
cy.task('stubReasonableAdjustments', 1102484)
cy.task('stubPersonalCareNeeds', 1102484)
cy.task('stubIdentifiers', 1102484)
visitPersonalDetailsPage()
})

Expand Down
7 changes: 5 additions & 2 deletions integration_tests/e2e/photoPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ context('Photo Page', () => {
const bookingId = 1102484

context('Permissions', () => {
const visitPage = () => cy.signIn({ failOnStatusCode: false, redirectPath: 'prisoner/G6123VU/image' })
const visitPage = prisonerDataOverrides => {
cy.setupBannerStubs({ prisonerNumber, bookingId, prisonerDataOverrides })
cy.signIn({ failOnStatusCode: false, redirectPath: 'prisoner/G6123VU/image' })
}
permissionsTests({ prisonerNumber, visitPage, pageToDisplay: PrisonerPhotoPage })
})

beforeEach(() => {
cy.task('reset')
cy.setupUserAuth()
cy.setupBannerStubs({ prisonerNumber })
cy.setupBannerStubs({ prisonerNumber, bookingId })
cy.setupOverviewPageStubs({ prisonerNumber, bookingId })
})

Expand Down
1 change: 1 addition & 0 deletions integration_tests/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare global {
setupBannerStubs(options: {
prisonerNumber: string
prisonerDataOverrides?: Partial<Prisoner>
bookingId?: number
}): Chainable<AUTWindow>
setupOverviewPageStubs(options: {
prisonerNumber: string
Expand Down
18 changes: 17 additions & 1 deletion integration_tests/mockApis/prison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ export default {
return stubFor({
request: {
method: 'GET',
urlPattern: `/prison/api/agencies/${agencyId}\\?activeOnly=false`,
urlPattern: `/prison/api/agencies/${agencyId}\\?.*`,
},
response: {
status: 200,
Expand Down Expand Up @@ -1132,4 +1132,20 @@ export default {
},
})
},

stubIdentifiers: (bookingId: number) => {
return stubFor({
request: {
method: 'GET',
urlPattern: `/prison/api/bookings/${bookingId}/identifiers`,
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: identifiersMock,
},
})
},
}
4 changes: 3 additions & 1 deletion integration_tests/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ Cypress.Commands.add('signIn', (options = { failOnStatusCode: true, redirectPath
return cy.task('getSignInUrl').then((url: string) => cy.visit(url, { failOnStatusCode }))
})

Cypress.Commands.add('setupBannerStubs', ({ prisonerNumber, prisonerDataOverrides }) => {
Cypress.Commands.add('setupBannerStubs', ({ prisonerNumber, prisonerDataOverrides, bookingId = 1102484 }) => {
cy.task('stubPrisonerData', { prisonerNumber, overrides: prisonerDataOverrides })
cy.task('stubEventsForProfileImage', prisonerNumber)
cy.task('stubAssessments', bookingId)
cy.task('stubInmateDetail', bookingId)
})

Cypress.Commands.add(
Expand Down
12 changes: 5 additions & 7 deletions server/controllers/prisonerScheduleController.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { PrisonerMockDataA } from '../data/localMockData/prisoner'
import { inmateDetailMock } from '../data/localMockData/inmateDetailMock'
import PrisonerScheduleController from './prisonerScheduleController'
import { dataAccess } from '../data'
import { PrisonerScheduleThisWeekMock } from '../data/localMockData/prisonerScheduleMock'
import { getEventsNextWeekMock, getEventsThisWeekMock } from '../data/localMockData/getEventsMock'
import { prisonApiClientMock } from '../../tests/mocks/prisonApiClientMock'
import { PrisonApiClient } from '../data/interfaces/prisonApiClient'

describe('Prisoner schedule', () => {
const offenderNo = 'ABC123'
const prisonApi = {
getDetails: jest.fn(),
getScheduledEventsForThisWeek: jest.fn(),
getScheduledEventsForNextWeek: jest.fn(),
}
let prisonApi: PrisonApiClient

let req: any
let res: any
Expand All @@ -31,9 +28,10 @@ describe('Prisoner schedule', () => {
}
res = { locals: {}, render: jest.fn(), status: jest.fn() }

prisonApi = prisonApiClientMock()
prisonApi.getScheduledEventsForThisWeek = jest.fn().mockResolvedValue(getEventsThisWeekMock)
prisonApi.getScheduledEventsForNextWeek = jest.fn().mockResolvedValue(getEventsNextWeekMock)
controller = new PrisonerScheduleController(dataAccess.prisonApiClientBuilder)
controller = new PrisonerScheduleController(() => prisonApi)
})

afterEach(() => {
Expand Down
13 changes: 1 addition & 12 deletions server/data/adjudicationsApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,7 @@ export default class AdjudicationsApiRestClient implements AdjudicationsApiClien
this.restClient = new RestClient('Adjudications API', config.apis.adjudicationsApi, token)
}

private async get<T>(args: object, localMockData?: T): Promise<T> {
try {
return await this.restClient.get<T>(args)
} catch (error) {
if (config.localMockData === 'true' && localMockData) {
return localMockData
}
return error
}
}

async getAdjudications(bookingId: number): Promise<AdjudicationSummary> {
return this.get<AdjudicationSummary>({ path: `/adjudications/by-booking-id/${bookingId}` })
return this.restClient.get<AdjudicationSummary>({ path: `/adjudications/by-booking-id/${bookingId}` })
}
}
23 changes: 6 additions & 17 deletions server/data/curiousApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,43 @@ export default class CuriousRestApiClient implements CuriousApiClient {
this.restClient = new RestClient('Curious API', config.apis.curiousApiUrl, token)
}

private async get<T>(args: object, localMockData?: T): Promise<T> {
try {
return await this.restClient.get<T>(args)
} catch (error) {
if (config.localMockData === 'true' && localMockData) {
return localMockData
}
return error
}
}

async getLearnerEmployabilitySkills(offenderNumber: string): Promise<LearnerEmployabilitySkills> {
return this.get<LearnerEmployabilitySkills>({
return this.restClient.get<LearnerEmployabilitySkills>({
path: `/learnerEmployabilitySkills/${offenderNumber}`,
ignore404: true,
})
}

async getLearnerProfile(offenderNumber: string): Promise<LearnerProfile[]> {
return this.get<LearnerProfile[]>({
return this.restClient.get<LearnerProfile[]>({
path: `/learnerProfile/${offenderNumber}`,
ignore404: true,
})
}

async getLearnerEducation(offenderNumber: string): Promise<LearnerEducation> {
return this.get<LearnerEducation>({
return this.restClient.get<LearnerEducation>({
path: `/learnerEducation/${offenderNumber}`,
ignore404: true,
})
}

async getLearnerLatestAssessments(offenderNumber: string): Promise<LearnerLatestAssessment[]> {
return this.get<LearnerLatestAssessment[]>({
return this.restClient.get<LearnerLatestAssessment[]>({
path: `/latestLearnerAssessments/${offenderNumber}`,
ignore404: true,
})
}

async getLearnerGoals(offenderNumber: string): Promise<LearnerGoals> {
return this.get<LearnerGoals>({
return this.restClient.get<LearnerGoals>({
path: `/learnerGoals/${offenderNumber}`,
ignore404: true,
})
}

async getLearnerNeurodivergence(offenderNumber: string): Promise<LearnerNeurodivergence[]> {
return this.get<LearnerNeurodivergence[]>({
return this.restClient.get<LearnerNeurodivergence[]>({
path: `/learnerNeurodivergence/${offenderNumber}`,
ignore404: true,
})
Expand Down
13 changes: 1 addition & 12 deletions server/data/incentivesApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,8 @@ export default class IncentivesApiRestClient implements IncentivesApiClient {
this.restClient = new RestClient('Incentives API', config.apis.incentivesApi, token)
}

private async get<T>(args: object, localMockData?: T): Promise<T> {
try {
return await this.restClient.get<T>(args)
} catch (error) {
if (config.localMockData === 'true' && localMockData) {
return localMockData
}
return error
}
}

async getReviews(bookingId: number): Promise<IncentiveReviews> {
return this.get<IncentiveReviews>({
return this.restClient.get<IncentiveReviews>({
path: `/iep/reviews/booking/${bookingId}`,
ignore404: true,
})
Expand Down
2 changes: 1 addition & 1 deletion server/data/interfaces/prisonApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface PrisonApiClient {
getUserCaseLoads(): Promise<CaseLoad[]>
getAccountBalances(bookingId: number): Promise<AccountBalances>
getVisitSummary(bookingId: number): Promise<VisitSummary>
getVisitBalances(prisonerNumber: string): Promise<VisitBalances>
getVisitBalances(prisonerNumber: string): Promise<VisitBalances | null>
getAssessments(bookingId: number): Promise<Assessment[]>
getBookingContacts(bookingId: number): Promise<ContactDetail>
getCaseNoteSummaryByTypes(params: object): Promise<CaseNote[]>
Expand Down
21 changes: 3 additions & 18 deletions server/data/nonAssociationsApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import config from '../config'
import { NonAssociationDetails } from '../interfaces/nonAssociationDetails'
import { NonAssociationsApiClient } from './interfaces/nonAssociationsApiClient'
import nonAssociationDetailsDummyData from './localMockData/nonAssociations'
import RestClient from './restClient'

export default class NonAssociationsApiRestClient implements NonAssociationsApiClient {
Expand All @@ -11,23 +10,9 @@ export default class NonAssociationsApiRestClient implements NonAssociationsApiC
this.restClient = new RestClient('Non associations API', config.apis.nonAssociationsApi, token)
}

private async get<T>(args: object, localMockData?: T): Promise<T> {
try {
return await this.restClient.get<T>(args)
} catch (error) {
if (config.localMockData === 'true' && localMockData) {
return localMockData
}
return error
}
}

getNonAssociationDetails(prisonerNumber: string): Promise<NonAssociationDetails> {
return this.get<NonAssociationDetails>(
{
path: `/legacy/api/offenders/${prisonerNumber}/non-association-details?currentPrisonOnly=true&excludeInactive=true`,
},
nonAssociationDetailsDummyData,
)
return this.restClient.get<NonAssociationDetails>({
path: `/legacy/api/offenders/${prisonerNumber}/non-association-details?currentPrisonOnly=true&excludeInactive=true`,
})
}
}
Loading