Skip to content

chore: moved setup.ts to src/setup and written tests for it #3568

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

Merged

Conversation

abbi4code
Copy link
Contributor

@abbi4code abbi4code commented Feb 9, 2025

What kind of change does this PR introduce?

  • Move setup.ts to src/setup & written tests for src/setup/setup.ts

Issue Number:

Fixes #3521

Snapshots/Videos:
Screenshot from 2025-02-09 06-01-50

Summary by CodeRabbit

  • Documentation
    • Added detailed documentation for the askAndSetRecaptcha and main functions.
  • Chores
    • Updated the setup command configuration for improved operation.
  • Tests
    • Introduced a comprehensive test suite to ensure a more reliable and robust setup process.
  • Refactor
    • Streamlined internal module imports to enhance overall maintainability of the setup functionality.
  • New Features
    • Made the askAndSetRecaptcha function accessible for use in other modules.

Copy link
Contributor

coderabbitai bot commented Feb 9, 2025

Walkthrough

This pull request introduces new documentation entries for the askAndSetRecaptcha() and main() functions, updates the setup script path in the package.json, and modifies import statements and the export declaration for askAndSetRecaptcha in src/setup/setup.ts. Additionally, a new Vitest test suite for the Talawa Admin Setup process is added, covering environment file checks, Docker configuration, reCAPTCHA handling, error logging, and related file system operations.

Changes

File(s) Change Summary
docs/.../askAndSetRecaptcha.md, docs/.../main.md Added documentation for the asynchronous functions askAndSetRecaptcha(): Promise<void> and main(): Promise<void>, including links to their source code.
package.json Updated the setup script path from "tsx setup.ts" to "tsx src/setup/setup.ts".
src/setup/setup.spec.ts Introduced a new Vitest test suite for Talawa Admin Setup, covering environment file checks, Docker configuration, reCAPTCHA interactions, error handling, and file system operations.
src/setup/setup.ts Simplified import paths and changed askAndSetRecaptcha to an exported asynchronous function.

Possibly related PRs

  • Docker setup in Setup Script #3187: The changes in the main PR, specifically the documentation for the askAndSetRecaptcha function, are directly related to the modifications in the retrieved PR, which includes a restructuring of the reCAPTCHA setup process that involves the same function.
  • Upgrade package inquirer from 11.1.0 to 12.3 #3549: The changes in the main PR are related to the modifications in the askAndSetRecaptcha function found in the retrieved PR, as both involve updates to the function's structure and usage of the inquirer.prompt method.

Suggested reviewers

  • palisadoes

Poem

I'm a rabbit with a hopping beat,
Skipping through docs so crisp and neat.
Tests and exports join in a joyful race,
Code and setup now in a brighter place.
With a twitch of whiskers and a hop so free,
I cheer the change – happy as can be! 🐰


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 602d822 and cfd984d.

📒 Files selected for processing (1)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Test Application
  • GitHub Check: Check Python Code Style
  • GitHub Check: Analyse Code With CodeQL (javascript)

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 your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Feb 9, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

codecov bot commented Feb 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.92%. Comparing base (2133293) to head (e62de43).
Report is 1 commits behind head on develop-postgres.

Additional details and impacted files
@@                 Coverage Diff                  @@
##           develop-postgres    #3568      +/-   ##
====================================================
+ Coverage             85.57%   85.92%   +0.35%     
====================================================
  Files                   358      358              
  Lines                  8968     8968              
  Branches               1932     1932              
====================================================
+ Hits                   7674     7706      +32     
+ Misses                  935      903      -32     
  Partials                359      359              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@palisadoes
Copy link
Contributor

Please fix the failing tests and make coderabbit.ai approve your work

@abbi4code
Copy link
Contributor Author

abbi4code commented Feb 13, 2025

Screenshot from 2025-02-13 15-26-16

finally got 100% test code coverage

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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/setup/setup.ts (1)

12-44: Consider adding input validation for the reCAPTCHA site key format.

While the function correctly validates the reCAPTCHA key using validateRecaptcha, consider adding a basic format check before making the validation call to provide faster feedback to users.

 validate: (input: string): boolean | string => {
+  if (!input || input.trim().length < 20) {
+    return 'reCAPTCHA site key must be at least 20 characters long';
+  }
   return (
     validateRecaptcha(input) ||
     'Invalid reCAPTCHA site key. Please try again.'
   );
 },
src/setup/setup.spec.ts (1)

48-95: Consider adding edge cases to the test suite.

While the basic test cases are well covered, consider adding tests for:

  • Invalid environment file content
  • Empty or malformed Docker configuration
  • Network timeouts during reCAPTCHA validation
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ae12ab and b7cb2b0.

📒 Files selected for processing (5)
  • docs/docs/auto-docs/setup/setup/functions/askAndSetRecaptcha.md (1 hunks)
  • docs/docs/auto-docs/setup/setup/functions/main.md (1 hunks)
  • package.json (1 hunks)
  • src/setup/setup.spec.ts (1 hunks)
  • src/setup/setup.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • docs/docs/auto-docs/setup/setup/functions/main.md
  • docs/docs/auto-docs/setup/setup/functions/askAndSetRecaptcha.md
🧰 Additional context used
🪛 GitHub Actions: PR Workflow
package.json

[error] 1-1: Unauthorized change/delete attempt on package.json.

🔇 Additional comments (4)
src/setup/setup.ts (2)

4-9: LGTM! Clean import path updates.

The import paths have been correctly updated to use relative paths, which is more maintainable after moving the file to src/setup.


62-92: LGTM! Well-structured main function with proper error handling.

The main function is well-organized with:

  • Proper environment file checks
  • Clear user feedback
  • Conditional Docker-based setup
  • Comprehensive error handling
src/setup/setup.spec.ts (2)

24-46: LGTM! Well-structured test setup with proper cleanup.

The test setup is thorough with:

  • Clear mock initialization
  • Proper spy setup for process.exit and console.error
  • Clean afterEach cleanup

165-179: LGTM! Comprehensive error handling test.

The error handling test properly verifies:

  • Error message formatting
  • Console error logging
  • Prevention of environment file updates

@abbi4code
Copy link
Contributor Author

Screenshot from 2025-02-13 15-43-26

i didnt got any issue here @palisadoes

@palisadoes palisadoes added the ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files label Feb 14, 2025
@palisadoes
Copy link
Contributor

  1. Merge with the latest upstream the failing file in the docs/ directory was recently updated.
  2. If that doesn't work, we may need to update the prettier configuration. It was working before, so that may not be the root cause.

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

Please fix the failing test

@JaiPannu-IITI
Copy link

JaiPannu-IITI commented Feb 15, 2025

@abbi4code Your changes haven't affected vitest, pull this PR into your code, it will be fixed.

#3601

@abbi4code
Copy link
Contributor Author

abbi4code commented Feb 15, 2025

Please fix the failing test

Yes sir! All tests are passing now

@abbi4code abbi4code requested a review from palisadoes February 15, 2025 07:09
@palisadoes palisadoes merged commit 68a69ed into PalisadoesFoundation:develop-postgres Feb 15, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants