lootsa tests fixes
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m30s

This commit is contained in:
2025-12-05 19:56:49 -08:00
parent 7829dd52d5
commit 7added99b8
5 changed files with 22 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
// src/routes/auth.test.ts
// src/routes/auth.routes.test.ts
import { describe, it, expect, vi, beforeEach } from 'vitest';
import supertest from 'supertest';
import express, { Request } from 'express';
@@ -49,9 +49,9 @@ vi.mock('bcrypt', async (importOriginal) => {
type PassportCallback = (error: Error | null, user: Express.User | false, info?: { message: string }) => void;
// Mock Passport middleware
vi.mock('./passport', () => ({
vi.mock('./passport.routes', () => ({
default: {
authenticate: (strategy: string, options: Record<string, unknown>, callback: PassportCallback) => (req: Request) => {
authenticate: (strategy: string, options: Record<string, unknown>, callback: PassportCallback) => (req: Request, res: any, next: any) => {
// Logic to simulate passport authentication outcome based on test input
if (req.body.password === 'wrong_password') {
// Simulate incorrect credentials
@@ -70,6 +70,7 @@ vi.mock('./passport', () => ({
const user = { user_id: 'user-123', email: req.body.email };
callback(null, user, undefined);
},
initialize: () => (req: any, res: any, next: any) => next(),
},
}));
@@ -79,6 +80,12 @@ app.use(express.json({ strict: false }));
app.use(cookieParser()); // Add cookie-parser middleware to populate req.cookies
app.use('/api/auth', authRouter);
// Add error handler to catch and log 500s during tests
app.use((err: any, req: Request, res: any, next: any) => {
console.error('[TEST APP ERROR]', err);
res.status(500).json({ message: err.message });
});
describe('Auth Routes (/api/auth)', () => {
beforeEach(() => {
vi.clearAllMocks();

View File

@@ -7,14 +7,19 @@ import { exec } from 'child_process';
import { geocodeAddress } from '../services/geocodingService.server';
// FIX: Use the simple factory pattern for child_process to avoid default export issues
vi.mock('child_process', () => ({
exec: vi.fn((command, callback) => {
vi.mock('child_process', () => {
const mockExec = vi.fn((command, callback) => {
if (typeof callback === 'function') {
callback(null, 'PM2 OK', '');
}
return { unref: () => {} };
})
}));
});
return {
default: { exec: mockExec },
exec: mockExec
};
});
// 2. Mock Geocoding
vi.mock('../services/geocodingService.server', () => ({

View File

@@ -1,4 +1,4 @@
// src/routes/user.ts
// src/routes/user.routes.ts
import express, { Request, Response } from 'express';
import passport from './passport.routes';
import multer from 'multer';

View File

@@ -10,7 +10,7 @@ import { AdminUserView } from './db/admin.db';
// Mock dependencies
vi.mock('node-cron');
vi.mock('./db');
vi.mock('./db/index.db');
vi.mock('./logger.server');
vi.mock('./emailService.server');

View File

@@ -1,4 +1,4 @@
// src/tests/setup/unit-setup.ts
// src/tests/setup/tests-setup-unit.ts
import { vi, afterEach } from 'vitest';
import { cleanup } from '@testing-library/react';
import '@testing-library/jest-dom/vitest';