Update tests

This commit is contained in:
Mubelotix
2025-07-31 12:44:35 +02:00
parent 94733a4a18
commit 9e43f7b419
3 changed files with 19 additions and 5 deletions

View File

@ -143,6 +143,7 @@ async fn get_webhooks(
pub struct PatchWebhooksAnalytics {
patch_webhooks_count: usize,
post_webhook_count: usize,
delete_webhook_count: usize,
}
impl PatchWebhooksAnalytics {
@ -153,6 +154,10 @@ impl PatchWebhooksAnalytics {
pub fn post_webhook() -> Self {
PatchWebhooksAnalytics { post_webhook_count: 1, ..Default::default() }
}
pub fn delete_webhook() -> Self {
PatchWebhooksAnalytics { delete_webhook_count: 1, ..Default::default() }
}
}
impl Aggregate for PatchWebhooksAnalytics {
@ -164,6 +169,7 @@ impl Aggregate for PatchWebhooksAnalytics {
Box::new(PatchWebhooksAnalytics {
patch_webhooks_count: self.patch_webhooks_count + new.patch_webhooks_count,
post_webhook_count: self.post_webhook_count + new.post_webhook_count,
delete_webhook_count: self.delete_webhook_count + new.delete_webhook_count,
})
}
@ -356,7 +362,6 @@ async fn get_webhook(
let webhook = webhooks.webhooks.remove(&uuid).ok_or(WebhooksError::WebhookNotFound(uuid))?;
debug!(returns = ?webhook, "Get webhook {}", uuid);
Ok(HttpResponse::Ok().json(WebhookWithMetadata {
uuid,
is_editable: uuid != Uuid::nil(),
@ -401,7 +406,6 @@ async fn post_webhook(
analytics.publish(PatchWebhooksAnalytics::post_webhook(), &req);
debug!(returns = ?webhook, "Created webhook {}", uuid);
Ok(HttpResponse::Created().json(WebhookWithMetadata { uuid, is_editable: true, webhook }))
}
@ -437,8 +441,7 @@ async fn delete_webhook(
WebhooksSettings { webhooks: Setting::Set(BTreeMap::from([(uuid, Setting::Reset)])) },
)?;
analytics.publish(PatchWebhooksAnalytics::patch_webhooks(), &req);
analytics.publish(PatchWebhooksAnalytics::delete_webhook(), &req);
debug!("Deleted webhook {}", uuid);
Ok(HttpResponse::NoContent().finish())
}

View File

@ -195,6 +195,11 @@ impl Server<Owned> {
self.service.get(url).await
}
pub async fn delete_webhook(&self, uuid: impl AsRef<str>) -> (Value, StatusCode) {
let url = format!("/webhooks/{}", uuid.as_ref());
self.service.delete(url).await
}
pub async fn get_metrics(&self) -> (Value, StatusCode) {
self.service.get("/metrics").await
}

View File

@ -288,7 +288,7 @@ async fn over_limits() {
}
#[actix_web::test]
async fn post_and_get() {
async fn post_get_delete() {
let server = Server::new().await;
let (value, code) = server
@ -322,4 +322,10 @@ async fn post_and_get() {
}
}
"#);
let (_value, code) = server.delete_webhook(uuid).await;
snapshot!(code, @"204 No Content");
let (_value, code) = server.get_webhook(uuid).await;
snapshot!(code, @"404 Not Found");
}