diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-23 01:14:47 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-23 01:14:47 -0400 |
| commit | dd78dcf2ef69f636e45c38791684099ed591e450 (patch) | |
| tree | 261de6344981f8cfca8676d16b2388434f8270c4 | |
| parent | 3fab58827017041168a769184469cff3722d6c38 (diff) | |
Test boot more thoroughly.
| -rw-r--r-- | src/boot/routes/test.rs | 125 | ||||
| -rw-r--r-- | src/test/fixtures/message.rs | 4 |
2 files changed, 124 insertions, 5 deletions
diff --git a/src/boot/routes/test.rs b/src/boot/routes/test.rs index 0430854..8808b70 100644 --- a/src/boot/routes/test.rs +++ b/src/boot/routes/test.rs @@ -6,10 +6,129 @@ use crate::test::fixtures; #[tokio::test] async fn returns_identity() { let app = fixtures::scratch_app().await; - let identity = fixtures::identity::fictitious(); - let response = get::handler(State(app), identity.clone()) + + let viewer = fixtures::identity::fictitious(); + let response = get::handler(State(app), viewer.clone()) + .await + .expect("boot always succeeds"); + + assert_eq!(viewer.login, response.login); +} + +#[tokio::test] +async fn includes_logins() { + let app = fixtures::scratch_app().await; + let spectator = fixtures::login::create(&app, &fixtures::now()).await; + + let viewer = fixtures::identity::fictitious(); + let response = get::handler(State(app), viewer) + .await + .expect("boot always succeeds"); + + assert!(response.snapshot.logins.contains(&spectator)); +} + +#[tokio::test] +async fn includes_channels() { + let app = fixtures::scratch_app().await; + let channel = fixtures::channel::create(&app, &fixtures::now()).await; + + let viewer = fixtures::identity::fictitious(); + let response = get::handler(State(app), viewer) + .await + .expect("boot always succeeds"); + + assert!(response.snapshot.channels.contains(&channel)); +} + +#[tokio::test] +async fn includes_messages() { + let app = fixtures::scratch_app().await; + let sender = fixtures::login::create(&app, &fixtures::now()).await; + let channel = fixtures::channel::create(&app, &fixtures::now()).await; + let message = fixtures::message::send(&app, &channel, &sender, &fixtures::now()).await; + + let viewer = fixtures::identity::fictitious(); + let response = get::handler(State(app), viewer) + .await + .expect("boot always succeeds"); + + assert!(response.snapshot.messages.contains(&message)); +} + +#[tokio::test] +async fn excludes_expired_messages() { + let app = fixtures::scratch_app().await; + let sender = fixtures::login::create(&app, &fixtures::ancient()).await; + let channel = fixtures::channel::create(&app, &fixtures::ancient()).await; + let expired_message = + fixtures::message::send(&app, &channel, &sender, &fixtures::ancient()).await; + + app.messages() + .expire(&fixtures::now()) + .await + .expect("expiry never fails"); + + let viewer = fixtures::identity::fictitious(); + let response = get::handler(State(app), viewer) + .await + .expect("boot always succeeds"); + + assert!(!response.snapshot.messages.contains(&expired_message)); +} + +#[tokio::test] +async fn excludes_deleted_messages() { + let app = fixtures::scratch_app().await; + let sender = fixtures::login::create(&app, &fixtures::now()).await; + let channel = fixtures::channel::create(&app, &fixtures::now()).await; + let deleted_message = fixtures::message::send(&app, &channel, &sender, &fixtures::now()).await; + + app.messages() + .delete(&deleted_message.id, &fixtures::now()) + .await + .expect("deleting valid message succeeds"); + + let viewer = fixtures::identity::fictitious(); + let response = get::handler(State(app), viewer) + .await + .expect("boot always succeeds"); + + assert!(!response.snapshot.messages.contains(&deleted_message)); +} + +#[tokio::test] +async fn excludes_expired_channels() { + let app = fixtures::scratch_app().await; + let expired_channel = fixtures::channel::create(&app, &fixtures::ancient()).await; + + app.channels() + .expire(&fixtures::now()) + .await + .expect("expiry never fails"); + + let viewer = fixtures::identity::fictitious(); + let response = get::handler(State(app), viewer) + .await + .expect("boot always succeeds"); + + assert!(!response.snapshot.channels.contains(&expired_channel)); +} + +#[tokio::test] +async fn excludes_deleted_channels() { + let app = fixtures::scratch_app().await; + let deleted_channel = fixtures::channel::create(&app, &fixtures::now()).await; + + app.channels() + .delete(&deleted_channel.id, &fixtures::now()) + .await + .expect("deleting a valid channel succeeds"); + + let viewer = fixtures::identity::fictitious(); + let response = get::handler(State(app), viewer) .await .expect("boot always succeeds"); - assert_eq!(identity.login, response.login); + assert!(!response.snapshot.channels.contains(&deleted_channel)); } diff --git a/src/test/fixtures/message.rs b/src/test/fixtures/message.rs index c450bce..38b511f 100644 --- a/src/test/fixtures/message.rs +++ b/src/test/fixtures/message.rs @@ -11,11 +11,11 @@ use crate::{ message::{self, Body, Message}, }; -pub async fn send(app: &App, channel: &Channel, login: &Login, sent_at: &RequestedAt) -> Message { +pub async fn send(app: &App, channel: &Channel, sender: &Login, sent_at: &RequestedAt) -> Message { let body = propose(); app.messages() - .send(&channel.id, login, sent_at, &body) + .send(&channel.id, sender, sent_at, &body) .await .expect("should succeed if the channel exists") } |
