Skip to content

Commit

Permalink
test(): add e2e to exercise combination of processors registering
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Oct 15, 2021
1 parent 4420873 commit a72c686
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
112 changes: 111 additions & 1 deletion e2e/module.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { MetadataScanner } from '@nestjs/core';
import { Queue } from 'bull';
import { BullModule, getQueueToken } from '../lib';
import { BullModule, getQueueToken, Processor } from '../lib';

describe('BullModule', () => {
describe('registerQueue', () => {
Expand Down Expand Up @@ -403,4 +404,113 @@ describe('BullModule', () => {
});
});
});

describe('handles all kind of valid processors providers', () => {
@Processor('test_processor_registering')
class MyProcessorA {}

@Processor('test_processor_registering')
class MyProcessorB {}

@Processor('test_processor_registering')
class MyProcessorC {}

let testingModule: TestingModule;

let metadataScanner: MetadataScanner;

beforeAll(async () => {
testingModule = await Test.createTestingModule({
imports: [
BullModule.registerQueue({
name: 'test_processor_registering',
redis: {
host: '0.0.0.0',
port: 6380,
},
}),
],
providers: [
{
provide: 'A',
useClass: MyProcessorA,
},
{
provide: 'B',
useValue: new MyProcessorB(),
},
{
provide: 'C',
useFactory: () => new MyProcessorC(),
},
],
}).compile();

metadataScanner = testingModule.get(MetadataScanner);
jest.spyOn(metadataScanner, 'scanFromPrototype');

await testingModule.init();
});
afterAll(async () => {
await testingModule.close();
});

it('should use MetadataScanner#scanFromPrototype when exploring', () => {
expect(metadataScanner.scanFromPrototype).toHaveBeenCalled();
});

it('should reach the processor supplied with `useClass`', () => {
const scanPrototypeCalls = jest.spyOn(
metadataScanner,
'scanFromPrototype',
).mock.calls;

const scanPrototypeCallsFirstArgsEveryCall = scanPrototypeCalls.flatMap(
(args) => args[0],
);

expect(
scanPrototypeCallsFirstArgsEveryCall.some(
(instanceWrapperInstance) =>
instanceWrapperInstance.constructor.name === MyProcessorA.name,
),
).toBeTruthy();
});

it('should reach the processor supplied with `useValue`', () => {
const scanPrototypeCalls = jest.spyOn(
metadataScanner,
'scanFromPrototype',
).mock.calls;

const scanPrototypeCallsFirstArgsEveryCall = scanPrototypeCalls.flatMap(
(args) => args[0],
);

expect(
scanPrototypeCallsFirstArgsEveryCall.some(
(instanceWrapperInstance) =>
instanceWrapperInstance.constructor.name === MyProcessorB.name,
),
).toBeTruthy();
});

it('should reach the processor supplied with `useFactory`', () => {
const scanPrototypeCalls = jest.spyOn(
metadataScanner,
'scanFromPrototype',
).mock.calls;

const scanPrototypeCallsFirstArgsEveryCall = scanPrototypeCalls.flatMap(
(args) => args[0],
);

expect(
scanPrototypeCallsFirstArgsEveryCall.some(
(instanceWrapperInstance) =>
instanceWrapperInstance.constructor.name === MyProcessorC.name,
),
).toBeTruthy();
});
});
});
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"module": "commonjs",
"declaration": true,
"noImplicitAny": false,
"lib": ["ES2019"],
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
Expand Down

0 comments on commit a72c686

Please sign in to comment.