@@ -160,10 +160,64 @@ describe('outbox', () => {
160
160
const entries = await outboxStorage . getEntries ( 2 )
161
161
162
162
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
+ } )
163
214
215
+ entries = await outboxStorage . getEntries ( 2 )
216
+ expect ( entries ) . toHaveLength ( 0 ) //Nothing to process anymore
164
217
expect ( outboxStorage . entries ) . toMatchObject ( [
165
218
{
166
219
status : 'SUCCESS' ,
220
+ retryCount : 1 ,
167
221
} ,
168
222
] )
169
223
} )
0 commit comments