Skip to content

Commit c3b08ea

Browse files
committed
another test
1 parent 9a9bf28 commit c3b08ea

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

packages/outbox-core/lib/outbox.spec.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,64 @@ describe('outbox', () => {
160160
const entries = await outboxStorage.getEntries(2)
161161

162162
expect(entries).toHaveLength(0)
163+
expect(outboxStorage.entries).toMatchObject([
164+
{
165+
status: 'SUCCESS',
166+
},
167+
])
168+
})
169+
170+
it('saves outbox entry and process it with error and retries', async () => {
171+
await outboxEventEmitter.emit(TestEvents.created, createdEventPayload, {
172+
correlationId: randomUUID(),
173+
})
174+
175+
const mockedEventEmitter = vi.spyOn(eventEmitter, 'emit')
176+
mockedEventEmitter.mockImplementationOnce(() => {
177+
throw new Error('Could not emit event.')
178+
})
179+
mockedEventEmitter.mockImplementationOnce(() =>
180+
Promise.resolve({
181+
...createdEventPayload,
182+
id: randomUUID(),
183+
timestamp: new Date().toISOString(),
184+
metadata: {
185+
schemaVersion: '1',
186+
producedBy: 'test',
187+
originatedFrom: 'service',
188+
correlationId: randomUUID(),
189+
},
190+
}),
191+
)
192+
193+
await outboxProcessor.processOutboxEntries({
194+
logger: TestLogger,
195+
reqId: randomUUID(),
196+
executorId: randomUUID(),
197+
})
198+
199+
let entries = await outboxStorage.getEntries(2)
200+
expect(entries).toHaveLength(1)
201+
expect(outboxStorage.entries).toMatchObject([
202+
{
203+
status: 'FAILED',
204+
retryCount: 1,
205+
},
206+
])
207+
208+
//Now let's process again successfully
209+
await outboxProcessor.processOutboxEntries({
210+
logger: TestLogger,
211+
reqId: randomUUID(),
212+
executorId: randomUUID(),
213+
})
163214

215+
entries = await outboxStorage.getEntries(2)
216+
expect(entries).toHaveLength(0) //Nothing to process anymore
164217
expect(outboxStorage.entries).toMatchObject([
165218
{
166219
status: 'SUCCESS',
220+
retryCount: 1,
167221
},
168222
])
169223
})

0 commit comments

Comments
 (0)