fix delete-batch route; #493

This commit is contained in:
qdequele 2020-03-04 15:06:16 +01:00 committed by Quentin de Quelen
parent 81ce90e57f
commit 54c675e195
3 changed files with 37 additions and 6 deletions

View File

@ -65,7 +65,7 @@ pub fn load_routes(app: &mut tide::Server<Data>) {
.get(|ctx| into_response(document::get_document(ctx)))
.delete(|ctx| into_response(document::delete_document(ctx)));
app.at("/indexes/:index/documents/:identifier/delete-batch")
app.at("/indexes/:index/documents/delete-batch")
.post(|ctx| into_response(document::delete_multiple_documents(ctx)));
app.at("/indexes/:index/settings")

View File

@ -58,6 +58,7 @@ impl Server {
let response: Value = serde_json::from_slice(&buf).unwrap();
if response["status"] == "processed" {
eprintln!("{:?}", response);
return;
}
block_on(sleep(Duration::from_secs(1)));
@ -219,14 +220,14 @@ impl Server {
self.delete_request_async(&url);
}
pub fn get_document(&mut self, document_id: u64) -> (Value, StatusCode) {
let url = format!("/indexes/{}/documents/{}", self.uid, document_id);
pub fn get_document(&mut self, document_id: impl ToString) -> (Value, StatusCode) {
let url = format!("/indexes/{}/documents/{}", self.uid, document_id.to_string());
self.get_request(&url)
}
pub fn delete_document(&mut self, document_id: u64) -> (Value, StatusCode) {
let url = format!("/indexes/{}/documents/{}", self.uid, document_id);
self.delete_request(&url)
pub fn delete_document(&mut self, document_id: impl ToString) -> (Value, StatusCode) {
let url = format!("/indexes/{}/documents/{}", self.uid, document_id.to_string());
self.delete_request_async(&url)
}
pub fn delete_multiple_documents(&mut self, body: Value) {

View File

@ -0,0 +1,30 @@
mod common;
#[test]
fn delete() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
let (_response, status_code) = server.get_document(419704);
assert_eq!(status_code, 200);
server.delete_document(419704);
let (_response, status_code) = server.get_document(419704);
assert_eq!(status_code, 404);
}
#[test]
fn delete_batch() {
let mut server = common::Server::with_uid("movies");
server.populate_movies();
let (_response, status_code) = server.get_document(419704);
assert_eq!(status_code, 200);
let body = serde_json::json!([419704,512200,181812]);
server.delete_multiple_documents(body);
let (_response, status_code) = server.get_document(419704);
assert_eq!(status_code, 404);
}