From ea74daca4809e4008dd8d01039db9fff3be659d9 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 16 Oct 2024 20:14:33 -0400 Subject: Organizational pass on endpoints and routes. --- src/channel/routes/test/on_send.rs | 94 -------------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 src/channel/routes/test/on_send.rs (limited to 'src/channel/routes/test/on_send.rs') diff --git a/src/channel/routes/test/on_send.rs b/src/channel/routes/test/on_send.rs deleted file mode 100644 index 293cc56..0000000 --- a/src/channel/routes/test/on_send.rs +++ /dev/null @@ -1,94 +0,0 @@ -use axum::extract::{Json, Path, State}; -use futures::stream::StreamExt; - -use crate::{ - channel, - channel::routes, - event::{self, Sequenced}, - message::{self, app::SendError}, - test::fixtures::{self, future::Immediately as _}, -}; - -#[tokio::test] -async fn messages_in_order() { - // Set up the environment - - let app = fixtures::scratch_app().await; - let sender = fixtures::login::create(&app, &fixtures::now()).await; - let channel = fixtures::channel::create(&app, &fixtures::now()).await; - - // Call the endpoint (twice) - - let requests = vec![ - (fixtures::now(), fixtures::message::propose()), - (fixtures::now(), fixtures::message::propose()), - ]; - - for (sent_at, body) in &requests { - let request = routes::SendRequest { body: body.clone() }; - - routes::on_send( - State(app.clone()), - Path(channel.id.clone()), - sent_at.clone(), - sender.clone(), - Json(request.clone()), - ) - .await - .expect("sending to a valid channel"); - } - - // Verify the semantics - - let events = app - .events() - .subscribe(None) - .await - .expect("subscribing to a valid channel") - .filter(fixtures::filter::messages()) - .take(requests.len()); - - let events = events.collect::>().immediately().await; - - for ((sent_at, message), event) in requests.into_iter().zip(events) { - assert_eq!(*sent_at, event.at()); - assert!(matches!( - event, - event::Event::Message(message::Event::Sent(event)) - if event.message.sender == sender.id - && event.message.body == message - )); - } -} - -#[tokio::test] -async fn nonexistent_channel() { - // Set up the environment - - let app = fixtures::scratch_app().await; - let login = fixtures::login::create(&app, &fixtures::now()).await; - - // Call the endpoint - - let sent_at = fixtures::now(); - let channel = channel::Id::generate(); - let request = routes::SendRequest { - body: fixtures::message::propose(), - }; - let routes::SendErrorResponse(error) = routes::on_send( - State(app), - Path(channel.clone()), - sent_at, - login, - Json(request), - ) - .await - .expect_err("sending to a nonexistent channel"); - - // Verify the structure of the response - - assert!(matches!( - error, - SendError::ChannelNotFound(error_channel) if channel == error_channel - )); -} -- cgit v1.2.3