Skip to content

feat: perform end to end testing of admin interfaces and bugfixes - #50

Open
vtotalova wants to merge 72 commits into
mainfrom
feature/47-test-perform-end-to-end-testing-of-admin-interfaces
Open

feat: perform end to end testing of admin interfaces and bugfixes#50
vtotalova wants to merge 72 commits into
mainfrom
feature/47-test-perform-end-to-end-testing-of-admin-interfaces

Conversation

@vtotalova

Copy link
Copy Markdown
Contributor

Description

Adds a frontend-side integration test suite (npm run test:integration) that exercises the real
frontend axios client against the running backend stack — covering every REST module: auth,
competencies, learning resources, users, relationships, resource links, scheduling/voting,
contributor stats, and admin imports. While building it, the suite surfaced four real bugs across
the FE and BE; this PR fixes them and refreshes outdated documentation.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • 📝 Documentation update
  • 🎨 Style/formatting changes (no functional changes)
  • ♻️ Code refactoring (no functional changes)
  • ⚡ Performance improvements
  • 🔧 Configuration changes
  • 🧪 Test additions or modifications
  • 🚀 Deployment/DevOps changes

Related Issues

  • Fixes #
  • Related to #

Changes Made

Client:

  • Added Vitest + a focused integration suite under src/lib/api/__tests__/ (9 files, 42 tests)
    driving the real src/lib/api/* modules against the running backend.
  • Added src/test/ harness: Keycloak password-grant token helper with idempotent admin-API user
    bootstrap, direct Postgres helpers for admin promotion and test-data cleanup, cached fixtures
    for getUserToken/getAdminToken/authAs.
  • Added vitest.integration.config.ts (single-fork, sequential, scoped to *.integration.test.ts).
  • Added npm run test:integration script.
  • Bug fix in src/lib/api/client.ts: response interceptor now mutates error.message and
    re-throws the original AxiosError instead of wrapping it in a plain Error — restores
    axios.isAxiosError(err) so the 404→null fallbacks in getByUrl and getByEmail actually fire.

Server:

  • Bug fix in SecurityConfig.java: POST /api/users/me/accept-consent and
    GET /api/users/{userId}/stats were caught by the catch-all /api/users/** ADMIN matcher and
    returned 403 for regular users. Added two specific authenticated matchers ahead of the catch-all
    so users can accept their own consent and view their own stats.
  • Bug fix in CompetencyResourceLink.java: added @JsonIgnore on the three lazy @ManyToOne
    associations (competency, resource, user) — GET /api/competency-resource-links/{id} and
    /api/competency-resource-links were returning 500 "Type definition error: ByteBuddyInterceptor"
    because Jackson was trying to serialize the Hibernate proxies. Scalar competencyId/resourceId/
    userId fields stay in the response, so the API contract is unchanged.
  • Test fix in UserRepositoryTest.shouldEnforceUniqueEmail: with @Sql setting the constraint
    to IMMEDIATE, the conflicting saveAndFlush(user2) throws right there — the assertion was
    wrapping a no-op SET CONSTRAINTS IMMEDIATE call instead of the actual write. Moved
    assertThatThrownBy around saveAndFlush(user2) and updated the expected type to
    DataIntegrityViolationException (the exception actually thrown).
  • Spotless formatting cleanup on DbRoleJwtAuthenticationConverterTest.java (pre-existing
    violation that broke ./gradlew build).

Database:

  • No schema changes.

Other:

  • Added e2e-user@memo.local / e2e-user (USER) and e2e-admin@memo.local / e2e-admin (ADMIN)
    to server/docker/keycloak/memo-realm.json, both pre-verified.
  • Updated CLAUDE.md — corrected stack (Vite/React Router 7, not Next.js; Spring Boot 3.4 / Java
    17 / Postgres 18, not 4.0/25/16); removed references to non-existent QUICKSTART.md and
    MIGRATION_COMPLETE.md and the deleted nextjs-expert agent.
  • Updated README.md — fixed the frontend port (3000, not 5173), replaced the never-existing
    demo/admin default users with the actually-seeded e2e-user/e2e-admin, removed the bogus
    POST /api/competency-relationships endpoint reference, added an Integration Tests section.
  • Updated server/README.md — full endpoint inventory with role gates, fixed seeded users, fixed
    the curl example, added a note on DB-driven role resolution.
  • Deleted scripts/init-db.sql (unreferenced; comment claimed Prisma but project uses Flyway) and
    the now-empty scripts/ directory.
  • Deleted .claude/agents/nextjs-expert.md (project is Vite, not Next.js).

Testing

Test Cases

  • Existing functionality still works (./gradlew build is green; pre-existing
    UserRepositoryTest.shouldEnforceUniqueEmail was failing on main and is now fixed)
  • New functionality works as expected (integration suite: 9 files, 42 tests, all green
    against the running docker stack)
  • Edge cases handled appropriately (RBAC denial paths covered for non-admin users on admin
    endpoints; 404→null fallbacks tested for getByUrl/getByEmail; all four vote types
    tested in scheduling)

Manual Testing

  • Tested in development environment
    • cd server && ./server-manage.sh up → stack healthy
    • npm run test:integration → 42/42 passing in ~3s
    • ./gradlew build → green (spotless + tests + bootJar)
    • npm run quality → green
  • Tested with different user roles/permissions (if applicable)
    • Verified regular e2e-user can accept own consent and read own stats
    • Verified e2e-user is correctly denied on admin-only endpoints (delete competency, list
      users, admin import)
    • Verified e2e-admin succeeds on the same endpoints

markstockhausen and others added 30 commits February 3, 2026 02:22
…sable component to use it on main page and while onboarding
@vtotalova vtotalova added this to the v0.1.0 milestone Apr 26, 2026
@vtotalova vtotalova self-assigned this Apr 26, 2026
@vtotalova vtotalova added the documentation Improvements or additions to documentation label Apr 26, 2026
Copilot AI review requested due to automatic review settings April 26, 2026 16:25
@vtotalova vtotalova added the testing 🧪 Test related changes label Apr 26, 2026
@vtotalova vtotalova linked an issue Apr 26, 2026 that may be closed by this pull request
@github-actions github-actions Bot added enhancement New feature or request server ⚙️ Server-side/API changes database 🗃️ Database related changes configuration ⚙️ Configuration file changes dependencies 📦 Dependency updates security 🔒 Security related labels Apr 26, 2026
@vtotalova vtotalova changed the title Feature/47 test perform end to end testing of admin interfaces feat: 47 test perform end to end testing of admin interfaces Apr 26, 2026
@github-actions

Copy link
Copy Markdown

🔍 Code Quality Report

📊 Code Statistics

🚨 Potential Issues

✅ No console statements found
⚠️ Found 'any' or 'unknown' types - consider using more specific types

@vtotalova vtotalova changed the title feat: 47 test perform end to end testing of admin interfaces feat: test perform end to end testing of admin interfaces Apr 26, 2026
@vtotalova vtotalova changed the title feat: test perform end to end testing of admin interfaces feat: perform end to end testing of admin interfaces and bugfixes Apr 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a frontend-driven FE↔BE integration test suite that runs against the real local docker stack, and fixes several issues uncovered during end-to-end coverage (Axios error handling, Spring Security matchers, and Hibernate/Jackson serialization), plus refreshes project documentation and seeded dev/test users.

Changes:

  • Add Vitest-based integration tests + Node test harness (Keycloak token helpers, Postgres helpers, fixtures) and npm run test:integration.
  • Fix FE Axios error handling to preserve AxiosError, fix BE security matcher ordering, and prevent Jackson from serializing lazy Hibernate proxies.
  • Update docs/Keycloak realm seed data and clean up outdated/dead repo artifacts.

Reviewed changes

Copilot reviewed 28 out of 30 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
vitest.integration.config.ts Adds dedicated Vitest config for sequential integration tests.
src/test/setup.ts Mocks Keycloak JS for Node-based tests.
src/test/keycloak-helpers.ts Adds Keycloak password-grant + admin-API bootstrap helpers for tests.
src/test/fixtures.ts Provides cached tokens/IDs and axios auth helpers for integration tests.
src/test/db-helpers.ts Adds direct Postgres helpers for test setup/cleanup.
src/lib/api/client.ts Preserves original AxiosError while improving user-facing error messages.
src/lib/api/__tests__/auth.integration.test.ts Adds auth/me integration coverage (401 + role assertions).
src/lib/api/__tests__/admin.integration.test.ts Adds admin import integration coverage (JSON + file upload + RBAC).
src/lib/api/__tests__/competencies.integration.test.ts Adds competencies CRUD + RBAC integration coverage.
src/lib/api/__tests__/competency-relationships.integration.test.ts Adds relationships listing + voting-created relationship checks.
src/lib/api/__tests__/competency-resource-links.integration.test.ts Adds competency-resource-links CRUD integration coverage.
src/lib/api/__tests__/contributor-stats.integration.test.ts Adds contributor stats response-shape integration coverage.
src/lib/api/__tests__/learning-resources.integration.test.ts Adds learning-resources CRUD + RBAC integration coverage.
src/lib/api/__tests__/scheduling.integration.test.ts Adds scheduling/voting integration coverage (vote types + unvote).
src/lib/api/__tests__/users.integration.test.ts Adds users admin-only API integration coverage + consent acceptance.
server/src/main/java/de/tum/cit/memo/security/SecurityConfig.java Adjusts matcher ordering to allow authenticated access to consent + stats endpoints.
server/src/main/java/de/tum/cit/memo/entity/CompetencyResourceLink.java Prevents Jackson from serializing lazy @ManyToOne proxies.
server/src/main/resources/db/migration/V11__add_consent_ttl_tracking.sql Adds consent tracking columns + backfill for existing users.
server/docker/keycloak/memo-realm.json Seeds e2e-user / e2e-admin for local dev and integration tests.
server/src/test/java/de/tum/cit/memo/security/SecurityConfigIntegrationTest.java Expands security integration assertions (401/403/200 + CORS preflight).
server/src/test/java/de/tum/cit/memo/security/DbRoleJwtAuthenticationConverterTest.java Adds unit tests for DB-driven role conversion behavior.
server/src/test/java/de/tum/cit/memo/repository/UserRepositoryTest.java Fixes unique-email test to assert on the actual write/flush failure.
server/src/test/java/de/tum/cit/memo/controller/AdminInterfaceE2ETest.java Adds server-side E2E tests for admin interfaces across the full stack.
server/README.md Refreshes backend docs: seeded users, endpoint inventory, role gates, curl examples.
README.md Refreshes root docs: ports, seeded users, endpoint highlights, integration test instructions.
CLAUDE.md Updates documented stack/tools and removes references to deleted/outdated docs/agents.
package.json Adds test:integration and dev deps (vitest, pg, @types/pg).
package-lock.json Locks new dev dependencies (Vitest + pg + transitive deps).
scripts/init-db.sql Deletes unused/incorrect DB init script.
.claude/agents/nextjs-expert.md Deletes outdated Next.js-specific Claude agent definition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

.requestMatchers("/swagger-ui/**", "/swagger-ui.html", "/api-docs/**").permitAll()
.requestMatchers("/actuator/health").permitAll()
.requestMatchers(HttpMethod.POST, "/api/users/me/accept-consent").authenticated()
.requestMatchers(HttpMethod.GET, "/api/users/*/stats").authenticated()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines +25 to +30
* DbRoleJwtAuthenticationConverter → Controller → Service → Repository → Database stack.
*
* <p>An admin user with id {@code e2e-admin} is pre-seeded before each test so that
* {@code jwt().jwt(j -> j.subject("e2e-admin"))} resolves to {@code ROLE_ADMIN} through
* the real {@link de.tum.cit.memo.security.DbRoleJwtAuthenticationConverter}.
* Plain {@code jwt()} (unknown subject) resolves to {@code ROLE_USER}.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread package.json Outdated
@github-actions

Copy link
Copy Markdown

🔍 Code Quality Report

📊 Code Statistics

🚨 Potential Issues

✅ No console statements found
⚠️ Found 'any' or 'unknown' types - consider using more specific types

@github-actions

Copy link
Copy Markdown

🔍 Code Quality Report

📊 Code Statistics

🚨 Potential Issues

✅ No console statements found
⚠️ Found 'any' or 'unknown' types - consider using more specific types

@github-actions

Copy link
Copy Markdown

🔍 Code Quality Report

📊 Code Statistics

🚨 Potential Issues

✅ No console statements found
⚠️ Found 'any' or 'unknown' types - consider using more specific types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration ⚙️ Configuration file changes database 🗃️ Database related changes dependencies 📦 Dependency updates documentation Improvements or additions to documentation enhancement New feature or request security 🔒 Security related server ⚙️ Server-side/API changes testing 🧪 Test related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: perform end-to-end testing of admin interfaces

3 participants