Update tests

This commit is contained in:
Mubelotix
2025-07-31 12:33:34 +02:00
parent 29fb4d5e2a
commit ad68245186
2 changed files with 49 additions and 1 deletions

View File

@ -186,6 +186,15 @@ impl Server<Owned> {
self.service.patch("/webhooks", value).await
}
pub async fn create_webhook(&self, value: Value) -> (Value, StatusCode) {
self.service.post("/webhooks", value).await
}
pub async fn get_webhook(&self, uuid: impl AsRef<str>) -> (Value, StatusCode) {
let url = format!("/webhooks/{}", uuid.as_ref());
self.service.get(url).await
}
pub async fn get_metrics(&self) -> (Value, StatusCode) {
self.service.get("/metrics").await
}

View File

@ -236,7 +236,9 @@ async fn over_limits() {
// Too many webhooks
for _ in 0..20 {
let (_value, code) = server
.set_webhooks(json!({ "webhooks": { Uuid::new_v4(): { "url": "http://localhost:8080" } } }))
.set_webhooks(
json!({ "webhooks": { Uuid::new_v4(): { "url": "http://localhost:8080" } } }),
)
.await;
snapshot!(code, @"200 OK");
}
@ -284,3 +286,40 @@ async fn over_limits() {
}
"#);
}
#[actix_web::test]
async fn post_and_get() {
let server = Server::new().await;
let (value, code) = server
.create_webhook(json!({
"url": "https://example.com/hook",
"headers": { "authorization": "TOKEN" }
}))
.await;
snapshot!(code, @"201 Created");
snapshot!(json_string!(value, { ".uuid" => "[uuid]" }), @r#"
{
"uuid": "[uuid]",
"isEditable": true,
"url": "https://example.com/hook",
"headers": {
"authorization": "TOKEN"
}
}
"#);
let uuid = value.get("uuid").unwrap().as_str().unwrap();
let (value, code) = server.get_webhook(uuid).await;
snapshot!(code, @"200 OK");
snapshot!(json_string!(value, { ".uuid" => "[uuid]" }), @r#"
{
"uuid": "[uuid]",
"isEditable": true,
"url": "https://example.com/hook",
"headers": {
"authorization": "TOKEN"
}
}
"#);
}