Skip to content

Commit bc80d7d

Browse files
committed
Fixed tests to new version of outbox entry.
1 parent ed4ce02 commit bc80d7d

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

packages/outbox-prisma-adapter/lib/outbox-prisma-adapter.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
OutboxEntry,
44
OutboxStorage,
55
} from '@message-queue-toolkit/outbox-core'
6-
import { type CommonEventDefinition, getMessageType } from '@message-queue-toolkit/schemas'
6+
import type { CommonEventDefinition } from '@message-queue-toolkit/schemas'
77
import type { PrismaClient } from '@prisma/client'
88

99
type ModelDelegate = {
@@ -33,14 +33,13 @@ export class OutboxPrismaAdapter<
3333
const prismaModel = this.prisma[this.modelName] as unknown as ModelDelegate
3434

3535
// @ts-ignore
36-
const messageType = getMessageType(outboxEntry.event)
3736
return prismaModel.create({
3837
data: {
3938
id: outboxEntry.id,
40-
type: messageType,
39+
type: outboxEntry.event.type,
4140
created: outboxEntry.created,
4241
updated: outboxEntry.updated,
43-
data: outboxEntry.data,
42+
event: outboxEntry.event,
4443
status: outboxEntry.status,
4544
retryCount: outboxEntry.retryCount,
4645
},
@@ -84,10 +83,10 @@ export class OutboxPrismaAdapter<
8483
data: toCreate.map((entry) => ({
8584
id: entry.id,
8685
// @ts-ignore
87-
type: getMessageType(entry.event),
86+
type: entry.event.type,
8887
created: entry.created,
8988
updated: new Date(),
90-
data: entry.data,
89+
event: entry.event,
9190
status: 'SUCCESS',
9291
})),
9392
})
@@ -124,11 +123,10 @@ export class OutboxPrismaAdapter<
124123
await prismaModel.createMany({
125124
data: toCreate.map((entry) => ({
126125
id: entry.id,
127-
// @ts-ignore
128-
type: getMessageType(entry.event),
126+
type: entry.event.type,
129127
created: entry.created,
130128
updated: new Date(),
131-
data: entry.data,
129+
event: entry.event,
132130
status: 'FAILED',
133131
retryCount: 1,
134132
})),

packages/outbox-prisma-adapter/prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ model OutboxEntry {
99
updated DateTime @default(now()) @updatedAt
1010
type String
1111
retryCount Int @default(0) @map("retry_count")
12-
data Json
12+
event Json
1313
status String
1414
1515
@@map("outbox_entry")

packages/outbox-prisma-adapter/test/outbox-prisma-adapter.spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,29 @@ describe('outbox-prisma-adapter', () => {
2828

2929
const ENTRY_1 = {
3030
id: uuidv7(),
31-
event: events.created,
3231
status: 'CREATED',
33-
data: {
32+
event: {
3433
id: uuidv7(),
3534
payload: {
3635
message: 'TEST EVENT',
3736
},
3837
metadata: {},
3938
timestamp: new Date().toISOString(),
39+
type: 'entity.created',
4040
},
4141
retryCount: 0,
4242
created: new Date(),
4343
} satisfies OutboxEntry<SupportedEvents[number]>
4444

4545
const ENTRY_2 = {
4646
id: uuidv7(),
47-
event: events.created,
4847
status: 'CREATED',
49-
data: {
48+
event: {
5049
id: uuidv7(),
5150
payload: {
5251
message: 'TEST EVENT 2',
5352
},
53+
type: 'entity.created',
5454
metadata: {},
5555
timestamp: new Date().toISOString(),
5656
},
@@ -76,7 +76,7 @@ describe('outbox-prisma-adapter', () => {
7676
created TIMESTAMP NOT NULL,
7777
updated TIMESTAMP,
7878
retry_count INT NOT NULL DEFAULT 0,
79-
data JSONB NOT NULL,
79+
event JSONB NOT NULL,
8080
status TEXT NOT NULL
8181
)
8282
`
@@ -95,13 +95,13 @@ describe('outbox-prisma-adapter', () => {
9595
it('creates entry in DB via outbox storage implementation', async () => {
9696
await outboxPrismaAdapter.createEntry({
9797
id: uuidv7(),
98-
event: events.created,
9998
status: 'CREATED',
100-
data: {
99+
event: {
101100
id: uuidv7(),
102101
payload: {
103102
message: 'TEST EVENT',
104103
},
104+
type: 'entity.created',
105105
metadata: {},
106106
timestamp: new Date().toISOString(),
107107
},
@@ -118,11 +118,12 @@ describe('outbox-prisma-adapter', () => {
118118
created: expect.any(Date),
119119
updated: expect.any(Date),
120120
retryCount: 0,
121-
data: {
121+
event: {
122122
id: expect.any(String),
123123
payload: {
124124
message: 'TEST EVENT',
125125
},
126+
type: 'entity.created',
126127
metadata: {},
127128
timestamp: expect.any(String),
128129
},

0 commit comments

Comments
 (0)