Skip to content

Commit

Permalink
Moved verifyApiPost to journeyUtils as a cypress task to be used else…
Browse files Browse the repository at this point in the history
…where
  • Loading branch information
Bob Meredith committed Nov 19, 2024
1 parent 1f1317a commit 575e1e0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import outOfServiceBed from './integration_tests/mockApis/outOfServiceBed'
import person from './integration_tests/mockApis/person'
import reports from './integration_tests/mockApis/reports'
import applications from './integration_tests/mockApis/applications'
import { stubJourney } from './integration_tests/mockApis/journeyUtils'
import { stubJourney, verifyApiPost } from './integration_tests/mockApis/journeyUtils'
import assessments from './integration_tests/mockApis/assessments'
import users from './integration_tests/mockApis/users'
import tasks from './integration_tests/mockApis/tasks'
Expand Down Expand Up @@ -57,6 +57,7 @@ export default defineConfig({
...spaceBookings,
...referenceData,
stubJourney,
verifyApiPost,
})
},
baseUrl: 'http://localhost:3007',
Expand Down
11 changes: 10 additions & 1 deletion integration_tests/mockApis/journeyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ApprovedPremisesAssessment as Assessment,
} from '@approved-premises/api'

import { bulkStub } from './setup'
import { bulkStub, getMatchingRequests } from './setup'
import isAssessment from '../../server/utils/assessments/isAssessment'

export const generateStubsForPage = (
Expand Down Expand Up @@ -152,6 +152,15 @@ export const copyCompleteTasksToData = ({ completeTasks, form }) => {
return data
}

export const verifyApiPost = async (path: string): Promise<Record<string, unknown>> => {
const result = await getMatchingRequests({
method: 'POST',
url: path,
})
const { requests } = result.body
return JSON.parse(requests[0].body)
}

export const stubJourney = (form: Application | Assessment): SuperAgentRequest => {
type JourneyType =
| { scenarioName: 'assess'; urlPrefix: 'assessment' }
Expand Down
9 changes: 0 additions & 9 deletions integration_tests/mockApis/spaceBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,4 @@ export default {
status: 200,
},
}),

getApiPost: async (path: string): Promise<Record<string, unknown>> => {
const result = await getMatchingRequests({
method: 'POST',
url: path,
})
const { requests } = result.body
return JSON.parse(requests[0].body)
},
}
2 changes: 1 addition & 1 deletion integration_tests/pages/manage/placements/arrival.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ArrivalCreatePage extends Page {

checkApiCalled(): void {
cy.task(
'getApiPost',
'verifyApiPost',
apiPaths.premises.placements.arrival({ premisesId: this.placement.premises.id, placementId: this.placement.id }),
).then(body => {
const { arrivalDateTime, expectedDepartureDate } = body as Cas1NewArrival
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/pages/manage/placements/keyworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class KeyworkerAssignmentPage extends Page {

checkApiCalled(placement: Cas1SpaceBooking): void {
cy.task(
'getApiPost',
'verifyApiPost',
apiPaths.premises.placements.keyworker({ premisesId: placement.premises.id, placementId: placement.id }),
).then(body => {
expect(body).to.deep.equal({ staffCode: this.staffMembers[1].code })
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/pages/manage/placements/nonArrival.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class RecordNonArrivalPage extends Page {

checkApiCalled(placement: Cas1SpaceBooking): void {
cy.task(
'getApiPost',
'verifyApiPost',
apiPaths.premises.placements.nonArrival({ premisesId: placement.premises.id, placementId: placement.id }),
).then(body => {
expect(body).to.deep.equal(this.nonArrivalDetails)
Expand Down
2 changes: 1 addition & 1 deletion server/testutils/factories/cas1NonArrival.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import { DateFormats } from '../../utils/dateUtils'
export default Factory.define<Cas1NonArrival>(() => ({
reason: faker.string.uuid(),
notes: faker.lorem.words(20),
confirmedAt: DateFormats.dateObjToIsoDateTime(new Date(faker.date.recent())),
confirmedAt: DateFormats.dateObjToIsoDateTime(faker.date.recent()),
}))

0 comments on commit 575e1e0

Please sign in to comment.