test: add failing test for CI - #1
Merged
Merged
Conversation
Update package.json migrate script to run `node-pg-migrate up` instead of invoking the binary without a subcommand. This ensures the npm script applies migrations (consistent with migrate:test) when executed.
Implement comment-like functionality across the stack: add a DB migration to create user_comment_likes with FK constraints and a uniqueness constraint; introduce UserCommentLikeRepository interface and Postgres implementation (add/verify/delete like). Add ToggleLikeCommentUseCase to toggle likes after verifying thread/comment existence. Expose a new HTTP endpoint (PUT /threads/:threadId/comments/:commentId/likes) with handler, route, and JWT auth middleware. Update ThreadRepositoryPostgres to fetch comments with aggregated like counts and return comments as part of the thread, and adjust GetThreadDetailUseCase to use thread.comments and include likeCount. Update DetailComment entity and its tests to require and validate likeCount. Also rename error middleware path to Interfaces/http/middlewares/errorMiddleware.js.
Move likes handlers/routes from src/Interfaces/http/api/comments/likes to src/Interfaces/http/api/likes, adjust middleware import paths accordingly, and register the likes router in createServer (mounted under /threads). This reorganizes the likes endpoint into a top-level API module and ensures it is wired into the server.
Register ToggleLikeCommentUseCase and UserCommentLikeRepository in createServer, and inject the use case into the likes route. Replace the old JWT-based auth middleware with a simpler authMiddleware that checks req.auth.credentials, update LikeCommentHandler to read user id from req.auth.credentials, and adapt likes routes to be mounted under /threads (relative path) and accept a handler instance. Also relocate error middleware to _middlewares. These changes wire the like-toggle feature and harmonize authentication routing/injection.
Instantiate LikeCommentHandler and pass the handler to the likes routes instead of forwarding the container. Adds an import for LikeCommentHandler and updates the default export to create the handler from the container and supply it to routes, ensuring the routes receive the proper handler instance.
Move express.Router() creation into the exported function so a fresh router instance is created per handler invocation instead of sharing a single router at module scope. This prevents cross-request/handler conflicts and allows handler-specific wiring.
Correct the import path for authMiddleware in src/Interfaces/http/api/likes/routes.js from '../../_middleware/authMiddleware.js' to '../../_middlewares/authMiddleware.js' to match the actual directory name and avoid module resolution errors. No functional changes made.
Import nanoid and set it as the default id generator for UserCommentLikeRepositoryPostgres (constructor defaults to nanoid). Removed the previous domain repository inheritance/import and updated createServer to pass nanoid when instantiating the repository so the id generator is explicit and available.
Safely destructure userId from req.auth using optional chaining and handle missing authentication: if userId is absent, respond with 401 and a JSON fail message ('Missing authentication'). This prevents runtime errors when auth credentials are not present before invoking ToggleLikeCommentUseCase.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.