diff --git a/.env.test b/.env.test new file mode 100644 index 00000000..655248af --- /dev/null +++ b/.env.test @@ -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 \ No newline at end of file diff --git a/package.json b/package.json index 8bb0c870..589c57df 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/services/shopping-list.integration.test.ts b/src/services/shopping-list.integration.test.ts index 5d67c110..ebbceed9 100644 --- a/src/services/shopping-list.integration.test.ts +++ b/src/services/shopping-list.integration.test.ts @@ -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 () => {