Skip to content

Commit

Permalink
feat(bullmq): skip initialization on missing config
Browse files Browse the repository at this point in the history
  • Loading branch information
abenerd authored and Romakita committed Nov 16, 2023
1 parent e8a3492 commit 3ccd5a8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/third-parties/bullmq/jest.config.js
Expand Up @@ -2,7 +2,7 @@ module.exports = {
...require("@tsed/jest-config"),
coverageThreshold: {
global: {
branches: 81.81,
branches: 82.85,
functions: 100,
lines: 100,
statements: 100
Expand Down
24 changes: 22 additions & 2 deletions packages/third-parties/bullmq/src/BullMQModule.spec.ts
@@ -1,7 +1,7 @@
import {PlatformTest} from "@tsed/common";
import {InjectorService, PlatformTest} from "@tsed/common";
import {catchAsyncError} from "@tsed/core";
import {Queue, Worker} from "bullmq";
import {instance, mock, verify, when} from "ts-mockito";
import {anyString, anything, instance, mock, verify, when} from "ts-mockito";

import "./BullMQModule";
import {BullMQModule} from "./BullMQModule";
Expand Down Expand Up @@ -182,3 +182,23 @@ describe("module", () => {
});
});
});

it('skips initialization when no config is provided', async () => {
const injector = mock(InjectorService)
const dispatcher = mock(JobDispatcher);
await PlatformTest.create({
imports: [
{
token: InjectorService,
use: instance(injector),
},
{
token: JobDispatcher,
use: instance(dispatcher)
}
]
})

verify(injector.add(anyString(), anything())).never();
verify(dispatcher.dispatch(anything())).never()
});
4 changes: 4 additions & 0 deletions packages/third-parties/bullmq/src/BullMQModule.ts
Expand Up @@ -15,6 +15,10 @@ export class BullMQModule implements BeforeInit {
constructor(private readonly injector: InjectorService, private readonly dispatcher: JobDispatcher) {}

$beforeInit() {
if (!this.bullmq) {
return;
}

this.buildWorkers();
this.buildQueues();

Expand Down

0 comments on commit 3ccd5a8

Please sign in to comment.