Skip to content

Commit

Permalink
chore: add proper body transformation to sneak case with wretch (#202)
Browse files Browse the repository at this point in the history
* chore: add proper body transformation to sneak case with wretch

* chore: handle case where body is not valid json

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: remove object mutation error

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
naeemdadi1 and coderabbitai[bot] authored Jul 23, 2024
1 parent 5bf0a34 commit 7740866
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/services/repoApi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { generateApiClient } from '@utils/apiUtils';
const repoApi = generateApiClient('github');

/**
* @see https://github.com/elbywan/wretch?tab=readme-ov-file#http-methods-
*/
export const getRepos = (repoName) => repoApi.get(`search/repositories?q=${repoName}`);
10 changes: 8 additions & 2 deletions app/utils/apiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ export const createApiClientWithTransForm = (baseURL) => {
const { body } = opts;
if (body) {
// this needs to actually mutate the request
// eslint-disable-next-line immutable/no-mutation
opts.body = mapKeysDeep(body, (keys) => snakeCase(keys));
try {
const parsedBody = JSON.parse(body);
// eslint-disable-next-line immutable/no-mutation
opts.body = JSON.stringify(mapKeysDeep(parsedBody, (keys) => snakeCase(keys)));
} catch (error) {
console.error('Invalid JSON body:', error);
throw new Error('Invalid JSON body');
}
}
return next(url, opts);
};
Expand Down

2 comments on commit 7740866

@github-actions
Copy link

Choose a reason for hiding this comment

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

Jest Coverage Report

Total coverage

Status Category Percentage Covered / Total
🟢 Statements 98.62% 357/362
🟢 Branches 95.76% 113/118
🟢 Functions 98.31% 116/118
🟢 Lines 98.73% 310/314

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

Report generated by 🧪jest coverage report action from 96b0465

@github-actions
Copy link

Choose a reason for hiding this comment

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

Jest Coverage Report

Total coverage

Status Category Percentage Covered / Total
🟢 Statements 98.62% 357/362
🟢 Branches 95.76% 113/118
🟢 Functions 98.31% 116/118
🟢 Lines 98.73% 310/314

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

Report generated by 🧪jest coverage report action from 778aa5e

Please sign in to comment.