From 5367d8f05aea361fd9279c7aeb4fb1156e497dda Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 16 Feb 2023 14:38:03 +0100 Subject: [PATCH] add two tests on the indexing of csvs --- meilisearch/tests/documents/add_documents.rs | 127 +++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/meilisearch/tests/documents/add_documents.rs b/meilisearch/tests/documents/add_documents.rs index e553dcacd..56c0ffac2 100644 --- a/meilisearch/tests/documents/add_documents.rs +++ b/meilisearch/tests/documents/add_documents.rs @@ -216,6 +216,133 @@ async fn add_single_document_with_every_encoding() { } } +#[actix_rt::test] +async fn add_csv_document() { + let server = Server::new().await; + let index = server.index("pets"); + + let document = "#id,name,race +0,jean,bernese mountain +1,jorts,orange cat"; + + let (response, code) = index.raw_update_documents(document, Some("text/csv"), "").await; + snapshot!(code, @"202 Accepted"); + snapshot!(json_string!(response, { ".enqueuedAt" => "[date]" }), @r###" + { + "taskUid": 0, + "indexUid": "pets", + "status": "enqueued", + "type": "documentAdditionOrUpdate", + "enqueuedAt": "[date]" + } + "###); + let response = index.wait_task(response["taskUid"].as_u64().unwrap()).await; + snapshot!(json_string!(response, { ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }), @r###" + { + "uid": 0, + "indexUid": "pets", + "status": "succeeded", + "type": "documentAdditionOrUpdate", + "canceledBy": null, + "details": { + "receivedDocuments": 2, + "indexedDocuments": 2 + }, + "error": null, + "duration": "[duration]", + "enqueuedAt": "[date]", + "startedAt": "[date]", + "finishedAt": "[date]" + } + "###); + + let (documents, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; + snapshot!(code, @"200 OK"); + snapshot!(json_string!(documents), @r###" + { + "results": [ + { + "#id": "0", + "name": "jean", + "race": "bernese mountain" + }, + { + "#id": "1", + "name": "jorts", + "race": "orange cat" + } + ], + "offset": 0, + "limit": 20, + "total": 2 + } + "###); +} + +#[actix_rt::test] +async fn add_csv_document_with_custom_delimiter() { + let server = Server::new().await; + let index = server.index("pets"); + + let document = "#id|name|race +0|jean|bernese mountain +1|jorts|orange cat"; + + let (response, code) = + index.raw_update_documents(document, Some("text/csv"), "?csvDelimiter=|").await; + snapshot!(code, @"202 Accepted"); + snapshot!(json_string!(response, { ".enqueuedAt" => "[date]" }), @r###" + { + "taskUid": 0, + "indexUid": "pets", + "status": "enqueued", + "type": "documentAdditionOrUpdate", + "enqueuedAt": "[date]" + } + "###); + let response = index.wait_task(response["taskUid"].as_u64().unwrap()).await; + snapshot!(json_string!(response, { ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]", ".duration" => "[duration]" }), @r###" + { + "uid": 0, + "indexUid": "pets", + "status": "succeeded", + "type": "documentAdditionOrUpdate", + "canceledBy": null, + "details": { + "receivedDocuments": 2, + "indexedDocuments": 2 + }, + "error": null, + "duration": "[duration]", + "enqueuedAt": "[date]", + "startedAt": "[date]", + "finishedAt": "[date]" + } + "###); + + let (documents, code) = index.get_all_documents(GetAllDocumentsOptions::default()).await; + snapshot!(code, @"200 OK"); + snapshot!(json_string!(documents), @r###" + { + "results": [ + { + "#id": "0", + "name": "jean", + "race": "bernese mountain" + }, + { + "#id": "1", + "name": "jorts", + "race": "orange cat" + } + ], + "offset": 0, + "limit": 20, + "total": 2 + } + "###); +} + /// any other content-type is must be refused #[actix_rt::test] async fn error_add_documents_test_bad_content_types() {