From dfc86c807d25e57d24e350adccc0cd44aff91c2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Gierwia=C5=82o?= Date: Sat, 6 Dec 2025 14:29:47 +0100 Subject: [PATCH] fix(tests): add activity_logs table and fix matches test - Create migration for activity_logs table (full schema with indexes) - Fix matches.test.js to use dynamic username for outsider user - Prevents unique constraint violations when tests run multiple times Progress: 7 failed, 349 passed, 9 skipped (down from 8 failures) --- .../migration.sql | 36 +++++++++++++++++++ backend/src/__tests__/matches.test.js | 4 +-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 backend/prisma/migrations/20251206130000_create_activity_logs/migration.sql diff --git a/backend/prisma/migrations/20251206130000_create_activity_logs/migration.sql b/backend/prisma/migrations/20251206130000_create_activity_logs/migration.sql new file mode 100644 index 0000000..c6281ee --- /dev/null +++ b/backend/prisma/migrations/20251206130000_create_activity_logs/migration.sql @@ -0,0 +1,36 @@ +-- CreateTable +CREATE TABLE "activity_logs" ( + "id" SERIAL NOT NULL, + "user_id" INTEGER, + "username" VARCHAR(50), + "ip_address" VARCHAR(45), + "action" VARCHAR(50) NOT NULL, + "category" VARCHAR(20) NOT NULL, + "resource" VARCHAR(100), + "method" VARCHAR(10), + "path" VARCHAR(255), + "metadata" JSONB, + "success" BOOLEAN NOT NULL DEFAULT true, + "error_message" TEXT, + "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "activity_logs_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE INDEX "activity_logs_user_id_created_at_idx" ON "activity_logs"("user_id", "created_at"); + +-- CreateIndex +CREATE INDEX "activity_logs_action_created_at_idx" ON "activity_logs"("action", "created_at"); + +-- CreateIndex +CREATE INDEX "activity_logs_category_created_at_idx" ON "activity_logs"("category", "created_at"); + +-- CreateIndex +CREATE INDEX "activity_logs_created_at_idx" ON "activity_logs"("created_at" DESC); + +-- CreateIndex +CREATE INDEX "activity_logs_username_created_at_idx" ON "activity_logs"("username", "created_at"); + +-- AddForeignKey +ALTER TABLE "activity_logs" ADD CONSTRAINT "activity_logs_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/backend/src/__tests__/matches.test.js b/backend/src/__tests__/matches.test.js index 896014e..7a56760 100644 --- a/backend/src/__tests__/matches.test.js +++ b/backend/src/__tests__/matches.test.js @@ -318,8 +318,8 @@ describe('Matches API Tests', () => { // Create third user const testUser3 = await prisma.user.create({ data: { - username: 'outsider', - email: 'outsider@example.com', + username: `outsider_${Date.now()}`, + email: `outsider_${Date.now()}@example.com`, passwordHash: await hashPassword('password123'), emailVerified: true, },