Skip to content

feat(posts): add backend endorsement system (tests failing)#16

Draft
michelleguo04 wants to merge 2 commits into
mainfrom
feat/endorse-backend-sample
Draft

feat(posts): add backend endorsement system (tests failing)#16
michelleguo04 wants to merge 2 commits into
mainfrom
feat/endorse-backend-sample

Conversation

@michelleguo04
Copy link
Copy Markdown

@michelleguo04 michelleguo04 commented Oct 11, 2025

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

@michelleguo04 michelleguo04 changed the title Feat/endorse backend sample feat(posts): add backend endorsement system (tests failing) Oct 11, 2025
@thejonathangu thejonathangu self-requested a review October 11, 2025 02:27
Copy link
Copy Markdown

@thejonathangu thejonathangu left a comment

Choose a reason for hiding this comment

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

Its not passing the flaky test with validation email

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants