Repository: meilisearch/meilisearch
File: meilisearch/tests/index/create_index.rs (Rust)

Code before:
}

#[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;

    assert_eq!(code, 202);

    assert_eq!(response["status"], "enqueued");

    let response = index.wait_task(response.uid()).await;

    assert_eq!(response["status"], "succeeded");
    assert_eq!(response["type"], "indexCreation");
    assert_eq!(response["details"]["primaryKey"], "primary");
}

#[actix_rt::test]
async fn create_index_with_invalid_primary_key() {
    let document = json!([ { "id": 2, "title": "Pride and Prejudice" } ]);

    let server = Server::new().await;
    let index = server.index("movies");
    let (response, code) = index.add_documents(document, Some("title")).await;
    assert_eq!(code, 202);

    index.wait_task(response.uid()).await;

    let (response, code) = index.get().await;
    assert_eq!(code, 200);
    assert_eq!(response["primaryKey"], json!(null));
}

#[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");

    let (task1, _) = index1.create(None).await;
    let (task2, _) = index2.create(None).await;
    let (task3, _) = index3.create(None).await;

    index1.wait_task(task1.uid()).await.succeeded();
    index2.wait_task(task2.uid()).await.succeeded();
    index3.wait_task(task3.uid()).await.succeeded();


Review comment (suggestion):
Same as above, we can use a shared server + unique index:
```rust
    let server = Server::new_shared().await;
    let index = server.unique_index();
    let (response, code) = index.add_documents(document, Some("title")).await;
```

Code after:

#[actix_rt::test]
async fn create_index_with_primary_key() {
    let server = Server::new_shared();
    let index = server.unique_index();
    let (response, code) = index.create(Some("primary")).await;

    assert_eq!(code, 202);

    assert_eq!(response["status"], "enqueued");

    let response = index.wait_task(response.uid()).await;

    assert_eq!(response["status"], "succeeded");
    assert_eq!(response["type"], "indexCreation");
    assert_eq!(response["details"]["primaryKey"], "primary");
}

#[actix_rt::test]
async fn create_index_with_invalid_primary_key() {
    let documents = json!([ { "id": 2, "title": "Pride and Prejudice" } ]);

    let server = Server::new_shared();
    let index = server.unique_index();
    let (response, code) = index.add_documents(documents, Some("title")).await;
    assert_eq!(code, 202);

    index.wait_task(response.uid()).await;

    let (response, code) = index.get().await;
    assert_eq!(code, 200);
    assert_eq!(response["primaryKey"], json!(null));

    let documents = json!([ { "id": "e".repeat(513) } ]);

    let (response, code) = index.add_documents(documents, Some("id")).await;
    assert_eq!(code, 202);

    index.wait_task(response.uid()).await;

    let (response, code) = index.get().await;
    assert_eq!(code, 200);
    assert_eq!(response["primaryKey"], json!(null));
}

#[actix_rt::test]
async fn test_create_multiple_indexes() {
    let server = Server::new_shared();
    let index1 = server.unique_index();
    let index2 = server.unique_index();
    let index3 = server.unique_index();