summaryrefslogtreecommitdiff
path: root/src/channel/routes/test/on_create.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel/routes/test/on_create.rs')
-rw-r--r--src/channel/routes/test/on_create.rs88
1 files changed, 0 insertions, 88 deletions
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
- ));
-}