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

Code before:
    let index = server.index("test");
    let (response, code) = index.create(Some("primary")).await;

    assert_eq!(code, 201);
    assert_eq!(response["uid"], "test");
    assert_eq!(response["name"], "test");
    assert!(response.get("createdAt").is_some());
    assert!(response.get("updatedAt").is_some());
    //assert_eq!(response["createdAt"], response["updatedAt"]);
    assert_eq!(response["primaryKey"], "primary");
    assert_eq!(response.as_object().unwrap().len(), 5);
}

#[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 app = test::init_service(create_app!(
        &server.service.meilisearch,
        true,
        &server.service.options
    ))
    .await;

    let req = test::TestRequest::post()
        .uri("/indexes/movies/documents?primaryKey=title")
        .set_payload(document.to_string())
        .insert_header(("content-type", "application/json"))
        .to_request();

    let res = test::call_service(&app, req).await;
    assert_eq!(res.status(), 202);

    let index = server.index("movies");
    index.wait_update_id(0).await;

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

// 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;

    assert_eq!(code, 201);

Review comment (suggestion):
can  you use:
```
let server = Server::new();
let index = server.index("test");
index.add_documents(...);
```
instead please? :)

Code after:

    assert_eq!(code, 201);
    assert_eq!(response["uid"], "test");
    assert_eq!(response["name"], "test");
    assert!(response.get("createdAt").is_some());
    assert!(response.get("updatedAt").is_some());
    //assert_eq!(response["createdAt"], response["updatedAt"]);
    assert_eq!(response["primaryKey"], "primary");
    assert_eq!(response.as_object().unwrap().len(), 5);
}

#[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_update_id(0).await;

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

// 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;

    assert_eq!(code, 201);

    let (_response, code) = index.create(Some("primary")).await;
    assert_eq!(code, 400);
}

#[actix_rt::test]
async fn create_with_invalid_index_uid() {
    let server = Server::new().await;
    let index = server.index("test test#!");
    let (_, code) = index.create(None).await;
    assert_eq!(code, 400);
}

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