fix: test expectations for idle user #2576
Conversation
Summary by CodeRabbitRelease Notes
No user-facing features or bug fixes in this release. WalkthroughThis PR introduces a locally scoped Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
models/discordactions.js (1)
40-40:⚠️ Potential issue | 🟠 Major
updateIdle7dUsersOnDiscordstill accumulates state into the module-levelallMavens— same bug that was fixed forupdateIdleUsersOnDiscordThe local
const allMavens = [];at line 407 correctly isolatesupdateIdleUsersOnDiscord. However,updateIdle7dUsersOnDiscordstill pushes to and reads from the module-level array (lines 674 and 697). Each invocation permanently appends Maven Discord IDs to this global, causing users who were once Mavens to be incorrectly excluded from the idle list in every subsequent call — even after they lose the Maven role. The array also grows without bound across cron/scheduler runs.The fix should mirror line 407: add
const allMavens = [];at the top ofupdateIdle7dUsersOnDiscordand remove the now-dead module-level declaration at line 40.🔧 Proposed fix
-const allMavens = []; - /** * * `@param` roleData { Object }: Data of the new roleconst updateIdle7dUsersOnDiscord = async (dev) => { let totalIdle7dUsers = 0; ... let groupIdle7dRoleId; + const allMavens = []; try {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@models/discordactions.js` at line 40, The module-level array allMavens is being mutated by updateIdle7dUsersOnDiscord which causes state to leak across invocations; mirror the fix used for updateIdleUsersOnDiscord by removing the module-level declaration of allMavens and instead declare a local const allMavens = [] at the start of the updateIdle7dUsersOnDiscord function, then update the function to push/read from that local array only so the list is cleared each run and no global growth occurs.test/unit/models/discordactions.test.js (1)
991-991:⚠️ Potential issue | 🟡 MinorStale test description — still says "as 3" but the assertions check for 2.
The description reads
"should return totalIdleUsers as 3,totalRolesApplied as 3, totalRoleToBeAdded as 3 as no one is maven", but the actual expectations asserttotalIdle7dUsers === 2andtotalUserRoleToBeAdded === 2. This should be updated to match.✏️ Proposed fix
- it("should return totalIdleUsers as 3,totalRolesApplied as 3, totalRoleToBeAdded as 3 as no one is maven", async function () { + it("should return totalIdle7dUsers as 2, totalUserRoleToBeAdded as 2, totalUserRoleToBeRemoved as 1, totalArchivedUsers as 1", async function () {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/unit/models/discordactions.test.js` at line 991, Update the stale test description in the it block whose title starts with "should return totalIdleUsers as 3,totalRolesApplied as 3, totalRoleToBeAdded as 3 as no one is maven" to reflect the actual expected values (2) used in the assertions; change the string to mention totalIdleUsers/totalIdle7dUsers and totalUserRoleToBeAdded (and totalRolesApplied if relevant) as 2 so the description matches the assertions referencing totalIdle7dUsers and totalUserRoleToBeAdded in the discordactions.test.js test case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@models/discordactions.js`:
- Line 40: The module-level array allMavens is being mutated by
updateIdle7dUsersOnDiscord which causes state to leak across invocations; mirror
the fix used for updateIdleUsersOnDiscord by removing the module-level
declaration of allMavens and instead declare a local const allMavens = [] at the
start of the updateIdle7dUsersOnDiscord function, then update the function to
push/read from that local array only so the list is cleared each run and no
global growth occurs.
In `@test/unit/models/discordactions.test.js`:
- Line 991: Update the stale test description in the it block whose title starts
with "should return totalIdleUsers as 3,totalRolesApplied as 3,
totalRoleToBeAdded as 3 as no one is maven" to reflect the actual expected
values (2) used in the assertions; change the string to mention
totalIdleUsers/totalIdle7dUsers and totalUserRoleToBeAdded (and
totalRolesApplied if relevant) as 2 so the description matches the assertions
referencing totalIdle7dUsers and totalUserRoleToBeAdded in the
discordactions.test.js test case.
* Merge pull request #2576 from RealDevSquad/2569-refactor-test-for-group-idle fix: test expectations for idle user * feat: enhance application scoring and update validation (#2573) * feat: enhance application scoring and update validation - Added score handling in nudgeApplication logic to increment score on nudging. - Updated application creation to set an initial score of 50. - Enhanced application update validation to include optional fields: firstName, lastName, college, skills, city, state, country, and role. - Improved integration tests to verify score updates and application modifications. - Adjusted unit tests to reflect changes in application scoring logic. * feat: introduce application scoring system and update application queries * test: refactor application update test for invalid role handling * refactor: remove firstName and lastName from application update validation and tests * refactor: rename 'college' to 'institution' in application validation, service, and tests * feat: implement user picture upload handling for application type (#2564) --------- Co-authored-by: Vinit khandal <vinit224488@gmail.com>
Date: 18-02-2025
Developer Name: @vinit717
Issue Ticket Number
Description
Fix the test expectations for the idle user and define mavens to an empty array
Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Test Coverage
Screenshot 1
Additional Notes