summaryrefslogtreecommitdiff
path: root/src/push/handlers/ping/test.rs
blob: 34811390634bf50ba9bab48af90de53ffdcb6efd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use axum::{
    extract::{Json, State},
    http::StatusCode,
};
use itertools::Itertools;

use crate::{event::Heartbeat, test::fixtures};

#[tokio::test]
async fn ping_without_subscriptions() {
    let app = fixtures::scratch_app().await;

    let recipient = fixtures::identity::create(&app, &fixtures::now()).await;

    let response = super::handler(State(app.push()), recipient, Json(super::Request {}))
        .await
        .expect("sending a ping with no subscriptions always succeeds");

    assert_eq!(StatusCode::ACCEPTED, response);

    assert!(
        app.publisher()
            .sent()
            .into_iter()
            .filter(|publish| publish.message_eq(&Heartbeat::Heartbeat)
                && publish.subscriptions.is_empty())
            .exactly_one()
            .is_ok()
    );
}

// More complete testing requires that we figure out how to generate working p256 ECDH keys for
// testing _with_, as `web_push` will actually parse and use those keys even if push messages are
// ultimately never serialized or sent over HTTP.
//
// Tests that are missing:
//
// * Verify that subscribing and sending a ping causes a ping to be delivered to that subscription.
// * Verify that two subscriptions both get pings.
// * Verify that other users' subscriptions are not pinged.
// * Verify that a ping that causes a permanent error causes the subscription to be deleted.
// * Verify that a ping that causes a non-permanent error does not cause the subscription to be
//   deleted.
// * Verify that a failure on one subscription doesn't affect delivery on other subscriptions.