diff --git a/packages/commons/src/events/ActionInput.ts b/packages/commons/src/events/ActionInput.ts index a1a3dd3cbc..f4f7c775c2 100644 --- a/packages/commons/src/events/ActionInput.ts +++ b/packages/commons/src/events/ActionInput.ts @@ -43,6 +43,8 @@ export const ValidateActionInput = BaseActionInput.merge( }) ) +export type ValidateActionInput = z.infer + export const NotifyActionInput = BaseActionInput.merge( z.object({ type: z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY), @@ -50,6 +52,8 @@ export const NotifyActionInput = BaseActionInput.merge( }) ) +export type NotifyActionInput = z.infer + export const DeclareActionInput = BaseActionInput.merge( z.object({ type: z.literal(ActionType.DECLARE).default(ActionType.DECLARE) diff --git a/packages/events/src/router/__snapshots__/event.get.test.ts.snap b/packages/events/src/router/__snapshots__/event.get.test.ts.snap index 53dfd49d5f..09f13b76d8 100644 --- a/packages/events/src/router/__snapshots__/event.get.test.ts.snap +++ b/packages/events/src/router/__snapshots__/event.get.test.ts.snap @@ -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": [ { @@ -69,6 +67,60 @@ exports[`get event > Returns event 1`] = ` "draft": false, "type": "CREATE", }, + { + "createdAt": "", + "createdAtLocation": { + "externalId": "", + "id": "", + "name": "Location name 0", + "partOf": null, + }, + "createdBy": { + "id": "", + "name": [ + { + "family": "Doe", + "given": [ + "John", + ], + "use": "en", + }, + ], + "systemRole": "REGISTRATION_AGENT", + }, + "data": { + "name": "John Doe", + }, + "draft": false, + "type": "DECLARE", + }, + { + "createdAt": "", + "createdAtLocation": { + "externalId": "", + "id": "", + "name": "Location name 0", + "partOf": null, + }, + "createdBy": { + "id": "", + "name": [ + { + "family": "Doe", + "given": [ + "John", + ], + "use": "en", + }, + ], + "systemRole": "REGISTRATION_AGENT", + }, + "data": { + "favouritePlayer": "Elena Rybakina", + }, + "draft": false, + "type": "VALIDATE", + }, ], "createdAt": "", "id": "", diff --git a/packages/events/src/router/event.get.test.ts b/packages/events/src/router/event.get.test.ts index b44d23cf91..3948240e0d 100644 --- a/packages/events/src/router/event.get.test.ts +++ b/packages/events/src/router/event.get.test.ts @@ -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() +}) diff --git a/packages/events/src/tests/generators.ts b/packages/events/src/tests/generators.ts index 60d13b75b1..fe79f299f7 100644 --- a/packages/events/src/tests/generators.ts +++ b/packages/events/src/tests/generators.ts @@ -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' @@ -60,6 +61,15 @@ export function payloadGenerator() { transactionId: input?.transactionId ?? getUUID(), data: input?.data ?? {}, eventId + }), + validate: ( + eventId: string, + input: Partial> = {} + ) => ({ + type: ActionType.VALIDATE, + transactionId: input?.transactionId ?? getUUID(), + data: input?.data ?? {}, + eventId }) } }