-
Notifications
You must be signed in to change notification settings - Fork 360
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
Cannot get API mocking non-default responses to work correctly on Windows #147
Comments
@chrisprijic great question! So you are using a completely different version of prism, and the way mocking works with the above command is a little bit different. You don't need any javascript actually, and to control the status code, use the query string parameter __code=400 to change the code being mocked back. Let me know if you have any issues with that, tomorrow I will create a mock server for you that uses a header. Are you trying to do something similar to sendgrid with your sdks? |
@pytlesk4 thanks! That worked great, and as expected. Is there any documentation, or a point of origin this is from, so I can let SendGrid know (I'll obviously ref this issue)? |
So there are some docs on prism here, https://docs.stoplight.io. And then for the mock server, and how it works, there are some docs in this scenario description. I actually need to update that description because it has changed quite a bit, but those options still work. I will do that tomorrow when I get into work. |
@chrisprijic also this blog post talks about one of the new features. |
@pytlesk4 thanks for all this, and the rapid responses. I'm new to prism and am using through another repo (see refs), so this is good for me to know. I'm good to go now, and I'll work on updating my tests to use the querystring parameter rather than the |
Overview
Checking in from sendgrid/sendgrid-go#257 with some issues using a
beforeScript
to enable mocking.Their implementation includes an option to provide an
X-Mock
header to the API being mocked, and using a similarbeforeScript
to enable mocking and choosing the response to return from it:Where the value of the
X-Mock
header is the status code for the response -- a la400
or413
or200
.However, when using their mock API, I always get the standard response, and the
X-Mock
header is ignored. I even tried adding additional logging in thebeforeScript
but could not get anything to work.I'm hoping that posting here can help me find some insights into getting this working!
Details (from sendgrid/sendgrid-go#257)
OS: Windows 10
Using: prism.exe (x64)
Version: 2.0.9
command: prism.exe mock -d -s https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json -p 4000
The above utilizes an X-Mock header to specify the response code to mock back. However, even when mocking endpoints like POST /alerts (below) without a request body, and with X-Mock header set to 400, I still get a 201 response code and a 201 response body.
example cURL:
example output:
When running that cURL command, it should return the provided
400
response, but instead it still returns a201
.Question
Is there a better way to do this, or is it clear what I'm doing wrong? I need to get this working in order to test API Client methods I'm writing for the API.
The text was updated successfully, but these errors were encountered: