-
Notifications
You must be signed in to change notification settings - Fork 92
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
feat: replace apisauce with wretch #201
Conversation
WalkthroughThe changes replace Changes
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
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: 0
Outside diff range, codebase verification and nitpick comments (1)
app/utils/apiUtils.js (1)
59-90
: Add tests forcreateApiClientWithTransForm
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
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 ingetRepos
.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 usinggenerateApiClient('github')
, which sets the base URL fromprocess.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 5Length 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 5Length 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
anditems
, 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 ofenableMocks
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 SectionThe 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.jsonThe dependencies have been updated to include
wretch
andjest-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
andaxios-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
andjest-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
oraxios-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 5Length of output: 39
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: 0
Ticket Link
Related Links
Description
Reason to migrate from apisauce to wretch
Reduce bundle size
With apisauce
With Wretch
Steps to Reproduce / Test
Checklist
yarn test
passesGIF's
Live Link
Summary by CodeRabbit
New Features
Api Sauce
toWretch
for API calls, enhancing network request handling.Bug Fixes
Tests
Chores
apisauce
andaxios-mock-adapter
, addedwretch
andjest-fetch-mock
.jest-fetch-mock
for testing purposes.