feat(posts): add backend endorsement system (tests failing)#16
Draft
michelleguo04 wants to merge 2 commits into
Draft
feat(posts): add backend endorsement system (tests failing)#16michelleguo04 wants to merge 2 commits into
michelleguo04 wants to merge 2 commits into
Conversation
thejonathangu
left a comment
There was a problem hiding this comment.
Its not passing the flaky test with validation email
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.
This branch cannot be merged into main because automated tests are failing. Additional debugging or test updates are required before merge approval.
Justification: I have tried several approaches in implementing the endorsement function. They all could not get over a test. My local npm run test passes on every try and I have tried rerunning the test on github, yet it kept giving the same test error related to post/emails on the github tests. Teammate Jonathan has fixed the post/emails bug in his latest version on main, but it reappears in my section. The committed code in this section might seem a lot, but they are smaller sections that were implemented previously on separate branches.
Change description:
Implements the complete backend functionality for post endorsements, including API routes, data handling, and integration across posts, topics, and search modules.
Issue #4
Issue #5
Isusue #7
BACKEND
src/posts/endorsements.js (New File)
Created the core endorsement logic module
Implemented:
Posts.endorse() — allows moderators/admins to endorse posts
Posts.unendorse() — removes endorsements
Posts.hasEndorsed() — checks if a user has endorsed post(s)
Posts.getEndorsers() — retrieves all users who endorsed a post
Added permission checks for administrators and moderators
Uses database sets (pid:${pid}:endorsers) to track endorsers
Fires plugin hooks:
action:post.endorse
action:post.unendorse
src/database/migrations/2025-01-27-add-endorsements-to-posts.js (New File)
Added endorsements field to post objects
Ensures all existing posts have the field initialized
API
src/api/posts.js
Added API methods for endorse and unendorse operations
Integrated these with the core endorsements module
src/api/helpers.js
Updated helper functions to support endorsement-related API responses
src/controllers/write/posts.js
Added:
Posts.endorse() controller handler
Posts.unendorse() controller handler
Both use the mock() helper for request preparation
src/routes/write/posts.js
Registered new routes:
PUT /api/v3/posts/:pid/endorse
DELETE /api/v3/posts/:pid/endorse
Routes require authentication and post assertion middleware
Database
src/posts/data.js
Updated post data retrieval to include endorsement info
src/posts/summary.js
Added endorsements to post summary retrieval
Added stripEndorsements option for search API compatibility
Handles endorsement visibility in anonymous post scenarios
src/posts/index.js
Integrated the endorsements module into the main Posts module
src/posts/diffs.js
Updated to handle endorsement data during post edits/diffs