Testing | laravel-mailcoach-sdk-rust | Spatie       

 SPATIE  

laravel-mailcoach-sdk-rust
==========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-mailcoach-sdk-rust](https://spatie.be/docs/laravel-mailcoach-sdk-rust/v1)  Testing

 Version   v1      

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

  Testing    
- [ Introduction ](https://spatie.be/docs/laravel-mailcoach-sdk-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-mailcoach-sdk-rust/v1/support-us)
- [ Installation ](https://spatie.be/docs/laravel-mailcoach-sdk-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-mailcoach-sdk-rust/v1/usage)
- [ Testing ](https://spatie.be/docs/laravel-mailcoach-sdk-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-mailcoach-sdk-rust/v1/changelog)

 Testing
=======

###  On this page 

1. [ Fake Mailcoach ](#content-fake-mailcoach)
2. [ Quality checks ](#content-quality-checks)

Fake Mailcoach
--------------------------------------------------------------------------------------------------

1. Add `wiremock = "0.6"` and Tokio with `macros` and `rt-multi-thread` to your dev dependencies.
2. Start an isolated loopback server and pass its URL to the client.
3. Assert the result and expected requests. No Mailcoach credentials are needed.

```
use serde_json::json;
use spatie_mailcoach_sdk::Mailcoach;
use wiremock::{Mock, MockServer, ResponseTemplate, matchers::{method, path, header}};

let server = MockServer::start().await;
Mock::given(method("GET"))
    .and(path("/api/campaigns/newsletter"))
    .and(header("authorization", "Bearer test-token"))
    .respond_with(ResponseTemplate::new(200).set_body_json(json!({
        "data": {"uuid": "newsletter", "name": "Rust news", "status": "draft"}
    })))
    .expect(1)
    .mount(&server).await;

let client = Mailcoach::new("test-token", &server.uri()).unwrap();
let campaign = client.campaign("newsletter").await.unwrap();

assert_eq!(campaign.name, "Rust news");
```

The SDK uses reqwest, so the framework HTTP fake does not intercept its requests. Always use the loopback server URL in tests. In the mailer package, use the framework HTTP fake or `mail::fake()` instead. Mailcoach's `fake` payload option still contacts its server and must not be used as a local fake.

Quality checks
--------------------------------------------------------------------------------------------------

Run these checks from the package directory:

```
cargo fmt --all -- --check
cargo clippy --locked --all-targets --all-features -- -D warnings
cargo clippy --locked --all-targets --no-default-features -- -D warnings
cargo test --locked --all-targets --all-features
cargo test --locked --doc --all-features
cargo test --locked --all-targets --no-default-features
cargo test --locked --doc --no-default-features
cargo doc --locked --no-deps --all-features
```

Set `RUSTDOCFLAGS` to `-D warnings` when running the documentation commands. In POSIX shells, prefix each command with `RUSTDOCFLAGS='-D warnings'`. In PowerShell, first run `$env:RUSTDOCFLAGS = '-D warnings'`.

README.md and all Markdown pages in docs/ participate in rustdoc tests. Setup lines prefixed with `# ` compile and execute but are hidden in rendered rustdoc. Assertions check the examples' results.

Check the minimum supported Rust version:

```
rustup toolchain install 1.99.0 --profile minimal
cargo +1.99.0 test --locked --all-targets --all-features
cargo +1.99.0 test --locked --doc --all-features
```

Check security advisories:

```
cargo install cargo-audit --locked
cargo audit
```

CI runs stable checks on Linux, macOS and Windows, and the MSRV and audit checks on Linux. An audit requires access to the RustSec advisory database.

The HTTP tests start loopback fixture servers and check methods, paths, authentication, JSON payloads, pagination, errors and timeouts. Every resource endpoint has a loopback contract check. Provider tests use `#[laravel::test]` and check singleton resolution, isolated SDK environment defaults, application config, binding overrides and lazy errors. No real API credentials are needed and no production API requests are made.

`publish = false` prevents publication. Registry package verification is not a delivery step for this Git-dependent crate; CI compiles and tests its source directly. CI can fetch the public package-tools dependency without credentials. When `SPATIE_GITHUB_TOKEN` is configured, it is used for authenticated dependency reads.

 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)
