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

chore: add tests #9

Merged
merged 3 commits into from
Dec 11, 2023
Merged

chore: add tests #9

merged 3 commits into from
Dec 11, 2023

Conversation

gitcommitshow
Copy link
Owner

@gitcommitshow gitcommitshow commented Dec 11, 2023

add tests using mocha and chai

Summary by CodeRabbit

  • New Features

    • Introduced new functionality to fetch all contributors and repository-specific contributors.
    • Enhanced the leaderboard file generation with customizable options for file paths.
  • Refactor

    • Updated functions to improve flexibility and code maintainability.
  • Tests

    • Temporarily disabled two test cases related to fetching contributors.
    • Added new test cases for archiving GitHub repository contributors.
  • Documentation

    • No explicit documentation changes mentioned for end-users.

Copy link
Contributor

coderabbitai bot commented Dec 11, 2023

Walkthrough

The codebase has been updated to enhance the functionality related to contributors. New export functions for fetching all contributors and repository-specific contributors have been added. The writeContributorLeaderboardToFile function has been modified to accept options for file path determination. Additionally, test coverage has been adjusted by skipping certain tests, and new test cases have been added for archiving GitHub contributors.

Changes

File Path Change Summary
contributors.js Added exports for getAllContributors, getRepoContributors; modified functions.
test/.../contributors.test.js Skipped execution of tests for fetching contributors.
test/fixtures/contributors.fixture.js Added exports for repository and contributor details.
test/index.test.js Added test cases for archiving GitHub contributors.

Poem

🐇 "In the burrow of the code, changes abound,
🌟 New paths to traverse, where contributors are found.
📜 Tests are asleep, while new checks arise,
🎉 A hop, skip, and a jump, for the archive's new guise."

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4ae95c9 and d12d2aa.
Files ignored due to filter (2)
  • package-lock.json
  • package.json
Files selected for processing (4)
  • contributors.js (3 hunks)
  • test/contributors.test.js (1 hunks)
  • test/fixtures/contributors.fixture.js (1 hunks)
  • test/index.test.js (1 hunks)
Additional comments: 5
contributors.js (2)
  • 6-11: The addition of new exports getAllContributors and getRepoContributors and the import of the path module are consistent with the PR's objective to enhance the codebase's functionality. Ensure that the new functions are covered by tests since this PR is focused on adding tests.

  • 79-82: The update to the JSDoc comment for getRepoContributors to include the pageNo parameter is good for documentation clarity. Verify that the implementation of pagination is correct and that the pageNo parameter is being used as intended in the function.

test/contributors.test.js (2)
  • 10-19: The test case for getRepoContributors is skipped. Ensure there is a tracking mechanism (like a TODO or an issue) to enable this test once the related code is stable or the blocking issue is resolved.

  • 21-30: Similarly, the test case for getAllContributors is also skipped. It's important to document the reason for skipping and have a plan for when these tests will be revisited.

test/fixtures/contributors.fixture.js (1)
  • 1-70: The new test fixture data looks well-structured and appropriate for testing purposes. However, please confirm that the data, especially URLs and node IDs, does not contain sensitive information. Additionally, consider if the repo field in the VALID_CONTRIBUTOR_SAMPLE object is necessary given the more detailed repos array. Lastly, evaluate if the allContributedRepos field would be more useful as an array or object rather than a concatenated string.


