-
-
Notifications
You must be signed in to change notification settings - Fork 140
test: add testing for isVotingWithinLastThreeMonths function #1837
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- sorry, please rename
testing
totest
to follow standard naming - I don't know why I suggestedtesting
initially 😄 - you forgot to add docs (first bullet point in requirements)
- provide jsdoc for
isVotingWithinLastThreeMonths
and put there an example ofvoteInfo
argument - I think that instead of
vote_tracker_utils.js
we should rather add there a new folder, as we already have some, like maintainers- .github - scripts - vote_tracker - index.js (previously `vote_tracker.js`) - utils.js
wdyt?
I thought of this: .github
└── scripts
├── vote_tracker
│ ├── index.js # Main vote tracking logic
├── vote_utils
│ ├── utils.js # Utility functions for vote tracking This way, the core logic and utilities are separate. What do you think? |
…d jsdoc for isVotingWithinLastThreeMonths
but it ain't a big project, so does it make sense to introduce such folder structure? especially that |
Yeah, fair point. I'll follow the other one and keep it simple. And by the way, I have added the jsdoc and the |
ping me whenever ready for another review round |
@Nandgopal-R any news from your side? |
""" WalkthroughThis update refactors the vote tracking script for TSC member voting on GitHub by moving the main logic from a single file to a new modular structure. The core vote tracking workflow is now in Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant GitHub Actions
participant VoteTracker (index.js)
participant Utils (utils.js)
participant Filesystem
User->>GitHub Actions: Trigger workflow (via comment or bot URL)
GitHub Actions->>VoteTracker: Invoke exported async function
VoteTracker->>GitHub Actions: Fetch comment/issue data
VoteTracker->>Filesystem: Read MAINTAINERS.yaml and voteTrackingFile.json
VoteTracker->>Utils: Call isVotingWithinLastThreeMonths
Utils-->>VoteTracker: Return recent voting status
VoteTracker->>Filesystem: Update voteTrackingFile.json
VoteTracker->>Filesystem: Write TSC_VOTING_OVERVIEW.md
VoteTracker-->>GitHub Actions: Finish workflow
Possibly related issues
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@derberg I have made the changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (4)
.github/scripts/vote_tracker/utils.js (1)
45-60
: Good implementation with proper edge case handling.The function correctly:
- Handles cases where a member has no voting history
- Rejects future dates as invalid
- Calculates the difference in days accurately
One minor suggestion would be to extract the "90 days" as a named constant at the top of the file for better maintainability.
+ // Number of days considered as "within 3 months" + const DAYS_IN_THREE_MONTHS = 90; function isVotingWithinLastThreeMonths(voteInfo) { // ...existing code... const diffInDays = (currentDate - lastVoteDate) / (1000 * 60 * 60 * 24); - return diffInDays <= 90; // 90 days = 3 months + return diffInDays <= DAYS_IN_THREE_MONTHS; }package.json (1)
1-8
: Basic package.json setup for testing.The package.json file correctly sets up Jest for testing but is missing standard metadata fields. Consider adding name, version, description, and other relevant fields to make the package.json more complete and informative.
{ + "name": "asyncapi-community", + "version": "1.0.0", + "description": "AsyncAPI Community repository", + "private": true, "scripts": { "test": "jest" }, "devDependencies": { "jest": "^29.0.0" } }.github/scripts/vote_tracker/index.js (2)
63-72
: Avoid double lookup of the same vote row
userVote
anduserInfo
are computed with identicalfind
calls. This duplicates work and complicates reasoning. Re-use the first lookup result:-const userVote = latestVotes.find(...); +const userVote = latestVotes.find( + (vote) => vote.user.toLowerCase() === voteInfo.name.toLowerCase() +); /* …later… */ -const userInfo = latestVotes.find( - (vote) => vote.user.toLowerCase() === voteInfo.name.toLowerCase() -); - -const voteChoice = userInfo ? userInfo.vote : "Not participated"; +const voteChoice = userVote ? userVote.vote : "Not participated";
259-261
: PreferObject.hasOwn
overhasOwnProperty
Using
hasOwnProperty
directly on potentially user-supplied objects can be hijacked.
Object.hasOwn()
is the modern, prototype-safe alternative.- return requiredKeys.every((key) => member.hasOwnProperty(key)); + return requiredKeys.every((key) => Object.hasOwn(member, key));🧰 Tools
🪛 Biome (1.9.4)
[error] 260-260: Do not access Object.prototype method 'hasOwnProperty' from target object.
It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.(lint/suspicious/noPrototypeBuiltins)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (6)
.github/scripts/vote_tracker.js
(0 hunks).github/scripts/vote_tracker/index.js
(1 hunks).github/scripts/vote_tracker/utils.js
(1 hunks)README.md
(1 hunks)package.json
(1 hunks)test/vote_tracker.test.js
(1 hunks)
💤 Files with no reviewable changes (1)
- .github/scripts/vote_tracker.js
🧰 Additional context used
🪛 Biome (1.9.4)
.github/scripts/vote_tracker/index.js
[error] 74-74: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 260-260: Do not access Object.prototype method 'hasOwnProperty' from target object.
It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.
(lint/suspicious/noPrototypeBuiltins)
🔇 Additional comments (5)
.github/scripts/vote_tracker/utils.js (1)
1-43
: Well-documented function with thorough JSDoc comments!The JSDoc comments are comprehensive, providing clear descriptions of parameters, return values, and good usage examples. This will help other developers understand how to use this function correctly.
README.md (1)
134-161
: Clear development documentation added.The new Development section provides clear and helpful instructions for running and creating tests. This will help contributors understand how to properly test their changes, which is essential for maintaining code quality.
test/vote_tracker.test.js (1)
3-91
: Well-structured tests covering important edge cases.The test suite is comprehensive and covers several important edge cases:
- Users who haven't voted recently (>90 days)
- Users who have never voted
- Invalid future dates
- New users who just voted
- Inactive members
This thorough testing will help ensure the utility function works correctly in all scenarios.
.github/scripts/vote_tracker/index.js (2)
154-158
: Property name mismatch breaks column tooltipThe titles map defines
hasVotedInLast3Months
, but objects useisVotedInLast3Months
.
As a result the generated markdown shows the raw key instead of the descriptive tooltip.- hasVotedInLast3Months: "Flag indicating if TSC member voted in last 3 months …", + isVotedInLast3Months: "Flag indicating if TSC member voted in last 3 months …",Ensure all writes/readers use the same property name (prefer
hasVotedInLast3Months
for readability, or rename everywhere).
After renaming, remember to adjust tests that may assert on this field.
94-103
:⚠️ Potential issue
isVotingWithinLastThreeMonths
is evaluated before the record is populated
lastParticipatedVoteTime
is added afterisVotingWithinLastThreeMonths(voteInfo)
is called, so the utility receives stale/empty data and will always returnfalse
.
Populate the field first, then call the helper.- voteInfo.isVotedInLast3Months = isVotingWithinLastThreeMonths(voteInfo); - voteInfo.lastParticipatedVoteTime = currentTime; +voteInfo.lastParticipatedVoteTime = currentTime; +voteInfo.isVotedInLast3Months = isVotingWithinLastThreeMonths(voteInfo);Likely an incorrect or invalid review comment.
@derberg can you please review this |
README.md
Outdated
### Adding New Tests | ||
If you are contributing new automation scripts, ensure they are covered by tests. To add a new test: | ||
|
||
1. Create or update the relevant test file in the `testing/` directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always remember to update docs 😛
abstainCount: 2, | ||
notParticipatingCount: 0 | ||
}, | ||
false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is giving true
instead of expecting false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it;s because you're checking agains the current date, which yeah, now is may, not before april
you need to somehow mock current date and set it as older, before april
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few minor comments left, but the overal it is a great quality PR and will help a lot long term
just to clarify, the code in index.js
was not changed comparing to the original except for taking one function outside?
@Nandgopal-R hey man, did you have a chance to look into my review? |
Yes, I did. I'm almost finished—just tidying up the README, after which I'll commit. |
@derberg Yes, that's correct. The only modification to index.js was extracting one function. |
@derberg, I have made the corrections. |
/rtm |
Desciption
Tests Introduced
isVotingWithinLastThreeMonths
.Fixes
isVotingWithinLastThreeMonths
to correctly handle future dates given inlastVoteDate
.How to test
npm test
to execute all test cases.This PR is related to issue #1786
Summary by CodeRabbit
New Features
Documentation
Tests
Chores