diff options
Diffstat (limited to 'src/channel/routes/test')
| -rw-r--r-- | src/channel/routes/test/mod.rs | 2 | ||||
| -rw-r--r-- | src/channel/routes/test/on_create.rs | 88 | ||||
| -rw-r--r-- | src/channel/routes/test/on_send.rs | 94 |
3 files changed, 0 insertions, 184 deletions
diff --git a/src/channel/routes/test/mod.rs b/src/channel/routes/test/mod.rs deleted file mode 100644 index 3e5aa17..0000000 --- a/src/channel/routes/test/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod on_create; -mod on_send; diff --git a/src/channel/routes/test/on_create.rs b/src/channel/routes/test/on_create.rs deleted file mode 100644 index eeecc7f..0000000 --- a/src/channel/routes/test/on_create.rs +++ /dev/null @@ -1,88 +0,0 @@ -use axum::extract::{Json, State}; -use futures::stream::StreamExt as _; - -use crate::{ - channel::{self, app, routes}, - event, - test::fixtures::{self, future::Immediately as _}, -}; - -#[tokio::test] -async fn new_channel() { - // Set up the environment - - let app = fixtures::scratch_app().await; - let creator = fixtures::login::create(&app, &fixtures::now()).await; - - // Call the endpoint - - let name = fixtures::channel::propose(); - let request = routes::CreateRequest { name }; - let Json(response_channel) = routes::on_create( - State(app.clone()), - creator, - fixtures::now(), - Json(request.clone()), - ) - .await - .expect("new channel in an empty app"); - - // Verify the structure of the response - - assert_eq!(request.name, response_channel.name); - - // Verify the semantics - - let snapshot = app.boot().snapshot().await.expect("boot always succeeds"); - assert!(snapshot - .channels - .iter() - .any(|channel| channel.name == response_channel.name && channel.id == response_channel.id)); - - let mut events = app - .events() - .subscribe(None) - .await - .expect("subscribing never fails") - .filter(fixtures::filter::created()); - - let event = events - .next() - .immediately() - .await - .expect("creation event published"); - - assert!(matches!( - event, - event::Event::Channel(channel::Event::Created(event)) - if event.channel == response_channel - )); -} - -#[tokio::test] -async fn duplicate_name() { - // Set up the environment - - let app = fixtures::scratch_app().await; - let creator = fixtures::login::create(&app, &fixtures::now()).await; - let channel = fixtures::channel::create(&app, &fixtures::now()).await; - - // Call the endpoint - - let request = routes::CreateRequest { name: channel.name }; - let routes::CreateError(error) = routes::on_create( - State(app.clone()), - creator, - fixtures::now(), - Json(request.clone()), - ) - .await - .expect_err("duplicate channel name"); - - // Verify the structure of the response - - assert!(matches!( - error, - app::CreateError::DuplicateName(name) if request.name == name - )); -} 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::<Vec<_>>().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 - )); -} |
