tests cannot connect to db
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 1m20s
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 1m20s
This commit is contained in:
@@ -27,6 +27,11 @@ const upload = multer({ storage: storage });
|
||||
* both authenticated and anonymous users to upload flyers.
|
||||
*/
|
||||
router.post('/process-flyer', optionalAuth, upload.array('flyerImages'), async (req: Request, res: Response, next: NextFunction) => {
|
||||
// --- AI ROUTE DEBUG LOGGING ---
|
||||
logger.debug('[API /ai/process-flyer] Request received.');
|
||||
logger.debug(`[API /ai/process-flyer] Files received: ${req.files ? (req.files as Express.Multer.File[]).length : 0}`);
|
||||
logger.debug(`[API /ai/process-flyer] Body masterItems (first 50 chars): ${req.body.masterItems?.substring(0, 50)}...`);
|
||||
// --- END DEBUG LOGGING ---
|
||||
try {
|
||||
if (!req.files || !Array.isArray(req.files) || req.files.length === 0) {
|
||||
return res.status(400).json({ message: 'Flyer image files are required.' });
|
||||
|
||||
@@ -201,11 +201,15 @@ const jwtOptions = {
|
||||
};
|
||||
|
||||
passport.use(new JwtStrategy(jwtOptions, async (jwt_payload, done) => {
|
||||
logger.debug('[JWT Strategy] Verifying token payload:', { jwt_payload });
|
||||
try {
|
||||
// The jwt_payload contains the data you put into the token during login (e.g., { id: user.id, email: user.email }).
|
||||
// We re-fetch the user from the database here to ensure they are still active and valid.
|
||||
const userProfile = await db.findUserProfileById(jwt_payload.id);
|
||||
|
||||
// --- JWT STRATEGY DEBUG LOGGING ---
|
||||
logger.debug(`[JWT Strategy] DB lookup for user ID ${jwt_payload.id} result: ${userProfile ? 'FOUND' : 'NOT FOUND'}`);
|
||||
|
||||
if (userProfile) {
|
||||
return done(null, userProfile); // User profile object will be available as req.user in protected routes
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import * as apiClient from '../services/apiClient';
|
||||
import { getPool } from '../services/db/connection';
|
||||
import type { User } from '../types';
|
||||
|
||||
/**
|
||||
@@ -26,6 +27,15 @@ describe('User API Routes Integration Tests', () => {
|
||||
let testUser: User;
|
||||
let authToken: string;
|
||||
|
||||
// --- START DEBUG LOGGING ---
|
||||
// Query the DB from within the test file to see its state.
|
||||
beforeAll(async () => {
|
||||
const res = await getPool().query('SELECT u.id, u.email, p.role FROM public.users u JOIN public.profiles p ON u.id = p.id');
|
||||
console.log('\n--- [user.integration.test.ts] Users found in DB from TEST perspective (beforeAll): ---');
|
||||
console.table(res.rows);
|
||||
console.log('-------------------------------------------------------------------------------------\n');
|
||||
});
|
||||
// --- END DEBUG LOGGING ---
|
||||
// Before any tests run, create a new user and log them in.
|
||||
// The token will be used for all subsequent API calls in this test suite.
|
||||
beforeAll(async () => {
|
||||
@@ -38,6 +48,7 @@ describe('User API Routes Integration Tests', () => {
|
||||
// After all tests, clean up by deleting the created user.
|
||||
afterAll(async () => {
|
||||
if (testUser) {
|
||||
logger.debug(`[user.integration.test.ts afterAll] Cleaning up user ID: ${testUser.id}`);
|
||||
// This requires an authenticated call to delete the account.
|
||||
await apiClient.deleteUserAccount(TEST_PASSWORD, authToken);
|
||||
}
|
||||
|
||||
@@ -151,6 +151,10 @@ router.delete('/users/account', async (req: Request, res: Response) => {
|
||||
const authenticatedUser = req.user as { id: string; email: string };
|
||||
const { password } = req.body;
|
||||
|
||||
// --- DELETE ACCOUNT DEBUG LOGGING ---
|
||||
logger.debug(`[API /users/account] Authenticated user from JWT:`, { user: req.user });
|
||||
// --- END DEBUG LOGGING ---
|
||||
|
||||
if (!password) {
|
||||
return res.status(400).json({ message: 'Password is required for account deletion.' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user