wuapi 0.17.0

Rust SDK for wuapi, a WhatsApp API for developers. Link numbers by QR or pairing code, send and receive messages, manage chats, contacts, groups and channels, split them into projects and verify webhooks.
Documentation
// Generated by wuapi-codegen from the OpenAPI spec. Do not edit: run `bun run codegen`.

#![allow(unused_imports)]

use crate::sdk::{self, types};
use crate::support::{self, KEY, MockApi, Reply};

#[tokio::test]
async fn stream_opens_the_stream() {
    let frame = "id: c1\nevent: sample\ndata: {\"id\":\"evt_1\",\"object\":\"event\"}\n\n";
    let api = MockApi::start(vec![Reply::raw(200, frame, "text/event-stream")]).await;
    let client = api.client();
    let params = sdk::resources::events::EventsStreamParams::new()
        .types([types::WebhookEventType::AccountQrCodeIssued])
        .accounts(["a", "b"])
        .last_event_id("c0");
    let mut stream = client.events().stream(params).unwrap();
    let event = stream.next_event().await.unwrap().unwrap();
    assert_eq!(event.event, "sample");
    assert_eq!(event.id.as_deref(), Some("evt_1"));
    assert_eq!(event.cursor.as_deref(), Some("c1"));
    assert_eq!(event.data, "{\"id\":\"evt_1\",\"object\":\"event\"}");
    assert_eq!(stream.last_event_id(), Some("c1"));
    stream.close();
    assert!(stream.next_event().await.is_none());

    let calls = api.calls().await;
    assert_eq!(calls.len(), 1);
    assert_eq!(calls[0].method, "GET");
    assert_eq!(calls[0].path, "/v1/events/stream");
    assert_eq!(calls[0].query, support::pairs(&[("types", "account.qr_code_issued"), ("accounts", "a,b")]));
    assert_eq!(calls[0].header("authorization"), Some(format!("Bearer {KEY}").as_str()));
    assert_eq!(calls[0].header("accept"), Some("text/event-stream"));
    assert_eq!(calls[0].header("user-agent"), Some(sdk::USER_AGENT));
    assert_eq!(calls[0].header("Last-Event-ID"), Some("c0"));
}