summaryrefslogtreecommitdiff
path: root/src/test/fixtures
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-12-09 15:13:21 -0500
committerOwen Jacobson <owen@grimoire.ca>2025-12-17 15:48:20 -0500
commit3c697f5fb1b8dbad46eac8fa299ed7cebfb36159 (patch)
treeb7854fb23d1e104f928acfe3bba75ea3b74b83d9 /src/test/fixtures
parent41a5a0f7e13bf5a82aaef59e34eb68f0fe7fa7f5 (diff)
Factor push message publication out to its own helper component.
The `Publisher` component handles the details of web push delivery. Callers must provide the subscription set, the current signer, and the message, while the publisher handles encoding and communication with web push endpoints. To facilitate testing, `Publisher` implements `Publish`, which is a new trait with the same interface. Components that might publish web push messages should rely on the trait where possible. The test suite now constructs an app with a dummy `Publish` impl, which captures push messages for examination. Note that the testing implementation of `Publish` is hand-crafted, and presently only acts to record the arguments it receives. The other alternative was to use a mocking library, such as `mockit`, and while I've used that approach before, I'm not super comfortable with the complexity in this situation. I think we can maintain a more reasonable testing `Publish` impl by hand, at least for now, and we can revisit that decision later if need be. Tests for the `ping` endpoint have been migrated to this endpoint.
Diffstat (limited to 'src/test/fixtures')
-rw-r--r--src/test/fixtures/mod.rs12
-rw-r--r--src/test/fixtures/vapid.rs16
2 files changed, 28 insertions, 0 deletions
diff --git a/src/test/fixtures/mod.rs b/src/test/fixtures/mod.rs
index 53bf31b..85935d6 100644
--- a/src/test/fixtures/mod.rs
+++ b/src/test/fixtures/mod.rs
@@ -12,8 +12,20 @@ pub mod invite;
pub mod login;
pub mod message;
pub mod user;
+pub mod vapid;
pub async fn scratch_app() -> App<Client> {
+ let app = scratch_app_without_vapid().await;
+
+ app.vapid()
+ .refresh_key(&now())
+ .await
+ .expect("refreshing the VAPID key always succeeds");
+
+ app
+}
+
+pub async fn scratch_app_without_vapid() -> App<Client> {
let pool = db::prepare("sqlite::memory:", "sqlite::memory:")
.await
.expect("setting up in-memory sqlite database");
diff --git a/src/test/fixtures/vapid.rs b/src/test/fixtures/vapid.rs
new file mode 100644
index 0000000..29cdf1a
--- /dev/null
+++ b/src/test/fixtures/vapid.rs
@@ -0,0 +1,16 @@
+use p256::ecdsa::VerifyingKey;
+
+use crate::{app::App, test::fixtures};
+
+pub async fn key<P>(app: &App<P>) -> VerifyingKey {
+ let boot = app.boot().snapshot().await.expect("boot always succeeds");
+ let changed = boot
+ .events
+ .into_iter()
+ .filter_map(fixtures::event::vapid)
+ .filter_map(fixtures::event::vapid::changed)
+ .next_back()
+ .expect("the application has a vapid key");
+
+ changed.key
+}