|
| 1 | +import type { OutboxEntry } from '@message-queue-toolkit/outbox-core' |
| 2 | +import { |
| 3 | + type CommonEventDefinition, |
| 4 | + enrichMessageSchemaWithBase, |
| 5 | +} from '@message-queue-toolkit/schemas' |
1 | 6 | import { PrismaClient } from '@prisma/client' |
| 7 | +import { uuidv7 } from 'uuidv7' |
2 | 8 | import { afterAll, beforeAll, describe, expect, it } from 'vitest' |
| 9 | +import { z } from 'zod' |
| 10 | +import { OutboxPrismaAdapter } from '../lib/outbox-prisma-adapter' |
| 11 | + |
| 12 | +const events = { |
| 13 | + created: { |
| 14 | + ...enrichMessageSchemaWithBase( |
| 15 | + 'entity.created', |
| 16 | + z.object({ |
| 17 | + message: z.string(), |
| 18 | + }), |
| 19 | + ), |
| 20 | + }, |
| 21 | +} satisfies Record<string, CommonEventDefinition> |
| 22 | + |
| 23 | +type SupportedEvents = (typeof events)[keyof typeof events][] |
3 | 24 |
|
4 | 25 | describe('outbox-prisma-adapter', () => { |
5 | 26 | let prisma: PrismaClient |
| 27 | + let outboxPrismaAdapter: OutboxPrismaAdapter<SupportedEvents> |
6 | 28 |
|
7 | 29 | beforeAll(async () => { |
8 | 30 | prisma = new PrismaClient() |
9 | 31 |
|
| 32 | + outboxPrismaAdapter = new OutboxPrismaAdapter<SupportedEvents>(prisma, 'OutboxEntry') |
| 33 | + |
10 | 34 | await prisma.$queryRaw`create schema if not exists prisma;` |
11 | 35 | await prisma.$queryRaw` |
12 | 36 | CREATE TABLE prisma.outbox_entry ( |
@@ -39,4 +63,20 @@ describe('outbox-prisma-adapter', () => { |
39 | 63 | }, |
40 | 64 | ]) |
41 | 65 | }) |
| 66 | + |
| 67 | + it('creates entry in DB via outbox storage implementation', async () => { |
| 68 | + await outboxPrismaAdapter.createEntry({ |
| 69 | + id: uuidv7(), |
| 70 | + event: events.created, |
| 71 | + status: 'CREATED', |
| 72 | + data: { |
| 73 | + id: uuidv7(), |
| 74 | + payload: { |
| 75 | + message: 'TEST EVENT', |
| 76 | + }, |
| 77 | + metadata: {}, |
| 78 | + timestamp: new Date().toISOString(), |
| 79 | + }, |
| 80 | + } satisfies OutboxEntry<SupportedEvents[number]>) |
| 81 | + }) |
42 | 82 | }) |
0 commit comments