@tsed/bullmq
Version:
BullMQ integration for Ts.ED
95 lines (71 loc) • 2.81 kB
text/typescript
import {Store} from "@tsed/core";
import {GlobalProviders} from "@tsed/di";
import {FallbackJobController, JobController} from "./JobController.js";
describe("JobController", () => {
afterEach(() => GlobalProviders.clear());
it("should set the proper store data", () => {
class TestJob {}
const store = Store.from(TestJob).get("bullmq");
expect(store.name).toBe("testjob");
expect(store.queue).toBe("default");
expect(store.opts).toStrictEqual({});
});
it("should allow settings a custom queue", () => {
class CustomQueueJob {}
const store = Store.from(CustomQueueJob).get("bullmq");
expect(store.queue).toBe("custom");
});
it("should allow custom options to be set", () => {
class CustomOptionsJob {}
const store = Store.from(CustomOptionsJob).get("bullmq");
expect(store.opts).toStrictEqual({
backoff: 69,
attempts: 42
});
});
it("should set type for cron jobs", () => {
class CustomCronJob {}
const store = Store.from(CustomCronJob).get("bullmq");
expect(store).toBeDefined();
});
});
describe("FallbackJobController", () => {
afterEach(() => GlobalProviders.clear());
describe("with queue", () => {
it("should set the proper store data", () => {
class FallbackJob {}
const store = Store.from(FallbackJob).get("bullmq");
expect(store.queue).toBe("default");
const fallbackControllerForQueue = GlobalProviders.get("bullmq.fallback-job.default");
expect(fallbackControllerForQueue).not.toBeUndefined();
expect(fallbackControllerForQueue?.type).toEqual("bullmq:fallback-job");
expect(fallbackControllerForQueue?.useClass).toEqual(FallbackJob);
const fallbackController = GlobalProviders.get("bullmq.fallback-job");
expect(fallbackController).toBeUndefined();
});
});
describe("without queue", () => {
it("should set the proper store data", () => {
class FallbackJob {}
const store = Store.from(FallbackJob).get("bullmq");
expect(store.queue).toBeUndefined();
const fallbackController = GlobalProviders.get("bullmq.fallback-job");
expect(fallbackController).not.toBeUndefined();
expect(fallbackController?.type).toEqual("bullmq:fallback-job");
expect(fallbackController?.useClass).toEqual(FallbackJob);
const fallbackControllerForQueue = GlobalProviders.get("bullmq.fallback-job.default");
expect(fallbackControllerForQueue).toBeUndefined();
});
});
});