test: fix failing tests by adding mocks to bullmq

This commit is contained in:
Nicolas Meienberger 2023-08-15 23:12:25 +02:00 committed by Nicolas Meienberger
parent 583a982930
commit 77dd73bdb4
4 changed files with 21 additions and 7 deletions

View file

@ -5,7 +5,7 @@ on:
env:
ROOT_FOLDER: /runtipi
JWT_SECRET: 'secret'
ROOT_FOLDER_HOST: /tipi
ROOT_FOLDER_HOST: /runtipi
APPS_REPO_ID: repo-id
INTERNAL_IP: localhost
REDIS_HOST: redis

View file

@ -22,7 +22,7 @@ describe('ResetPasswordContainer', () => {
render(<ResetPasswordContainer isRequested={false} />);
expect(screen.getByText('Reset your password')).toBeInTheDocument();
expect(screen.getByText('Run this command on your server and then refresh this page')).toBeInTheDocument();
expect(screen.getByText('./scripts/reset-password.sh')).toBeInTheDocument();
expect(screen.getByText('./runtipi-cli reset-password')).toBeInTheDocument();
});
it('should render the password reset success message', async () => {

View file

@ -24,11 +24,13 @@ class EventDispatcher {
public async cleanRepeatableJobs() {
const repeatableJobs = await this.queue.getRepeatableJobs();
await Promise.all(
repeatableJobs.map(async (job) => {
await this.queue.removeRepeatableByKey(job.key);
}),
);
if (repeatableJobs) {
await Promise.all(
repeatableJobs.map(async (job) => {
await this.queue.removeRepeatableByKey(job.key);
}),
);
}
}
public static getInstance(): EventDispatcher {

View file

@ -13,6 +13,18 @@ jest.mock('vitest', () => ({
vi: jest,
}));
jest.mock('bullmq', () => ({
Queue: jest.fn().mockImplementation(() => ({
add: jest.fn(),
getRepeatableJobs: jest.fn().mockResolvedValue([]),
removeRepeatableByKey: jest.fn(),
obliterate: jest.fn(),
})),
QueueEvents: jest.fn().mockImplementation(() => ({
on: jest.fn(),
})),
}));
console.error = jest.fn();
beforeEach(async () => {