Browse Source

test: migrate tests for auth.service to vitest

Nicolas Meienberger 2 years ago
parent
commit
369d20e4b6
2 changed files with 8 additions and 4 deletions
  1. 3 4
      src/server/services/auth/auth.service.test.ts
  2. 5 0
      tests/server/jest.setup.ts

+ 3 - 4
src/server/services/auth/auth.service.test.ts

@@ -1,10 +1,11 @@
 import fs from 'fs-extra';
+import { vi } from 'vitest';
 import * as argon2 from 'argon2';
 import { faker } from '@faker-js/faker';
 import { TotpAuthenticator } from '@/server/utils/totp';
 import { generateSessionId } from '@/server/common/session.helpers';
 import { fromAny, fromPartial } from '@total-typescript/shoehorn';
-import { mockInsert, mockQuery, mockSelect } from '@/server/tests/drizzle-helpers';
+import { mockInsert, mockQuery, mockSelect } from '@/tests/mocks/drizzle';
 import { createDatabase, clearDatabase, closeDatabase, TestDatabase } from '@/server/tests/test-utils';
 import { encrypt } from '../../utils/encryption';
 import { setConfig } from '../../core/TipiConfig';
@@ -23,8 +24,6 @@ beforeAll(async () => {
 });
 
 beforeEach(async () => {
-  jest.mock('fs-extra');
-  jest.mock('redis');
   await setConfig('demoMode', false);
   await clearDatabase(database);
 });
@@ -448,7 +447,7 @@ describe('Test: logout', () => {
 
   it('Should destroy session upon logount', async () => {
     // arrange
-    const destroy = jest.fn();
+    const destroy = vi.fn();
     const req = { session: { userId: 1, destroy } };
 
     // act

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

@@ -7,6 +7,11 @@ global.location = fromPartial({
   hostname: 'localhost',
 });
 
+// Temporary hack to still run all jest tests and get correct coverage
+jest.mock('vitest', () => ({
+  vi: jest,
+}));
+
 console.error = jest.fn();
 
 // Mock Logger