summaryrefslogtreecommitdiff
path: root/src/channel/routes/test/on_create.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-09-19 01:25:31 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-09-20 23:55:22 -0400
commite5f72711c5a17c5db24e209b14f82d426eceb86e (patch)
tree04865172284c86549dd08d700c21a29c36f54005 /src/channel/routes/test/on_create.rs
parent0079624488af334817f58e30dbc676d3adde8de6 (diff)
Write tests.
Diffstat (limited to 'src/channel/routes/test/on_create.rs')
-rw-r--r--src/channel/routes/test/on_create.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/channel/routes/test/on_create.rs b/src/channel/routes/test/on_create.rs
new file mode 100644
index 0000000..df23deb
--- /dev/null
+++ b/src/channel/routes/test/on_create.rs
@@ -0,0 +1,58 @@
+use axum::extract::{Json, State};
+
+use crate::{
+ channel::{app, routes},
+ test::fixtures,
+};
+
+#[tokio::test]
+async fn new_channel() {
+ // Set up the environment
+
+ let app = fixtures::scratch_app().await;
+ let creator = fixtures::login::create(&app).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, 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 channels = app.channels().all().await.expect("always succeeds");
+
+ assert!(channels.contains(&response_channel));
+}
+
+#[tokio::test]
+async fn duplicate_name() {
+ // Set up the environment
+
+ let app = fixtures::scratch_app().await;
+ let creator = fixtures::login::create(&app).await;
+ let channel = fixtures::channel::create(&app).await;
+
+ // Call the endpoint
+
+ let request = routes::CreateRequest { name: channel.name };
+ let routes::CreateError(error) =
+ routes::on_create(State(app.clone()), creator, Json(request.clone()))
+ .await
+ .expect_err("duplicate channel name");
+
+ // Verify the structure of the response
+
+ fixtures::error::expected!(
+ error,
+ app::CreateError::DuplicateName(name),
+ assert_eq!(request.name, name),
+ );
+}