fix the dang integration tests
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 32m44s

This commit is contained in:
2026-01-05 22:38:21 -08:00
parent 0478e176d5
commit 6b2079ef2c
16 changed files with 121 additions and 56 deletions

View File

@@ -1,9 +1,8 @@
// src/tests/integration/user.integration.test.ts
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
import supertest from 'supertest';
import path from 'path';
import fs from 'node:fs/promises';
import app from '../../../server';
import { logger } from '../../services/logger.server';
import { getPool } from '../../services/db/connection.db';
import type { UserProfile, MasterGroceryItem, ShoppingList } from '../../types';
@@ -15,9 +14,8 @@ import { cleanupFiles } from '../utils/cleanupFiles';
* @vitest-environment node
*/
const request = supertest(app);
describe('User API Routes Integration Tests', () => {
let request: ReturnType<typeof supertest>;
let testUser: UserProfile;
let authToken: string;
const createdUserIds: string[] = [];
@@ -25,6 +23,10 @@ describe('User API Routes Integration Tests', () => {
// 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 () => {
vi.stubEnv('FRONTEND_URL', 'https://example.com');
const app = (await import('../../../server')).default;
request = supertest(app);
const email = `user-test-${Date.now()}@example.com`;
const { user, token } = await createAndLoginUser({ email, fullName: 'Test User', request });
testUser = user;
@@ -35,6 +37,7 @@ describe('User API Routes Integration Tests', () => {
// After all tests, clean up by deleting the created user.
// This now cleans up ALL users created by this test suite to prevent pollution.
afterAll(async () => {
vi.unstubAllEnvs();
await cleanupDb({ userIds: createdUserIds });
// Safeguard to clean up any avatar files created during tests.