@@ -1269,7 +1269,7 @@ describe('events', function () {
1269
1269
} ) ;
1270
1270
1271
1271
describe ( 'when publishing custom events' , function ( ) {
1272
- it ( 'emits waiting when a job has been added ' , async ( ) => {
1272
+ it ( 'emits custom event ' , async ( ) => {
1273
1273
const queueName2 = `test-${ v4 ( ) } ` ;
1274
1274
const queueEventsProducer = new QueueEventsProducer ( queueName2 , {
1275
1275
connection,
@@ -1311,5 +1311,50 @@ describe('events', function () {
1311
1311
await queueEvents2 . close ( ) ;
1312
1312
await removeAllQueueData ( new IORedis ( redisHost ) , queueName2 ) ;
1313
1313
} ) ;
1314
+
1315
+ describe ( 'when published event is an object' , function ( ) {
1316
+ it ( 'deserialize event' , async ( ) => {
1317
+ const queueName2 = `test-${ v4 ( ) } ` ;
1318
+ const queueEventsProducer = new QueueEventsProducer ( queueName2 , {
1319
+ connection,
1320
+ prefix,
1321
+ } ) ;
1322
+ const queueEvents2 = new QueueEvents ( queueName2 , {
1323
+ autorun : false ,
1324
+ connection,
1325
+ prefix,
1326
+ lastEventId : '0-0' ,
1327
+ } ) ;
1328
+ await queueEvents2 . waitUntilReady ( ) ;
1329
+
1330
+ interface CustomListener extends QueueEventsListener {
1331
+ example : ( args : { custom : { foo : string } } , id : string ) => void ;
1332
+ }
1333
+ const customEvent = new Promise < void > ( resolve => {
1334
+ queueEvents2 . on < CustomListener > ( 'example' , async ( { custom } ) => {
1335
+ await delay ( 250 ) ;
1336
+ await expect ( custom . foo ) . to . be . equal ( 'value' ) ;
1337
+ resolve ( ) ;
1338
+ } ) ;
1339
+ } ) ;
1340
+
1341
+ interface CustomEventPayload {
1342
+ eventName : string ;
1343
+ custom : { foo : string } ;
1344
+ }
1345
+
1346
+ await queueEventsProducer . publishEvent < CustomEventPayload > ( {
1347
+ eventName : 'example' ,
1348
+ custom : { foo : 'value' } ,
1349
+ } ) ;
1350
+
1351
+ queueEvents2 . run ( ) ;
1352
+ await customEvent ;
1353
+
1354
+ await queueEventsProducer . close ( ) ;
1355
+ await queueEvents2 . close ( ) ;
1356
+ await removeAllQueueData ( new IORedis ( redisHost ) , queueName2 ) ;
1357
+ } ) ;
1358
+ } ) ;
1314
1359
} ) ;
1315
1360
} ) ;
0 commit comments