describe.skip('#getRepoContributors('+contributorsFixture.VALID_REPO+');', async function() {
it('should return the repo contribuors', async function() {
this.timeout(100000);
Copy link
Contributor

Choose a reason for hiding this comment

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

The timeout for these tests is set to 100000 milliseconds, which is quite long. If these tests are making real HTTP requests, consider using mocks or stubs to simulate API responses for faster and more reliable tests.

Also applies to: 23-23

let contributorsHandlesString = await OCK.contributors.github.archive(contributorsFixture.VALID_REPO_OWNER);
assert.isNotNull(contributorsHandlesString);
expect(contributorsHandlesString).to.be.not.empty;
expect(str).to.include('@');
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 11, 2023

Choose a reason for hiding this comment

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

The variable str is not defined in this scope. It seems like it should be contributorsHandlesString.

- expect(str).to.include('@');
+ expect(contributorsHandlesString).to.include('@');

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
expect(str).to.include('@');
expect(contributorsHandlesString).to.include('@');

Copy link
Owner Author

Choose a reason for hiding this comment

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

good bot

Copy link
Contributor

Choose a reason for hiding this comment

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

@gitcommitshow, thank you for the feedback! I'm glad the suggestion was helpful. If there's anything else I can assist with, just let me know! 🐰


If you found the review helpful, we would love if you give us a shout-out on X (twitter).

contributors.js Outdated
Comment on lines 200 to 216
* @param {Array} contributors List of contributors details with their contributions metrics
* @param {Object} options
* @param {string} options.archiveFolder where to save the final content
* @param {string} options.archiveFileName the name of the archive file, the content will be overwritten if it exists already
*/
function writeContributorLeaderboardToFile(contributors) {
function writeContributorLeaderboardToFile(contributors, options={}) {
if(!contributors || contributors.length<1){
return;
}
const ARCHIVE_FOLDER = options.archiveFolder || process.cwd();
const ARCHIVE_FULL_PATH = path.join(ARCHIVE_FOLDER, options.archiveFileName || 'archive-gh-contributors-leaderboard.csv');
const fs = require('fs');
let ghContributorLeaderboard = contributors.map((contributor) => {
return ["@" + contributor.login, contributor.contributions, contributor.html_url, contributor.avatar_url, contributor.topContributedRepo, contributor.allContributedRepos].join();
}).join("\n");
ghContributorLeaderboard = "Github Username,Total Contributions,Profile,Avatar,Most Contribution To,Contributed To\n" + ghContributorLeaderboard;
fs.writeFile("./gh-contributors-leaderboard.csv", ghContributorLeaderboard, { flag: 'a+' }, function (err) {
fs.writeFile(ARCHIVE_FULL_PATH, ghContributorLeaderboard, { flag: 'a+' }, function (err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The modification of writeContributorLeaderboardToFile to accept an options object is a good practice for function extensibility. However, the fs.writeFile method is being used with the { flag: 'a+' } option, which appends to the file if it exists or creates a new file if it does not. This could lead to unexpected behavior if the file already exists, as it would append the new content to the old content. Consider if overwriting the file is the desired behavior and use { flag: 'w' } if so.

- fs.writeFile(ARCHIVE_FULL_PATH, ghContributorLeaderboard, { flag: 'a+' }, function (err) {
+ fs.writeFile(ARCHIVE_FULL_PATH, ghContributorLeaderboard, { flag: 'w' }, function (err) {

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* @param {Array} contributors List of contributors details with their contributions metrics
* @param {Object} options
* @param {string} options.archiveFolder where to save the final content
* @param {string} options.archiveFileName the name of the archive file, the content will be overwritten if it exists already
*/
function writeContributorLeaderboardToFile(contributors) {
function writeContributorLeaderboardToFile(contributors, options={}) {
if(!contributors || contributors.length<1){
return;
}
const ARCHIVE_FOLDER = options.archiveFolder || process.cwd();
const ARCHIVE_FULL_PATH = path.join(ARCHIVE_FOLDER, options.archiveFileName || 'archive-gh-contributors-leaderboard.csv');
const fs = require('fs');
let ghContributorLeaderboard = contributors.map((contributor) => {
return ["@" + contributor.login, contributor.contributions, contributor.html_url, contributor.avatar_url, contributor.topContributedRepo, contributor.allContributedRepos].join();
}).join("\n");
ghContributorLeaderboard = "Github Username,Total Contributions,Profile,Avatar,Most Contribution To,Contributed To\n" + ghContributorLeaderboard;
fs.writeFile("./gh-contributors-leaderboard.csv", ghContributorLeaderboard, { flag: 'a+' }, function (err) {
fs.writeFile(ARCHIVE_FULL_PATH, ghContributorLeaderboard, { flag: 'a+' }, function (err) {
fs.writeFile(ARCHIVE_FULL_PATH, ghContributorLeaderboard, { flag: 'w' }, function (err) {

assert.isNotNull(contributorsHandlesString);
expect(contributorsHandlesString).to.be.not.empty;
expect(str).to.include('@');
// expect(str).to.include(',');
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a commented-out assertion. If it's not needed, it should be removed; otherwise, add a comment explaining why it's commented out.

contributors.js Outdated
Comment on lines 198 to 219
/**
* Writes all contributors data to a file
* @param {Array} contributors
* @param {Array} contributors List of contributors details with their contributions metrics
* @param {Object} options
* @param {string} options.archiveFolder where to save the final content
* @param {string} options.archiveFileName the name of the archive file, the content will be overwritten if it exists already
*/
function writeContributorLeaderboardToFile(contributors) {
function writeContributorLeaderboardToFile(contributors, options={}) {
if(!contributors || contributors.length<1){
return;
}
const ARCHIVE_FOLDER = options.archiveFolder || process.cwd();
const ARCHIVE_FULL_PATH = path.join(ARCHIVE_FOLDER, options.archiveFileName || 'archive-gh-contributors-leaderboard.csv');
const fs = require('fs');
let ghContributorLeaderboard = contributors.map((contributor) => {
return ["@" + contributor.login, contributor.contributions, contributor.html_url, contributor.avatar_url, contributor.topContributedRepo, contributor.allContributedRepos].join();
}).join("\n");
ghContributorLeaderboard = "Github Username,Total Contributions,Profile,Avatar,Most Contribution To,Contributed To\n" + ghContributorLeaderboard;
fs.writeFile("./gh-contributors-leaderboard.csv", ghContributorLeaderboard, { flag: 'a+' }, function (err) {
fs.writeFile(ARCHIVE_FULL_PATH, ghContributorLeaderboard, { flag: 'a+' }, function (err) {
if (err) {
return console.log(err);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The archiveContributorsLeaderboard function calls writeContributorLeaderboardToFile without passing the options object. This could lead to the function not using the intended archive path and file name. Ensure that the options object is passed correctly to writeContributorLeaderboardToFile to reflect the changes made to the function signature.

- writeContributorLeaderboardToFile(contributors);
+ writeContributorLeaderboardToFile(contributors, options);

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
/**
* Writes all contributors data to a file
* @param {Array} contributors
* @param {Array} contributors List of contributors details with their contributions metrics
* @param {Object} options
* @param {string} options.archiveFolder where to save the final content
* @param {string} options.archiveFileName the name of the archive file, the content will be overwritten if it exists already
*/
function writeContributorLeaderboardToFile(contributors) {
function writeContributorLeaderboardToFile(contributors, options={}) {
if(!contributors || contributors.length<1){
return;
}
const ARCHIVE_FOLDER = options.archiveFolder || process.cwd();
const ARCHIVE_FULL_PATH = path.join(ARCHIVE_FOLDER, options.archiveFileName || 'archive-gh-contributors-leaderboard.csv');
const fs = require('fs');
let ghContributorLeaderboard = contributors.map((contributor) => {
return ["@" + contributor.login, contributor.contributions, contributor.html_url, contributor.avatar_url, contributor.topContributedRepo, contributor.allContributedRepos].join();
}).join("\n");
ghContributorLeaderboard = "Github Username,Total Contributions,Profile,Avatar,Most Contribution To,Contributed To\n" + ghContributorLeaderboard;
fs.writeFile("./gh-contributors-leaderboard.csv", ghContributorLeaderboard, { flag: 'a+' }, function (err) {
fs.writeFile(ARCHIVE_FULL_PATH, ghContributorLeaderboard, { flag: 'a+' }, function (err) {
if (err) {
return console.log(err);
}
// No changes required in the provided code snippet

@gitcommitshow gitcommitshow merged commit 713ef19 into main Dec 11, 2023
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.

1 participant