Testing webhooks | laravel-webhook-server-rust | Spatie       

 SPATIE  

laravel-webhook-server-rust
===========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-webhook-server-rust](https://spatie.be/docs/laravel-webhook-server-rust/v1)  Testing webhooks

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-webhook-server-rust/v1) 

  Testing webhooks    
- [ Introduction ](https://spatie.be/docs/laravel-webhook-server-rust/v1/introduction)
- [ Installation and setup ](https://spatie.be/docs/laravel-webhook-server-rust/v1/installation-and-setup)
- [ Sending webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/sending-webhooks)
- [ Signing requests ](https://spatie.be/docs/laravel-webhook-server-rust/v1/signing-requests)
- [ Retrying failed webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/retrying-failed-webhooks)
- [ Transport options ](https://spatie.be/docs/laravel-webhook-server-rust/v1/transport-options)
- [ Events ](https://spatie.be/docs/laravel-webhook-server-rust/v1/events)
- [ Testing webhooks ](https://spatie.be/docs/laravel-webhook-server-rust/v1/testing-webhooks)
- [ Upgrading ](https://spatie.be/docs/laravel-webhook-server-rust/v1/upgrading)
- [ Testing ](https://spatie.be/docs/laravel-webhook-server-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-webhook-server-rust/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-webhook-server-rust/v1/support-us)

 Testing webhooks
================

###  On this page 

1. [ Assert HTTP requests ](#content-assert-http-requests)
2. [ Assert dispatch without executing the job ](#content-assert-dispatch-without-executing-the-job)
3. [ Contributing to the package ](#content-contributing-to-the-package)

Assert HTTP requests
--------------------------------------------------------------------------------------------------------------------

Use Laravel's HTTP fake in the same application scope as delivery:

```
use laravel::{Application, config::Env, http::client};
use serde_json::json;
use spatie_laravel_webhook_server::{WebhookCall, service_provider};

let app = Application::configure()
    .replace_env(Env::default())
    .with_providers(|providers| { providers.add(service_provider()); })
    .create();

app.scope(async || {
    let http = client::fake()
        .prevent_stray_requests()
        .with("other-app.com/webhooks", client::response().status(204));

    WebhookCall::create()
        .url("https://other-app.com/webhooks")
        .payload(json!({"order_id": 123}))
        .use_secret("your-shared-secret")
        .dispatch_sync().await?;

    http.assert_sent_count(1).assert_sent(|request| {
        request.method() == "POST" && request.body() == br#"{"order_id":123}"#
            && request.header("signature").is_some()
    });
    Ok::<(), laravel::Error>(())
}).await?;
```

Fakes are application-local and are not shared with a separate worker process. Use `laravel::testing::RunsJobs` to execute serialized native job attempts and assert delayed release/failure behavior without sleeping through backoff.

Assert dispatch without executing the job
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Inside application scope, use `laravel::queue::fake()` before calling `dispatch().await`, then `assert_pushed::<CallWebhookJob>()`. This records queue dispatch without making an HTTP request. Custom job dispatchers can be asserted using their native job types instead.

Contributing to the package
-----------------------------------------------------------------------------------------------------------------------------------------

See [testing](testing) for formatting, Clippy, tests, doctests, packaging and MSRV checks. Integration tests exercise native application configuration, HTTP fakes, queue serialization and an actual local HTTP server. No third-party endpoint or credentials are required for the tests.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
