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

feat: replace apisauce with wretch #201

Merged

Conversation

naeemdadi1
Copy link
Contributor

@naeemdadi1 naeemdadi1 commented Jul 16, 2024

Ticket Link


Related Links


Description

  1. Replaced Apisauce(axios) with Wretch
  2. Added support for wretch in tests

Reason to migrate from apisauce to wretch

Reduce bundle size

With apisauce

Screenshot 2024-07-16 at 4 02 37 PM

With Wretch

Screenshot 2024-07-16 at 4 04 06 PM

Steps to Reproduce / Test



Checklist

  • PR description included
  • yarn test passes
  • Tests are [changed or added]
  • Relevant documentation is changed or added (and PR referenced)

GIF's


Live Link


Summary by CodeRabbit

  • New Features

    • Switched from Api Sauce to Wretch for API calls, enhancing network request handling.
  • Bug Fixes

    • Updated string interpolation in API URL construction to use backticks for consistency.
  • Tests

    • Replaced Axios mock with fetch mock in API call tests for more accurate simulation of API responses.
  • Chores

    • Updated dependencies: removed apisauce and axios-mock-adapter, added wretch and jest-fetch-mock.
    • Enabled jest-fetch-mock for testing purposes.

Copy link
Contributor

coderabbitai bot commented Jul 16, 2024

Walkthrough

The changes replace Api Sauce with Wretch for handling API calls throughout the project. This update impacts the network request functionalities, including the transformation of requests and responses, and error handling mechanisms. Adjustments were made to the test setup to align with the new library, and corresponding dependencies were updated in the package.json file.

Changes

Files Change Summary
README.md Updated references from Api Sauce to Wretch for API calls.
app/services/repoApi.js Modified the getRepos function to use backticks for URL construction.
app/services/tests/repoApi.test.js Replaced Axios mock with a fetch mock for API response simulation.
app/utils/apiUtils.js Refactored to use Wretch instead of Api Sauce for API client creation, including middleware for request and response transformations and error handling.
jest.setup.js Added import and initialization for jest-fetch-mock.
package.json Removed apisauce and axios-mock-adapter, added wretch and jest-fetch-mock dependencies.

Poem

In code’s quiet hum, a change so deft, 🐇
From Api Sauce, Wretch's embrace we’ve left,
Requests now whisper, responses sing,
With Wretch's magic, new joy it brings,
Testing anew with a fetch mock's touch,
Our code evolves, we’ve gained so much. 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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
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: 0

Outside diff range, codebase verification and nitpick comments (1)
app/utils/apiUtils.js (1)

59-90: Add tests for createApiClientWithTransForm to ensure middleware functionality.

The current implementation lacks direct tests for the createApiClientWithTransForm function and its middleware. To ensure data integrity and correct transformations, please add tests that validate:

  • Transformation of request bodies to snake_case.

  • Transformation of response data to camelCase.

  • Error handling in the response resolver.

Analysis chain

Verify middleware functionality in createApiClientWithTransForm.

The middleware for transforming request options and handling responses appears comprehensive. Ensure that these transformations are tested thoroughly to prevent data integrity issues.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the middleware functionality in `createApiClientWithTransForm`.

# Test: Search for the `createApiClientWithTransForm` function implementation. Expect: Correct handling of data transformations and error management.
ast-grep --lang javascript --pattern $'export const createApiClientWithTransForm = ($_) => {
  $$$
}'

Length of output: 2088


Script:

#!/bin/bash
# Search for the usage of `createApiClientWithTransForm`
rg 'createApiClientWithTransForm'

# Search for tests related to `createApiClientWithTransForm` or the transformations
rg 'createApiClientWithTransForm' --glob '*test*.js'
rg 'mapKeysDeep' --glob '*test*.js'

Length of output: 816


Script:

#!/bin/bash
# Check if `app/utils/apiUtils.js` is imported and used in other test files
rg 'apiUtils' --glob '*test*.js'

Length of output: 32

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0598030 and 6e93de1.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (6)
  • README.md (1 hunks)
  • app/services/repoApi.js (1 hunks)
  • app/services/tests/repoApi.test.js (1 hunks)
  • app/utils/apiUtils.js (2 hunks)
  • jest.setup.js (1 hunks)
  • package.json (4 hunks)
Additional comments not posted (5)
app/services/repoApi.js (1)

4-4: Verify the URL construction in getRepos.

Ensure that the base URL from the API client correctly concatenates with the endpoint. This is crucial as the migration from Apisauce to Wretch might affect how URLs are handled.

Verification successful

The URL construction in getRepos is verified and correct.

  • The repoApi is initialized using generateApiClient('github'), which sets the base URL from process.env.GITHUB_URL.
  • The createApiClientWithTransForm function correctly handles the base URL and concatenates it with the endpoint.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the base URL concatenation in the `generateApiClient` function.

