I am using hapi for a simple API. I need to submit some data to a 3rd party api, with the data in a POST body, Content-Type: application/x-www-form-urlencoded in the header and the body containing the form data. I'm doing this successfully using form-data and node-fetch.
I'm writing a test for this using jest-fetch-mock to mock the fetch service. However, the mocked fetch request is a FormData() object, and to get the values of the body I have to use the form-data methods, specifically getBuffer(). The best I can do is get the text of the form data stream, which looks like this:
----------------------------873172308964049871716608
Content-Disposition: form-data; name="grant_type"
mockAuthorization_code
----------------------------873172308964049871716608
Content-Disposition: form-data; name="code"
mockAuthCode
----------------------------873172308964049871716608
Content-Disposition: form-data; name="redirect_uri"
redirectUrl.com/
----------------------------873172308964049871716608--
Is there any way I can parse these to test that the correct values are being submitted?
Thanks