Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add allowed error message to integration testsuite's malformed JSON t…
…est (#7080) I'm currently building a Next.js integration for Apollo Server 4 over [here](https://github.com/apollo-server-integrations/apollo-server-integration-next). To make sure the integration works properly with Next.js I'm reusing Next.js's [apiResolver](https://github.com/vercel/next.js/blob/canary/packages/next/server/api-utils/node.ts#L426), which handles parsing API route requests. I [managed to make every test](apollo-server-integrations/apollo-server-integration-next#14) in `apollo-server-integrations-testsuite` pass except for one, `throws an error if POST JSON is malformed`. This test checks the error message in the server response when malformed JSON data is sent and matches it to two possible substrings, `Unexpected token f` and `Bad Request`. Next.js's `apiResolver` uses the [parseBody](https://github.com/vercel/next.js/blob/canary/packages/next/server/api-utils/node.ts#L143) function to parse the request body, which in turn uses [parseJSON](https://github.com/vercel/next.js/blob/canary/packages/next/server/api-utils/node.ts#L126) to parse JSON. In the case of malformed JSON `parseJSON` throws an `ApiError` with the message `Invalid JSON`, which is then returned in the server response. Since it's not possible for me to change the message returned by Next.js I was hoping I could add it to the tests's allowed error messages, making the test pass. Co-authored-by: David Glasser <[email protected]>
- Loading branch information