# Test: Search for the `generateApiClient` function implementation. Expect: Proper handling of URL concatenation.
ast-grep --lang javascript --pattern $'export const generateApiClient = ($_) => {
  $$$
}'

Length of output: 922


Script:

#!/bin/bash
# Description: Check the URL concatenation in the `createApiClientWithTransForm` function.

# Test: Search for the `createApiClientWithTransForm` function implementation. Expect: Proper handling of URL concatenation.
ast-grep --lang javascript --pattern $'const createApiClientWithTransForm = ($_) => {
  $$$
}'

Length of output: 2081


Script:

#!/bin/bash
# Description: Check the usage of `repoApi` in the `getRepos` function to confirm correct URL concatenation.

# Test: Search for the `repoApi` usage in the `getRepos` function. Expect: Proper handling of URL concatenation.
rg 'repoApi\.get' -A 5

Length of output: 136


Script:

#!/bin/bash
# Description: Check the initialization of `repoApi` to ensure it uses the `createApiClientWithTransForm` function with the correct base URL.

# Test: Search for the `repoApi` initialization. Expect: Proper usage of `createApiClientWithTransForm`.
rg 'const repoApi' -A 5

Length of output: 231

app/services/tests/repoApi.test.js (1)

16-17: Verify the API response structure in tests.

Ensure that the test accurately reflects the expected structure and status codes of the API response. This is crucial for maintaining the integrity of the tests after the library migration.

Verification successful

The API response structure in the tests is correctly verified.

The test accurately reflects the expected structure and status codes of the API response. The mocked response includes totalCount and items, and the status code is set to 200, which is appropriate for a successful response.

  • The test setup using fetch.mockResponseOnce is correct.
  • The structure of the mocked data matches typical API response structures.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the API response structure in tests.

# Test: Search for the `getRepos` function implementation to confirm the response structure. Expect: Correct handling of JSON response and status codes.
ast-grep --lang javascript --pattern $'export const getRepos = ($_) => {
  $$$
}'

Length of output: 82


Script:

#!/bin/bash
# Description: List all functions in the repoApi.test.js file to understand the context.

# Step 1: List all functions in the repoApi.test.js file
ast-grep --lang javascript --pattern 'function $_($_) { $$$ }' $(fd repoApi.test.js)

# Step 2: Search for functions related to fetching repositories
ast-grep --lang javascript --pattern 'const $_ = async () => { $$$ }' $(fd repoApi.test.js)

Length of output: 250


Script:

#!/bin/bash
# Description: Search for fetch.mockResponseOnce in repoApi.test.js and include surrounding lines for context.

# Step 1: Search for fetch.mockResponseOnce in repoApi.test.js
rg 'fetch.mockResponseOnce' -A 5 -B 5 $(fd repoApi.test.js)

Length of output: 338

jest.setup.js (1)

2-5: Approve the addition of enableMocks in jest setup.

The addition of enableMocks from 'jest-fetch-mock' is necessary for the new testing setup and appears to be correctly implemented. Ensure that this setup is isolated and does not interfere with other mocks or settings.

README.md (1)

84-86: Updated Network Requests Section

The documentation has been updated to reflect the switch from Apisauce to Wretch for API calls. This change aligns with the PR's objectives and should help in reducing the bundle size.

Please ensure that the links provided in the documentation are active and lead to the correct resources.

package.json (1)

129-129: Updated Dependencies in package.json

The dependencies have been updated to include wretch and jest-fetch-mock, aligning with the PR's goal of replacing Apisauce with Wretch. This should help in reducing the bundle size and improving test setups.

Please ensure that the removal of apisauce and axios-mock-adapter does not affect other parts of the application that might still rely on these packages.

Also applies to: 218-218

Verification successful

Updated Dependencies in package.json

The dependencies have been updated to include wretch and jest-fetch-mock, aligning with the PR's goal of replacing Apisauce with Wretch. This should help in reducing the bundle size and improving test setups.

No references to apisauce or axios-mock-adapter were found in the codebase, confirming that these dependencies have been successfully removed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that no other parts of the application still rely on `apisauce` or `axios-mock-adapter`.

# Test: Search for any remaining references to `apisauce` or `axios-mock-adapter`.
rg --type json -A 5 $'apisauce|axios-mock-adapter'

Length of output: 51


Script:

#!/bin/bash
# Description: Verify that no other parts of the application still rely on `apisauce` or `axios-mock-adapter`.

# Test: Search for any remaining references to `apisauce` or `axios-mock-adapter` in all file types.
rg 'apisauce|axios-mock-adapter' -A 5

Length of output: 39

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6e93de1 and 92ab192.

Files selected for processing (1)
  • README.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • README.md

@praveenkumar1798 praveenkumar1798 merged commit 5bf0a34 into wednesday-solutions:master Jul 18, 2024
4 checks passed
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.

2 participants