Skip to content

Commit 29937e9

Browse files
committed
add testcase
1 parent d7a9532 commit 29937e9

4 files changed

+60
-3
lines changed

e2e/testcases/v2-events-rest-api/create-and-notify-event.spec.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ test.describe('Events REST API', () => {
224224
let healthFacilityId: string
225225

226226
test.beforeAll(async () => {
227-
const healthFacility = await getAllLocations('HEALTH_FACILITY')
227+
const healthFacilities = await getAllLocations('HEALTH_FACILITY')
228228

229-
if (!healthFacility[0].id) {
229+
if (!healthFacilities[0].id) {
230230
throw new Error('No health facility found')
231231
}
232232

233-
healthFacilityId = healthFacility[0].id
233+
healthFacilityId = healthFacilities[0].id
234234
})
235235

236236
test('HTTP 401 when invalid token is used', async () => {
@@ -497,6 +497,60 @@ test.describe('Events REST API', () => {
497497
expect(body.message).toMatchSnapshot()
498498
})
499499

500+
test('HTTP 400 when trying to notify an event with a non-office createdAtLocation', async () => {
501+
const createEventResponse = await fetchClientAPI(
502+
'/api/events/events',
503+
'POST',
504+
clientToken,
505+
{
506+
type: EVENT_TYPE,
507+
transactionId: uuidv4()
508+
}
509+
)
510+
511+
const createEventResponseBody = await createEventResponse.json()
512+
const eventId = createEventResponseBody.id
513+
514+
const childName = {
515+
firstNames: faker.person.firstName(),
516+
familyName: faker.person.lastName()
517+
}
518+
519+
const locations = await getAllLocations('ADMIN_STRUCTURE')
520+
const centralLocation = locations.find(
521+
(location) => location.name === 'Central'
522+
)
523+
524+
if (!centralLocation) {
525+
throw new Error('No central location found')
526+
}
527+
528+
const response = await fetchClientAPI(
529+
'/api/events/events/notifications',
530+
'POST',
531+
clientToken,
532+
{
533+
eventId,
534+
transactionId: uuidv4(),
535+
type: 'NOTIFY',
536+
declaration: {
537+
'child.name': {
538+
firstname: childName.firstNames,
539+
surname: childName.familyName
540+
},
541+
'child.dob': format(subDays(new Date(), 1), 'yyyy-MM-dd')
542+
},
543+
annotation: {},
544+
createdAtLocation: centralLocation.id
545+
}
546+
)
547+
548+
const body = await response.json()
549+
550+
expect(response.status).toBe(400)
551+
expect(body.message).toMatchSnapshot()
552+
})
553+
500554
test('HTTP 200 with valid payload', async ({ page }) => {
501555
const createEventResponse = await fetchClientAPI(
502556
'/api/events/events',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Input validation failed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Input validation failed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
createdAtLocation must be an office location

0 commit comments

Comments
 (0)