You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importQueuefrom'bull';interfacePayload{orderId: string;}constexpirationQueue=newQueue<Payload>('order:expiration',{redis: {host: process.env.REDIS_HOST,},});expirationQueue.process(async(job)=>{console.log('I want to publish an expiration:complete event for orderId',job.data.orderId);});export{expirationQueue};
asynconMessage(data: OrderCreatedEvent['data'],msg: Message){constdelay=newDate(data.expiresAt).getTime()-newDate().getTime();console.log('Waiting this many milliseconds to process the job:',delay);awaitexpirationQueue.add({orderId: data.id,},{
delay,});msg.ack();}
it('updates the order status to cancelled',async()=>{const{ listener, order, data, msg }=awaitsetup();awaitlistener.onMessage(data,msg);constupdatedOrder=awaitOrder.findById(order.id);expect(updatedOrder!.status).toEqual(OrderStatus.Cancelled);});it('emit an OrderCancelled event',async()=>{const{ listener, order, data, msg }=awaitsetup();awaitlistener.onMessage(data,msg);expect(natsWrapper.client.publish).toHaveBeenCalled();consteventData=JSON.parse((natsWrapper.client.publishasjest.Mock).mock.calls[0][1]);expect(eventData.id).toEqual(order.id);});it('ack the message',async()=>{const{ listener, data, msg }=awaitsetup();awaitlistener.onMessage(data,msg);expect(msg.ack).toHaveBeenCalled();});