question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DSL for Http Server to assert on Webhooks and similar

See original GitHub issue

I want to test that my API is calling webhooks, and that it is sending the data as specified. Currently, I need to write my own HTTP server that saves and returns the data, so I can assert it. It would be awesome to have this integrated in Cornichon.

Here’s an example with a made-up DSL:

// Create the HTTP server that listens for webhooks
When I httpListenTo("http://localhost:12345/webhook")
// Do something that should trigger the webhook
When I post("/users").withBody(
"""
{
  "firstname": "Foo",
  "lastname": "Bar"
}
""")
Then assert status.is(201)
// Check that webhook was delivered
Then assert httpListen.received_calls(1)
And assert httpListen.lastBody.is(...)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
agourlaycommented, Sep 5, 2016

Here is what I believe I can propose for a start.

httpListenTo(label = "my-server", port = 12345){
  When I post("/users").withBody(
  """
  {
    "firstname": "Foo",
    "lastname": "Bar"
  }
  """) 
  Then assert status.is(201)
}
// Check that webhook was delivered
Then assert httpListen("my-server").received_calls(1)
And assert httpListen("my-server").receivedRequest(1).onUrl("...").withVerb("...").withBody("...")

Design points:

  • the server is automatically started and stopped at the end of the block.
  • assertions on the server must be done outside of the block.
  • by default POST will receive 201 and the rest 200.

WDYT?

0reactions
agourlaycommented, Oct 10, 2016

first public version shipped in 0.9.3 + minimal doc available in Readme.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Build a Webhook System in Rails Using Sidekiq
It's going to accept a webhook ID as an input parameter, use that to query the endpoint, then POST the event payload to...
Read more >
Verifying whether specific HTTP requests were made | WireMock
Verifying and querying requests relies on the request journal, which is an in-memory log of received requests. This can be disabled for load...
Read more >
HTTP - Apache Camel
Send requests to external HTTP servers using Apache HTTP Client 4.x. ... Configuring components can be done with the Component DSL, in a...
Read more >
Testing Webhooks with JS - Assert.This
The post route accepts incoming webhook requests and responds with our default status code. The webhook request is destructured so we can ...
Read more >
checkr/openmock: Mock all the services. Intuitive ... - GitHub
Intuitive YAML DSL for HTTP, gRPC, Kafka, and AMQP mocks. - GitHub - checkr/openmock: Mock ... Used in Makefile during swagger admin API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found