meilisearch/meilisearch-http/tests/index/create_index.rs

75 lines
2.3 KiB
Rust
Raw Normal View History

2021-02-19 02:50:52 +08:00
use crate::common::Server;
use serde_json::Value;
#[actix_rt::test]
async fn create_index_no_primary_key() {
let server = Server::new().await;
let index = server.index("test");
let (response, code) = index.create(None).await;
2021-07-05 17:21:02 +08:00
assert_eq!(code, 201);
2021-02-19 02:50:52 +08:00
assert_eq!(response["uid"], "test");
2021-03-16 01:38:13 +08:00
assert_eq!(response["name"], "test");
2021-02-19 02:50:52 +08:00
assert!(response.get("createdAt").is_some());
assert!(response.get("updatedAt").is_some());
assert_eq!(response["createdAt"], response["updatedAt"]);
assert_eq!(response["primaryKey"], Value::Null);
2021-03-16 01:38:13 +08:00
assert_eq!(response.as_object().unwrap().len(), 5);
2021-02-19 02:50:52 +08:00
}
#[actix_rt::test]
async fn create_index_with_primary_key() {
let server = Server::new().await;
let index = server.index("test");
let (response, code) = index.create(Some("primary")).await;
2021-07-05 17:21:02 +08:00
assert_eq!(code, 201);
2021-02-19 02:50:52 +08:00
assert_eq!(response["uid"], "test");
2021-03-16 01:38:13 +08:00
assert_eq!(response["name"], "test");
2021-02-19 02:50:52 +08:00
assert!(response.get("createdAt").is_some());
assert!(response.get("updatedAt").is_some());
2021-03-12 21:48:43 +08:00
//assert_eq!(response["createdAt"], response["updatedAt"]);
2021-02-19 02:50:52 +08:00
assert_eq!(response["primaryKey"], "primary");
2021-03-16 01:38:13 +08:00
assert_eq!(response.as_object().unwrap().len(), 5);
2021-02-19 02:50:52 +08:00
}
// TODO: partial test since we are testing error, amd error is not yet fully implemented in
// transplant
#[actix_rt::test]
async fn create_existing_index() {
let server = Server::new().await;
let index = server.index("test");
let (_, code) = index.create(Some("primary")).await;
2021-07-05 17:21:02 +08:00
assert_eq!(code, 201);
2021-02-19 02:50:52 +08:00
let (_response, code) = index.create(Some("primary")).await;
assert_eq!(code, 400);
}
2021-02-19 02:52:00 +08:00
#[actix_rt::test]
async fn create_with_invalid_index_uid() {
let server = Server::new().await;
2021-03-10 21:43:10 +08:00
let index = server.index("test test#!");
2021-02-19 02:52:00 +08:00
let (_, code) = index.create(None).await;
assert_eq!(code, 400);
}
2021-02-19 03:32:34 +08:00
#[actix_rt::test]
async fn test_create_multiple_indexes() {
let server = Server::new().await;
let index1 = server.index("test1");
let index2 = server.index("test2");
let index3 = server.index("test3");
let index4 = server.index("test4");
index1.create(None).await;
index2.create(None).await;
index3.create(None).await;
assert_eq!(index1.get().await.1, 200);
assert_eq!(index2.get().await.1, 200);
assert_eq!(index3.get().await.1, 200);
2021-06-16 04:21:52 +08:00
assert_eq!(index4.get().await.1, 404);
2021-02-19 03:32:34 +08:00
}