Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Humera fix x hours in x weeks streak badges #1208

Open
wants to merge 12 commits into
base: development
Choose a base branch
from

Conversation

humera314
Copy link

@humera314 humera314 commented Jan 26, 2025

Description

This PR fixes the issue where users weren't receiving the correct streak badges. The system now tracks and awards badges for completing the correct number of hours over consecutive weeks.

Bug : Users were not receiving the streak badges correctly for meeting the hourly targets over multiple weeks.
Fix: Adjusted logic to award badges based on the consecutive streak of hours.


Related PRS (if any):

None


Main changes explained:

  • Updated checkXHrsForOneWeek function to correctly handle awarding badges for X hours in one week.
  • Modified checkXHrsForXWeeks function to handle streak badges by replacing lower streak badges with higher ones when applicable.
  • Updated awardNewBadges to allow targeting specific users during testing.

##How to test:

  1. Check out the current branch: humera_fix_x_hours_in_x_weeks_streak_badges.
  2. Run npm install and start the development server with npm run dev.
  3. Clear browser data/cache.
  4. Log in as any user.
  5. Navigate to HGNRest -> src -> helpers -> UserHelper.js.
  6. Find awardNewBadges at line 1966 and add the following line:
  7. const users = await userProfile.find({ email: 'your email ID' }).populate('badgeCollection.badge');
  8. To get the autentication token, using postman to make request POST http://localhost:4500/api/login, and include the
  9. following JSON in the request body(replace with your own email and password)
       {"email":"your-email",
         "password":"your-password"
       }
    

10.Using postman to make request GET http://localhost:4500/api/badge/awardBadgesTest, and include Authorization: your-token in the header.
11. In MongoDB Compass, go to userProfiles, find your email, and update the savedTangibleHrs to [30, 30, 30, 40, 40, 40].
12. Use Postman to send the request and verify if the badge is awarded based on the correct streak.
13. go to HGN account->view Profile->Feature Badges


##Test Cases:

  1. savedTangibleHrs = [30] → Award badge for 30 hours, 1-week streak.
  2. savedTangibleHrs = [30, 30] → Replace badge for 30 hours for 1 week streak with a 2-week streak.
  3. savedTangibleHrs = [30, 30, 30] → Replace badge for 30 hours, 2-week streak with a 3-week streak.
  4. savedTangibleHrs = [30, 30, 30, 40, 40, 40] → Award badge for 40-hours, 3-week streak.

##Screenshots or videos of changes:

video1550111681.mp4

image

@one-community one-community added the High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible label Jan 27, 2025
Copy link
Contributor

@skaush21 skaush21 left a comment

Choose a reason for hiding this comment

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

Tested the following using latest frontend PR and backend PR#1208.
[30]: 30 hours in 1 week
[30, 30] (30 hours in 2 weeks):
30 hours in 1 week drops off
30 hours in 2 weeks assigns and displays

[30,30,30] (30 hours in 3 weeks):
30 hours in 2 weeks drops off (frontend: featured badges)
30 hours in 3 weeks assigns and displays
note: A 2-week streak is not present in DB.

[30,30,30,30] (30 hours in 4 weeks):
30 hours in 3 weeks doesn’t drop off (frontend: featured badges)
30 hours in 4 weeks assigns and displays

[30,30,30, 30,30,30] (30 hours in 6 weeks):

  • 30 hours in 3 weeks doesn’t drop off (frontend: featured badges)
  • 30 hours in 4 weeks doesn’t drop off (frontend: featured badges)
  • 30 hours in 6 weeks assigns and displays

The above test was done for 40 hours as well, and achieved the same results.

Previous weeks should drop off if they are in a consecutive week. In this case, these are consecutive weeks. Please fix this.

Note: I edited cronjob to run per minute to test this. I also modified the following line in userHelper.js to test this.
const users = await userProfile.find({ email: '[email protected]' }).populate('badgeCollection.badge');
Please remove comments made for testing purposes, this should be removed before the merge.

Screen Shot 2025-01-27 at 7 35 08 PM Screen Shot 2025-01-27 at 7 35 27 PM

Note: I did not test the entire range of streaks.
Please re-test the following streaks for this issue:
for 30 and 40 hours:
streak 2 weeks in a row
streak 3 weeks in a row
streak 4 weeks in a row
streak 6 weeks in a row
streak 10 weeks
streak 15 weeks
streak 20 weeks
streak 40 weeks
streak 60 weeks
streak 80 weeks
streak 100 weeks
streak 150 weeks
streak 200 weeks

for 50 and 60 hours:
2 weeks in a row
3 weeks in a row
4 weeks in a row
6 weeks in a row

@Eveye2023
Copy link

Eveye2023 commented Jan 29, 2025

I think the instructions for Step 8 and Step 9 could be clearer to make them easier for someone new to the project to follow. Here’s a summary of what I followed:

  • step 8: To get the autentication token, using postman to make request POST http://localhost:4500/api/login, and include the following JSON in the request body(replace with your own email and password)
{"email":"your-email",
  "password":"your-password"
}

Below are my test cases, I'm a bit confused about why the 1-week streak is not being replaced:
[30] - Award 1-week streak badge for 30 hours.
[30,30] - Award 2-week streak badge for 30 hours. 1-week streak still there.
[30,30,30] - Replace 2-week streak badge for 30 hours with a 3-week streak. But 1-week streak still there
[30,30,30,40] - Award 1-week streak badge for 40 hours.
[30,30,30,40,40] - Award 2-week streak badge for 40 hours. 1-week streak still there.
[30,30,30,40,40,40] - Replace 2-week streak badge for 30 hours with a 3-week streak. But 1-week streak still there.

PR

Screenshot 2025-01-28 at 11 05 20 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants