Skip to content

Commit

Permalink
chore: add test cases for event
Browse files Browse the repository at this point in the history
  • Loading branch information
makelicious committed Jan 10, 2025
1 parent b914ee8 commit 677cba1
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/commons/src/events/ActionInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ export const ValidateActionInput = BaseActionInput.merge(
})
)

export type ValidateActionInput = z.infer<typeof ValidateActionInput>

export const NotifyActionInput = BaseActionInput.merge(
z.object({
type: z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY),
createdAtLocation: z.string()
})
)

export type NotifyActionInput = z.infer<typeof NotifyActionInput>

export const DeclareActionInput = BaseActionInput.merge(
z.object({
type: z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
Expand Down
58 changes: 55 additions & 3 deletions packages/events/src/router/__snapshots__/event.get.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ exports[`Returns event 1`] = `
}
`;

exports[`get event > Returns 404 when not found 1`] = `[TRPCError: Event not found with ID: id-not-persisted]`;

exports[`get event > Returns event 1`] = `
exports[`Returns event with all actions resolved 1`] = `
{
"actions": [
{
Expand Down Expand Up @@ -69,6 +67,60 @@ exports[`get event > Returns event 1`] = `
"draft": false,
"type": "CREATE",
},
{
"createdAt": "<createdAt />",
"createdAtLocation": {
"externalId": "<externalId />",
"id": "<id />",
"name": "Location name 0",
"partOf": null,
},
"createdBy": {
"id": "<id />",
"name": [
{
"family": "Doe",
"given": [
"John",
],
"use": "en",
},
],
"systemRole": "REGISTRATION_AGENT",
},
"data": {
"name": "John Doe",
},
"draft": false,
"type": "DECLARE",
},
{
"createdAt": "<createdAt />",
"createdAtLocation": {
"externalId": "<externalId />",
"id": "<id />",
"name": "Location name 0",
"partOf": null,
},
"createdBy": {
"id": "<id />",
"name": [
{
"family": "Doe",
"given": [
"John",
],
"use": "en",
},
],
"systemRole": "REGISTRATION_AGENT",
},
"data": {
"favouritePlayer": "Elena Rybakina",
},
"draft": false,
"type": "VALIDATE",
},
],
"createdAt": "<createdAt />",
"id": "<id />",
Expand Down
22 changes: 22 additions & 0 deletions packages/events/src/router/event.get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,25 @@ test('Returns event', async () => {

expect(sanitizeUnstableKeys(fetchedEvent)).toMatchSnapshot()
})

test('Returns event with all actions resolved', async () => {
const { user, generator } = await setupTestCase()
const client = createTestClient(user)

const event = await client.event.create(generator.event.create())

await client.event.actions.declare(
generator.event.actions.declare(event.id, { data: { name: 'John Doe' } })
)

await client.event.actions.validate(
generator.event.actions.validate(event.id, {
data: { favouritePlayer: 'Elena Rybakina' }
})
)

const fetchedEvent = await client.event.get(event.id)

expect(fetchedEvent.actions).toHaveLength(3)
expect(sanitizeUnstableKeys(fetchedEvent)).toMatchSnapshot()
})
12 changes: 11 additions & 1 deletion packages/events/src/tests/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
EventInput,
getUUID,
ActionType,
ResolvedLocation
ResolvedLocation,
ValidateActionInput
} from '@opencrvs/commons'
import { Location } from '@events/service/locations/locations'
import { Db } from 'mongodb'
Expand Down Expand Up @@ -60,6 +61,15 @@ export function payloadGenerator() {
transactionId: input?.transactionId ?? getUUID(),
data: input?.data ?? {},
eventId
}),
validate: (
eventId: string,
input: Partial<Pick<ValidateActionInput, 'transactionId' | 'data'>> = {}
) => ({
type: ActionType.VALIDATE,
transactionId: input?.transactionId ?? getUUID(),
data: input?.data ?? {},
eventId
})
}
}
Expand Down

0 comments on commit 677cba1

Please sign in to comment.