mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-04 19:56:30 +00:00
Update tests
This commit is contained in:
@ -143,6 +143,7 @@ async fn get_webhooks(
|
|||||||
pub struct PatchWebhooksAnalytics {
|
pub struct PatchWebhooksAnalytics {
|
||||||
patch_webhooks_count: usize,
|
patch_webhooks_count: usize,
|
||||||
post_webhook_count: usize,
|
post_webhook_count: usize,
|
||||||
|
delete_webhook_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PatchWebhooksAnalytics {
|
impl PatchWebhooksAnalytics {
|
||||||
@ -153,6 +154,10 @@ impl PatchWebhooksAnalytics {
|
|||||||
pub fn post_webhook() -> Self {
|
pub fn post_webhook() -> Self {
|
||||||
PatchWebhooksAnalytics { post_webhook_count: 1, ..Default::default() }
|
PatchWebhooksAnalytics { post_webhook_count: 1, ..Default::default() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_webhook() -> Self {
|
||||||
|
PatchWebhooksAnalytics { delete_webhook_count: 1, ..Default::default() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Aggregate for PatchWebhooksAnalytics {
|
impl Aggregate for PatchWebhooksAnalytics {
|
||||||
@ -164,6 +169,7 @@ impl Aggregate for PatchWebhooksAnalytics {
|
|||||||
Box::new(PatchWebhooksAnalytics {
|
Box::new(PatchWebhooksAnalytics {
|
||||||
patch_webhooks_count: self.patch_webhooks_count + new.patch_webhooks_count,
|
patch_webhooks_count: self.patch_webhooks_count + new.patch_webhooks_count,
|
||||||
post_webhook_count: self.post_webhook_count + new.post_webhook_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))?;
|
let webhook = webhooks.webhooks.remove(&uuid).ok_or(WebhooksError::WebhookNotFound(uuid))?;
|
||||||
|
|
||||||
debug!(returns = ?webhook, "Get webhook {}", uuid);
|
|
||||||
Ok(HttpResponse::Ok().json(WebhookWithMetadata {
|
Ok(HttpResponse::Ok().json(WebhookWithMetadata {
|
||||||
uuid,
|
uuid,
|
||||||
is_editable: uuid != Uuid::nil(),
|
is_editable: uuid != Uuid::nil(),
|
||||||
@ -401,7 +406,6 @@ async fn post_webhook(
|
|||||||
|
|
||||||
analytics.publish(PatchWebhooksAnalytics::post_webhook(), &req);
|
analytics.publish(PatchWebhooksAnalytics::post_webhook(), &req);
|
||||||
|
|
||||||
debug!(returns = ?webhook, "Created webhook {}", uuid);
|
|
||||||
Ok(HttpResponse::Created().json(WebhookWithMetadata { uuid, is_editable: true, webhook }))
|
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)])) },
|
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())
|
Ok(HttpResponse::NoContent().finish())
|
||||||
}
|
}
|
||||||
|
@ -195,6 +195,11 @@ impl Server<Owned> {
|
|||||||
self.service.get(url).await
|
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) {
|
pub async fn get_metrics(&self) -> (Value, StatusCode) {
|
||||||
self.service.get("/metrics").await
|
self.service.get("/metrics").await
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ async fn over_limits() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::test]
|
#[actix_web::test]
|
||||||
async fn post_and_get() {
|
async fn post_get_delete() {
|
||||||
let server = Server::new().await;
|
let server = Server::new().await;
|
||||||
|
|
||||||
let (value, code) = server
|
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");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user