unit tests fixin
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 1m43s

This commit is contained in:
2025-11-22 10:30:33 -08:00
parent 3081e3998a
commit f64eb42233
3 changed files with 29 additions and 6 deletions

21
.env.test Normal file
View File

@@ -0,0 +1,21 @@
# .env.test
# Environment variables for the test environment.
# This file is loaded by `tsx` when running the `npm run test:integration` command.
# --- Test Database Connection ---
# IMPORTANT: These should point to your *test* database, not production.
# These values will be used by the backend server when it starts for integration tests.
DB_HOST=localhost
DB_PORT=5432
DB_USER=flyer_crawler_user
DB_PASSWORD=WoA2kFtqqHdTLqdZsoCa
DB_DATABASE=flyer-crawler-test
DB_NAME=flyer-crawler-test
# --- Test JWT Secret ---
JWT_SECRET=a-secure-secret-for-testing-only
# --- Other Test Variables ---
# These can be dummy values if the feature is not being tested directly.
FRONTEND_URL=http://localhost:3000
GEMINI_API_KEY=dummy-api-key-for-testing

View File

@@ -11,7 +11,7 @@
"test:integration": "vitest run -c vitest.config.integration.ts",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"seed": "ts-node-dev scripts/seed.ts",
"start:server": "tsx server.ts"
"start:server": "tsx --env-file .env.test server.ts"
},
"dependencies": {
"@google/genai": "^1.30.0",

View File

@@ -23,18 +23,20 @@ describe('Shopping List DB Service Tests', () => {
});
it('should create and retrieve a shopping list for a user', async () => {
// Arrange: Create two lists for our test user
// Arrange: The `beforeEach` hook already creates a user, which in turn
// triggers the creation of a "Main Shopping List". We then create two more.
await db.createShoppingList(testUserId, 'Weekly Groceries');
await db.createShoppingList(testUserId, 'Party Supplies');
// Act: Fetch the shopping lists for that user
const lists = await db.getShoppingLists(testUserId);
// Assert: Check that we got the correct lists back
// Assert: We expect to find 3 lists: the default one and the two we just created.
expect(lists).toBeDefined();
expect(lists).toHaveLength(2);
expect(lists[0].name).toBe('Weekly Groceries');
expect(lists[1].name).toBe('Party Supplies');
expect(lists).toHaveLength(3);
expect(lists.some(list => list.name === 'Main Shopping List')).toBe(true);
expect(lists.some(list => list.name === 'Weekly Groceries')).toBe(true);
expect(lists.some(list => list.name === 'Party Supplies')).toBe(true);
});
it('should not retrieve shopping lists belonging to another user', async () => {