Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app-generic): add test for add job use case to check the injected queue service #3941

Merged
merged 1 commit into from
Aug 11, 2023

Conversation

p-fernandez
Copy link
Contributor

What change does this PR introduce?

Adds unit test for AddJob use case.

Why was this change needed?

To validate the QueueService injection in the MemoryDB PR for validation.

Other information (Screenshots)

@p-fernandez p-fernandez self-assigned this Aug 9, 2023
@linear
Copy link

linear bot commented Aug 9, 2023

@@ -0,0 +1,77 @@
import { Test } from '@nestjs/testing';
import { ExecutionDetailsRepository, JobRepository } from '@novu/dal';
import { UserSession } from '@novu/testing';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some unused imports and variables ;)

Comment on lines 63 to 75
it('should instantiate properly the use case', async () => {
const queueService = useCase.getQueueService();

expect(queueService.DEFAULT_ATTEMPTS).toEqual(3);
expect(queueService.name).toEqual('standard');
const { bullMqService } = queueService;
expect(bullMqService).toBeDefined();
expect(await bullMqService.getRunningStatus()).toEqual({
queueIsPaused: false,
queueName: 'standard',
workerIsRunning: undefined,
workerName: undefined,
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've created the test for the AddJob use-case but just checking if the queue is instantiated properly? 🤔
is something missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to validate that the queueName used by the BullMqService is the right one for the intentions of AddJob. I am facing problems with the DI on the MemoryDB PR and I am going back and forth from next to that PR to double check I am doing the changes properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are facing problems with DI typically it's because few provider instances have the same interface. If that's still a problem maybe you should use the "named" injections.

Comment on lines 39 to 41
public getQueueService(): QueueService {
return this.queueService;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to expose it this way, in the test you can do (useCase as any).queueService

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the visibility to public readonly as I consider bad advise with hacking the type away as I mentioned in previous PRs.

@p-fernandez p-fernandez added this pull request to the merge queue Aug 11, 2023
Merged via the queue into next with commit ce7ba1e Aug 11, 2023
25 checks passed
@p-fernandez p-fernandez deleted the nv-2676-addjob-use-case-test branch August 11, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants