All files / src/utils null-queue.ts

80% Statements 4/5
100% Branches 0/0
20% Functions 1/5
66.66% Lines 2/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3311x                     11x                                          
import { Injectable } from '@nestjs/common';
 
/**
 * NullQueue is a lightweight in-memory stub that fulfils the subset of the
 * BullMQ `Queue` API that our services rely on (currently only `add`).
 *
 * It is meant to be injected in place of a real BullMQ queue when running
 * under NODE_ENV === 'test' so that e2e and unit tests do not require a
 * running Redis instance. All methods are implemented as no-ops.
 */
@Injectable()
export class NullQueue {
  /**
   * Mimics `Queue.add()` by immediately resolving with a fake Job object.
   * Only the properties accessed in tests / production code are included.
   */
  async add(name: string, data: any) {
    return {
      id  : `${Date.now()}`,
      name,
      data,
    };
  }
 
  // The rest of the BullMQ Queue API below is provided for completeness and
  // to avoid `undefined is not a function` errors if new calls are added in
  // the future. All are synchronous no-ops that return `this` or void.
 
  async pause() {/* noop */}
  async resume() {/* noop */}
  async empty() {/* noop */}
  async close() {/* noop */}
}