Sfoglia il codice sorgente

test: fix failing tests by adding mocks to bullmq

Nicolas Meienberger 1 anno fa
parent
commit
77dd73bdb4

+ 1 - 1
.github/workflows/ci.yml

@@ -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

+ 1 - 1
src/client/modules/Auth/containers/ResetPasswordContainer/ResetPasswordContainer.test.tsx

@@ -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 () => {

+ 7 - 5
src/server/core/EventDispatcher/EventDispatcher.ts

@@ -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 {

+ 12 - 0
tests/server/jest.setup.ts

@@ -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 () => {