From bfbfd0e72987ea182203ec19c640aebf5e8552ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Gierwia=C5=82o?= Date: Wed, 19 Nov 2025 20:23:25 +0100 Subject: [PATCH] test: fix auth test expectations and add test commands to Makefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update auth.test.js to match current API error messages - Registration success message includes email verification notice - Duplicate credentials use generic message to prevent user enumeration - Add test commands to Makefile - make test: run all backend tests - make test-watch: run tests in watch mode - make test-coverage: run tests with coverage report All auth tests now pass (19/19 ✓) --- Makefile | 16 +++++++++++++++- backend/src/__tests__/auth.test.js | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 8b36344..10113ea 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,8 @@ endif .PHONY: help dev-cli prod-cli \ dev-up dev-down dev-up-rebuild \ - prod-up prod-down prod-up-rebuild + prod-up prod-down prod-up-rebuild \ + test test-watch test-coverage help: @echo "Available targets:" @@ -23,6 +24,9 @@ help: @echo " make prod-up # docker compose --profile prod up -d" @echo " make prod-up-rebuild # docker compose --profile prod up -d --build" @echo " make prod-down # docker compose --profile prod down" + @echo " make test # Run backend tests" + @echo " make test-watch # Run backend tests in watch mode" + @echo " make test-coverage # Run backend tests with coverage report" @echo "Notes: GNU Make nie wspiera subkomend z odstępami (np. 'make prod up')." @echo " Użyj odpowiednich celów z myślnikiem." @@ -52,3 +56,13 @@ prod-up-rebuild: prod-down: $(COMPOSE) --profile prod down + +# Tests +test: + $(COMPOSE) exec $(BACKEND_SVC) npm test + +test-watch: + $(COMPOSE) exec $(BACKEND_SVC) npm run test:watch + +test-coverage: + $(COMPOSE) exec $(BACKEND_SVC) npm test -- --coverage diff --git a/backend/src/__tests__/auth.test.js b/backend/src/__tests__/auth.test.js index 2c6a1ef..c30ba2d 100644 --- a/backend/src/__tests__/auth.test.js +++ b/backend/src/__tests__/auth.test.js @@ -27,7 +27,7 @@ describe('Authentication API Tests', () => { .expect(201); expect(response.body).toHaveProperty('success', true); - expect(response.body).toHaveProperty('message', 'User registered successfully'); + expect(response.body).toHaveProperty('message', 'User registered successfully. Please check your email to verify your account.'); expect(response.body.data).toHaveProperty('user'); expect(response.body.data).toHaveProperty('token'); expect(response.body.data.user).toHaveProperty('id'); @@ -49,7 +49,7 @@ describe('Authentication API Tests', () => { .expect(400); expect(response.body).toHaveProperty('success', false); - expect(response.body).toHaveProperty('error', 'Email already registered'); + expect(response.body).toHaveProperty('error', 'An account with these credentials already exists. Please try logging in or use different credentials.'); }); it('should reject registration with duplicate username', async () => { @@ -64,7 +64,7 @@ describe('Authentication API Tests', () => { .expect(400); expect(response.body).toHaveProperty('success', false); - expect(response.body).toHaveProperty('error', 'Username already taken'); + expect(response.body).toHaveProperty('error', 'An account with these credentials already exists. Please try logging in or use different credentials.'); }); it('should reject registration with invalid email', async () => {