/* This Gist demonstrates how to create type-safe DTOs for BullMQ jobs in TypeScript and validate them in Jest tests using Supertest. By extending job payloads and responses with DTOs, you can ensure strong typing while testing your NestJS webhooks and background jobs. The example shows how to: Define a job DTO (SendMilionsOfEmailsDTO) and response DTO (SendMilionsOfEmailsResponseDTO). Infer the correct job type from bullmq.Job.toJSON. Write Jest + Supertest assertions for job processing results, including attemptsMade, finishedOn, processedOn, and typed returnvalue. Validate nested DTOs (email, name) using expect.objectContaining. This approach improves test reliability, maintainability, and TypeScript safety when working with BullMQ queues in Node.js/NestJS applications. 🔑 Keywords (for SEO) typescript bullmq types for failed and success jobs BullMQ TypeScript Example BullMQ Jest Supertest NestJS BullMQ Job Testing TypeScript DTO BullMQ BullMQ Queue Testing Example Type-Safe BullMQ Jobs Jest Supertest BullMQ Integration BullMQ Job toJSON TypeScript 📚 Tags for Gist #typescript #nestjs #bullmq #jest #supertest #queues #testing #dto #jobs - Little Docs generated with IA, GPT-5 */ import { Job } from 'bullmq'; import * as request from 'supertest'; // You're gonna need your DTO and the response. class User { email!: string; name!: string; } export class SendMilionsOfEmailsDTO { userEmail!: string; } export class SendMilionsOfEmailsResponseDTO extends User {} export type ProcessSendMilionsOfEmailsToAUserDTO = ReturnType< Job['toJSON'] >; // And you can expect in a test file the following assertion: await request(app.getHttpServer()) .get(`/api/webhooks/jobs/${id}/status`) .set('Content-Type', 'application/json') .expect(200) .expect((res) => { expect(res.body).toMatchObject({ attemptsMade: expect.any(Number), attemptsStarted: expect.any(Number), finishedOn: expect.any(Number), processedOn: expect.any(Number), timestamp: expect.any(Number), queueQualifiedName: expect.any(String), returnvalue: expect.any(Object), data: expect.objectContaining({ email: expect.any(String), name: expect.any(String), }), opts: expect.any(Object), progress: expect.any(Number), stacktrace: expect.any(Array), delay: expect.any(Number), priority: expect.any(Number), stalledCounter: expect.any(Number), name: expect.any(String), deferredFailure: expect.any(String), failedReason: expect.any(String), }); });