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

Cannot mock API by X-Mock header using Prism Windows #257

Open
chrisprijic opened this issue May 17, 2018 · 7 comments
Open

Cannot mock API by X-Mock header using Prism Windows #257

chrisprijic opened this issue May 17, 2018 · 7 comments
Labels
difficulty: unknown or n/a fix is unknown in difficulty status: help wanted requesting help from the community type: twilio enhancement feature request on Twilio's roadmap

Comments

@chrisprijic
Copy link

chrisprijic commented May 17, 2018

Issue Summary

I'm working on struct-ing out a bit more of the SendGrid API for a project, and am diving into testing the first few endpoints I've been building out (in hopes to provide some PR's in the future!)

However, when running tests using prism and the provided SendGrid OAI spec (see below), I cannot mock anything else besides the "default" response code an endpoint provides. The X-Mock header doesn't seem to affect output from prism.

Steps to Reproduce

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

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 code:

// assuming prism is running, mocking the API w/ the above command
// and running on the default port of 4010:
req, _:= http.NewRequest("POST", "localhost:4010/v3/alerts", nil)

req.Header.Set("Authorization", "Bearer SENDGRID_APIKEY")
req.Header.Set("Accept", "application/json")
req.Header.Set("X-Mock", "400")

response, err := http.DefaultClient.Do(req)
// here, response.StatusCode is 201, and the response body shows the 
// mocked 201 response object, and err is nil

response status code: 201

response body:

{"created_at":1451520930,"email_to":"[email protected]","frequency":"daily","id":48,"type":"stats_notification","updated_at":1451520930}

I have tried altering the oai-stoplight.json beforeScript functions but to no avail...

Technical details:

  • sendgrid-go Version: master (latest commit: 588320a)
  • Go Version: 1.10.1 windows/amd64
@thinkingserious thinkingserious added type: question question directed at the library status: help wanted requesting help from the community difficulty: unknown or n/a fix is unknown in difficulty labels May 17, 2018
@thinkingserious
Copy link
Contributor

Thanks for reporting this @chrisprijic,

I've added this to our backlog for review. In the mean time, perhaps the prism documentation or the StopLight team might have some insight.

With Best Regards,

Elmer

@chrisprijic
Copy link
Author

Answer from: stoplightio/prism#147

Looks like the new version of prism uses __code=400 (or any status code) as a query param to allow specified output. They'll get back to me about where this documentation is, or where you can have a reference for this.

As for this repo and my issue, I'll leave it up to you on how to handle this -- if prism's version needs to be explicitly stated or if you want to update to the newest prism way of mocking a particular response.

If you want to update, I'd be happy to provide a PR for it. I'll check out the contributing docs tomorrow morning regardless.

@pytlesk4
Copy link
Contributor

@thinkingserious did you guys update to the new version of Prism? If you did, let's make some time next week to migrate you over properly. Let me know.

@thinkingserious
Copy link
Contributor

Hi @pytlesk4,

We are now running a pre-loaded Prism in a Docker container, like so. I would love to learn how to get upgraded to the latest version.

How about Tuesday 11am PST?

Thanks!

With Best Regards,

Elmer

@thinkingserious
Copy link
Contributor

Hello @chrisprijic,

We use this older version of Prism (here are the docs) in this manner.

The functionality you want is available in the newest version of Prism. If you would like to help us with upgrading to the newest version, a PR would be most welcome :) Note that we have been moving towards setting up Prism within a Docker container, like so.

With Best Regards,

Elmer

P.S. Thanks to @pytlesk4 for helping out!

@pytlesk4
Copy link
Contributor

Here is an example of it with golang: https://github.com/pytlesk4/sendgrid-go/tree/prism-2.0

@childish-sambino childish-sambino added type: twilio enhancement feature request on Twilio's roadmap and removed hacktoberfest type: question question directed at the library labels Aug 3, 2020
@childish-sambino
Copy link
Contributor

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: unknown or n/a fix is unknown in difficulty status: help wanted requesting help from the community type: twilio enhancement feature request on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

4 participants