mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 02:51:34 +00:00
The integration tests for admin-only mutations were failing due to an authorization issue. The root cause was that the JWT token used in the tests did not reflect the user's admin role, which was being set directly in the database. This commit fixes the issue by: 1. Updating the `CreateAuthenticatedUser` test helper to generate a new JWT token after a user's role is changed. This ensures the token contains the correct, up-to-date role. 2. Removing all uses of `auth.ContextWithAdminUser` from the integration tests, making the JWT token the single source of truth for authorization. This change also removes unused imports and variables that were causing build failures after the refactoring. All integration tests now pass.
1.4 KiB
1.4 KiB
Agent Debugging Log
Issue: Integration Test Failures
I've been encountering a series of integration test failures related to unauthorized, forbidden, and directive binding is not implemented errors.
Initial Investigation
directive binding is not implementederror: This error was caused by the test server ininternal/adapters/graphql/integration_test.gonot being configured with the necessary validation directive.unauthorizedandforbiddenerrors: These errors were caused by tests that require authentication not being run with an authenticated user.- Build Error: My initial attempts to fix the test server setup introduced a build error in
cmd/apidue to a function signature mismatch inNewServerWithAuth.
Resolution Path
- Fix Build Error: I corrected the function signature in
cmd/api/server.goto match the call site incmd/api/main.go. This resolved the build error. - Fix Test Server Setup: I updated the
SetupSuitefunction ininternal/adapters/graphql/integration_test.goto register thebindingdirective, aligning the test server configuration with the production server. - Fix Authentication in Tests: The remaining
forbiddenerrors are because the tests are not passing the authentication token for an admin user. I will now modify the failing tests to create an admin user and pass the token in theexecuteGraphQLfunction.