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

Code before:
    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();

    assert_eq!(index1.get().await.1, 200);
    assert_eq!(index2.get().await.1, 200);
    assert_eq!(index3.get().await.1, 200);
    assert_eq!(index4.get().await.1, 404);
}

#[actix_rt::test]
async fn error_create_existing_index() {
    let server = Server::new().await;
    let index = server.index("test");
    let (_, code) = index.create(Some("primary")).await;

    assert_eq!(code, 202);

    let (task, _) = index.create(Some("primary")).await;

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

    let expected_response = json!({
        "message": "Index `test` already exists.",
        "code": "index_already_exists",
        "type": "invalid_request",
        "link":"https://docs.meilisearch.com/errors#index_already_exists"
    });

    assert_eq!(response["error"], expected_response);
}

#[actix_rt::test]
async fn error_create_with_invalid_index_uid() {

Review comment (suggestion):
I cannot select the right place but it’s the same as above, we can use a shared server + 4 unique index

Code after:
    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();
    let index4 = server.unique_index();

    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();

    assert_eq!(index1.get().await.1, 200);
    assert_eq!(index2.get().await.1, 200);
    assert_eq!(index3.get().await.1, 200);
    assert_eq!(index4.get().await.1, 404);
}

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

    assert_eq!(code, 202);

    let (task, _) = index.create(Some("primary")).await;

    let response = index.wait_task(task.uid()).await;
    let msg = format!(
        "Index `{}` already exists.",
        task["indexUid"].as_str().expect("indexUid should exist").trim_matches('"')