Skip to content
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

Allow to specify request body on serverMock #50

Open
josemarluedke opened this issue May 14, 2019 · 3 comments · May be fixed by #61
Open

Allow to specify request body on serverMock #50

josemarluedke opened this issue May 14, 2019 · 3 comments · May be fixed by #61

Comments

@josemarluedke
Copy link

Server mocks are great! I have already been using it and works nicely.

I'm using it to mock a GraphQL server. While it has been working fine for my set of simple tests, for me to be able to use it further, I would need to be able to mock requests on the same path but differentiate it on the request body.

It seems that nock does support this use case: https://github.com/nock/nock#specifying-request-body

Note that all requests to a GraphQL server are POST methods.

Supporting request body as String, RegExp and JSON object should do the trick.

@ryanto
Copy link
Member

ryanto commented May 14, 2019

Ah nice catch! I didn't even think about GraphQL's single endpoint for this feature.

What do you think of this API?

mockServer.post('/graphql', { requestBody }, { responseBody }, statusCode);

Another idea would be just to copy nock's API.

mockServer
  .post('/graphql', { requestBody })
  .reply({ responseBody }, statusCode);

Any thoughts?

@josemarluedke
Copy link
Author

I personally prefer the second option, something more similar to nock's API. It does help differentiate from the request to response a little more.

@ryanto
Copy link
Member

ryanto commented May 19, 2019

Ok I started a PR for this. Would love to get your feedback on these two sample tests: https://github.com/embermap/ember-cli-fastboot-testing/pull/51/files#diff-8f31fb1d9a649d88e4e1f5431a3c6465

Right now it only mocks the request body as JSON (or a string).

I know you mentioned wanting to support a RegExp object, do you have any examples of tests that need that? I was having trouble coming up with something to test here.

@CvX CvX linked a pull request Jun 21, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants