unit tests fixin
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 1m43s
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 1m43s
This commit is contained in:
21
.env.test
Normal file
21
.env.test
Normal 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
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"test:integration": "vitest run -c vitest.config.integration.ts",
|
"test:integration": "vitest run -c vitest.config.integration.ts",
|
||||||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
"seed": "ts-node-dev scripts/seed.ts",
|
"seed": "ts-node-dev scripts/seed.ts",
|
||||||
"start:server": "tsx server.ts"
|
"start:server": "tsx --env-file .env.test server.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@google/genai": "^1.30.0",
|
"@google/genai": "^1.30.0",
|
||||||
|
|||||||
@@ -23,18 +23,20 @@ describe('Shopping List DB Service Tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should create and retrieve a shopping list for a user', async () => {
|
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, 'Weekly Groceries');
|
||||||
await db.createShoppingList(testUserId, 'Party Supplies');
|
await db.createShoppingList(testUserId, 'Party Supplies');
|
||||||
|
|
||||||
// Act: Fetch the shopping lists for that user
|
// Act: Fetch the shopping lists for that user
|
||||||
const lists = await db.getShoppingLists(testUserId);
|
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).toBeDefined();
|
||||||
expect(lists).toHaveLength(2);
|
expect(lists).toHaveLength(3);
|
||||||
expect(lists[0].name).toBe('Weekly Groceries');
|
expect(lists.some(list => list.name === 'Main Shopping List')).toBe(true);
|
||||||
expect(lists[1].name).toBe('Party Supplies');
|
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 () => {
|
it('should not retrieve shopping lists belonging to another user', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user