AmadeusITGroup / kassette

kassette is a development server, used mainly for testing, which proxies requests and is able to easily manage local mocks.
MIT License
9 stars 15 forks source link

Provide option to save bodies as JSON objects #487

Closed KayleighYum closed 11 months ago

KayleighYum commented 11 months ago

A new configuration option has been added, saveStringBodies, which is set to true by default. This can be changed with the new setSaveStringBodies method. A new parameter has been added to toHarPostData and toHarContent where saveStringBodies will be passed in.

When saveStringBodies is set to false and the mimeType of the request/response is application/json the body will be json parsed and saved.

This will only be applied when the mockFormat is 'HAR'. This will be applied to both request (when saveInputRequestBody is true) and response bodies.

KayleighYum commented 11 months ago

@KayleighYum Thank you very much for your PR! It is a good improvement for kassette. I have left some comments about the things I think should or could be changed before integrating this new feature.

Thanks @divdavem! I'll take a look at the comments

KayleighYum commented 11 months ago

@divdavem I have fixed the issue with the failing api doc generation. Apologies about that

codecov[bot] commented 11 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (ce30f1d) 91.52% compared to head (9a8e4a8) 91.64%. Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #487 +/- ## ========================================== + Coverage 91.52% 91.64% +0.11% ========================================== Files 36 36 Lines 1192 1209 +17 Branches 268 273 +5 ========================================== + Hits 1091 1108 +17 Misses 50 50 Partials 51 51 ``` | [Flag](https://app.codecov.io/gh/AmadeusITGroup/kassette/pull/487/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AmadeusITGroup) | Coverage Δ | | |---|---|---| | [e2e](https://app.codecov.io/gh/AmadeusITGroup/kassette/pull/487/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AmadeusITGroup) | `79.56% <50.00%> (-0.47%)` | :arrow_down: | | [ut](https://app.codecov.io/gh/AmadeusITGroup/kassette/pull/487/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AmadeusITGroup) | `60.29% <86.36%> (+0.39%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AmadeusITGroup#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

KayleighYum commented 11 months ago

Hi @KayleighYum ! Thank you very much for the changes you have already made following my comments and to fix the build failure. If it is ok for you, I have added some more comments to improve the code before we can integrate it. Thank you!

Hey @divdavem I've made the adjustments based on your feedback, please can you resolve the conversations if you're happy with the changes or let me know if I've missed anything

divdavem commented 11 months ago

@KayleighYum Thank you very much for your PR! It is now integrated. :tada: We will release a new kassette version on npm soon. If you have any feedback about kassette, and how you use it, we are always happy to hear about it.