Skip to content

Feature/wishlists notify me restock & price drop alerts#34

Open
heet2312 wants to merge 4 commits into
hoangsonww:masterfrom
heet2312:Feature/Wishlists-Notify-Me-Restock-&-Price-Drop-Alerts
Open

Feature/wishlists notify me restock & price drop alerts#34
heet2312 wants to merge 4 commits into
hoangsonww:masterfrom
heet2312:Feature/Wishlists-Notify-Me-Restock-&-Price-Drop-Alerts

Conversation

@heet2312
Copy link
Copy Markdown

Description

Implements the Wishlist + "Notify Me" (Restock & Price-Drop Alerts) feature requested in Issue #21.

Shoppers can now save products to a personal wishlist and subscribe to email alerts when an out-of-stock item is restocked or when a product's price drops below a chosen threshold or percentage. Alert delivery uses a console transport in development and SendGrid in production, and is gated behind FEATURE_ALERTS=true.

Fixes #21


Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

How Has This Been Tested?

Unit tests — 29 new Jest tests in backend/__tests__/wishlist-alerts.spec.js covering:

  • Wishlist GET / POST / DELETE endpoint validation and happy paths
  • Alert subscribe validation (missing type, invalid type, price_drop without threshold, duplicate active sub)
  • Alert cancel and list (mine) endpoints
  • evaluateSubscriptions service: restock fires/no-fire, price_drop targetPrice fires/no-fire, dropPercent threshold fires/no-fire, idempotency (concurrent trigger is a no-op)

Manual testing:

  1. Sign in → navigate to an out-of-stock product → click "Notify me when back in stock" → subscription created
  2. Run PATCH /api/products/:id with { "stock": 10 } → backend console logs restock email ✅
  3. Sign in → navigate to an in-stock product → click "Price-drop alert" → set target $900 (current $999)
  4. Run PATCH /api/products/:id with { "price": 850 } → backend console logs price-drop email ✅
  5. Repeat step 4 → no second email (subscription is TRIGGERED, idempotent) ✅
  6. Wishlist add/remove → heart icon fills instantly (optimistic update), count badge updates in header ✅

To reproduce:

# Start both servers
cd backend && npm start
npm start

# Update stock to trigger restock alert
curl -X PATCH http://localhost:5000/api/products/<id> \
  -H "Content-Type: application/json" -d '{"stock": 10}'

# Update price to trigger price-drop alert
curl -X PATCH http://localhost:5000/api/products/<id> \
  -H "Content-Type: application/json" -d '{"price": 850}'
` ``

- [x] Unit tests
- [ ] Integration tests
- [x] Manual testing

---

## Checklist

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes

@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

@heet2312 is attempting to deploy a commit to the dav nguyen's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 24, 2026

Deploy Preview for mern-stack-ecommerce-website ready!

Name Link
🔨 Latest commit 524be11
🔍 Latest deploy log https://app.netlify.com/projects/mern-stack-ecommerce-website/deploys/6a1351b5e967590008f0bf83
😎 Deploy Preview https://deploy-preview-34--mern-stack-ecommerce-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 60
Accessibility: 91
Best Practices: 100
SEO: 100
PWA: 80
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive Wishlist and 'Notify Me' alert system, allowing users to save products and receive email notifications for restocks or price drops. Key additions include new Mongoose models, API endpoints for wishlist and alert management, and a SendGrid-powered email service. The frontend is updated with a dedicated wishlist page, a React context for state management, and interactive UI elements on product detail pages. Review feedback highlights opportunities to optimize the email service initialization, improve input validation for product updates, reduce unnecessary network traffic by removing wishlist polling, and ensure data consistency by fetching user emails dynamically during alert evaluation.

Comment thread backend/services/emailService.js
Comment thread backend/services/emailService.js Outdated
Comment thread backend/routes/products.js Outdated
Comment thread src/context/WishlistContext.jsx Outdated
Comment thread backend/services/evaluateSubscriptions.js Outdated
@heet2312
Copy link
Copy Markdown
Author

All 5 Gemini review suggestions addressed in commits 9ce8f1d and 524be11.

@hoangsonww hoangsonww added documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers question Further information is requested labels May 24, 2026
@hoangsonww hoangsonww added this to the v1.x.x - Stable Release milestone May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Feature: Wishlists + “Notify Me” (Restock & Price-Drop Alerts)

2 participants