summaryrefslogtreecommitdiff
path: root/src/channel/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel/routes')
-rw-r--r--src/channel/routes/channel/delete.rs23
-rw-r--r--src/channel/routes/channel/test/delete.rs17
-rw-r--r--src/channel/routes/channel/test/post.rs29
-rw-r--r--src/channel/routes/test.rs15
4 files changed, 42 insertions, 42 deletions
diff --git a/src/channel/routes/channel/delete.rs b/src/channel/routes/channel/delete.rs
index 91eb506..2d2b5f1 100644
--- a/src/channel/routes/channel/delete.rs
+++ b/src/channel/routes/channel/delete.rs
@@ -1,12 +1,12 @@
use axum::{
- extract::{Path, State},
+ extract::{Json, Path, State},
http::StatusCode,
- response::{IntoResponse, Response},
+ response::{self, IntoResponse},
};
use crate::{
app::App,
- channel::app,
+ channel::{self, app},
clock::RequestedAt,
error::{Internal, NotFound},
token::extract::Identity,
@@ -17,10 +17,21 @@ pub async fn handler(
Path(channel): Path<super::PathInfo>,
RequestedAt(deleted_at): RequestedAt,
_: Identity,
-) -> Result<StatusCode, Error> {
+) -> Result<Response, Error> {
app.channels().delete(&channel, &deleted_at).await?;
- Ok(StatusCode::ACCEPTED)
+ Ok(Response { id: channel })
+}
+
+#[derive(Debug, serde::Serialize)]
+pub struct Response {
+ pub id: channel::Id,
+}
+
+impl IntoResponse for Response {
+ fn into_response(self) -> response::Response {
+ (StatusCode::ACCEPTED, Json(self)).into_response()
+ }
}
#[derive(Debug, thiserror::Error)]
@@ -28,7 +39,7 @@ pub async fn handler(
pub struct Error(#[from] pub app::Error);
impl IntoResponse for Error {
- fn into_response(self) -> Response {
+ fn into_response(self) -> response::Response {
let Self(error) = self;
#[allow(clippy::match_wildcard_for_single_variants)]
match error {
diff --git a/src/channel/routes/channel/test/delete.rs b/src/channel/routes/channel/test/delete.rs
index e9af12f..0371b0a 100644
--- a/src/channel/routes/channel/test/delete.rs
+++ b/src/channel/routes/channel/test/delete.rs
@@ -1,7 +1,4 @@
-use axum::{
- extract::{Path, State},
- http::StatusCode,
-};
+use axum::extract::{Path, State};
use crate::{
channel::{app, routes::channel::delete},
@@ -9,7 +6,7 @@ use crate::{
};
#[tokio::test]
-pub async fn delete_channel() {
+pub async fn valid_channel() {
// Set up the environment
let app = fixtures::scratch_app().await;
@@ -29,7 +26,7 @@ pub async fn delete_channel() {
// Verify the response
- assert_eq!(response, StatusCode::ACCEPTED);
+ assert_eq!(channel.id, response.id);
// Verify the semantics
@@ -38,7 +35,7 @@ pub async fn delete_channel() {
}
#[tokio::test]
-pub async fn delete_invalid_channel_id() {
+pub async fn invalid_channel_id() {
// Set up the environment
let app = fixtures::scratch_app().await;
@@ -62,7 +59,7 @@ pub async fn delete_invalid_channel_id() {
}
#[tokio::test]
-pub async fn delete_deleted() {
+pub async fn channel_deleted() {
// Set up the environment
let app = fixtures::scratch_app().await;
@@ -91,7 +88,7 @@ pub async fn delete_deleted() {
}
#[tokio::test]
-pub async fn delete_expired() {
+pub async fn channel_expired() {
// Set up the environment
let app = fixtures::scratch_app().await;
@@ -120,7 +117,7 @@ pub async fn delete_expired() {
}
#[tokio::test]
-pub async fn delete_purged() {
+pub async fn channel_purged() {
// Set up the environment
let app = fixtures::scratch_app().await;
diff --git a/src/channel/routes/channel/test/post.rs b/src/channel/routes/channel/test/post.rs
index 67e7d36..111a703 100644
--- a/src/channel/routes/channel/test/post.rs
+++ b/src/channel/routes/channel/test/post.rs
@@ -1,11 +1,11 @@
use axum::extract::{Json, Path, State};
-use futures::stream::StreamExt;
+use futures::stream::{self, StreamExt as _};
use crate::{
channel::{self, routes::channel::post},
event::Sequenced,
- message::{self, app::SendError},
- test::fixtures::{self, future::Immediately as _},
+ message::app::SendError,
+ test::fixtures::{self, future::Expect as _},
};
#[tokio::test]
@@ -39,24 +39,23 @@ async fn messages_in_order() {
// Verify the semantics
- let events = app
+ let mut events = app
.events()
.subscribe(None)
.await
.expect("subscribing to a valid channel succeeds")
- .filter_map(fixtures::message::events)
- .take(requests.len());
+ .filter_map(fixtures::event::message)
+ .filter_map(fixtures::event::message::sent)
+ .zip(stream::iter(requests));
- let events = events.collect::<Vec<_>>().immediately().await;
-
- for ((sent_at, message), event) in requests.into_iter().zip(events) {
+ while let Some((event, (sent_at, body))) = events
+ .next()
+ .expect_ready("an event should be ready for each message")
+ .await
+ {
assert_eq!(*sent_at, event.at());
- assert!(matches!(
- event,
- message::Event::Sent(event)
- if event.message.sender == sender.login.id
- && event.message.body == message
- ));
+ assert_eq!(sender.login.id, event.message.sender);
+ assert_eq!(body, event.message.body);
}
}
diff --git a/src/channel/routes/test.rs b/src/channel/routes/test.rs
index 216eba1..10b1e8d 100644
--- a/src/channel/routes/test.rs
+++ b/src/channel/routes/test.rs
@@ -7,7 +7,7 @@ use super::post;
use crate::{
channel::app,
name::Name,
- test::fixtures::{self, future::Immediately as _},
+ test::fixtures::{self, future::Expect as _},
};
#[tokio::test]
@@ -39,7 +39,6 @@ async fn new_channel() {
.channels()
.get(&response.id)
.await
- .expect("searching for channels by ID never fails")
.expect("the newly-created channel exists");
assert_eq!(response, channel);
@@ -48,15 +47,11 @@ async fn new_channel() {
.subscribe(None)
.await
.expect("subscribing never fails")
- .filter_map(fixtures::channel::events)
- .filter_map(fixtures::channel::created)
+ .filter_map(fixtures::event::channel)
+ .filter_map(fixtures::event::channel::created)
.filter(|event| future::ready(event.channel == response));
- let event = events
- .next()
- .immediately()
- .await
- .expect("creation event published");
+ let event = events.next().expect_some("creation event published").await;
assert_eq!(event.channel, response);
}
@@ -165,7 +160,6 @@ async fn name_reusable_after_delete() {
.channels()
.get(&response.id)
.await
- .expect("searching for channels by ID never fails")
.expect("the newly-created channel exists");
assert_eq!(response, channel);
}
@@ -215,7 +209,6 @@ async fn name_reusable_after_expiry() {
.channels()
.get(&response.id)
.await
- .expect("searching for channels by ID never fails")
.expect("the newly-created channel exists");
assert_eq!(response, channel);
}