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

Code before:
async fn no_index_return_empty_list() {
    let server = Server::new_shared();
    let (response, code) = server.list_indexes(None, None).await;
    assert_eq!(code, 200);
    assert!(response["results"].is_array());
    assert!(response["results"].as_array().unwrap().is_empty());
}

#[actix_rt::test]
async fn list_multiple_indexes() {
    let server = Server::new_shared();

    let index_without_key = server.unique_index();
    let (response_without_key, _status_code) = index_without_key.create(None).await;

    let index_with_key = server.unique_index();
    let (response_with_key, _status_code) = index_with_key.create(Some("key")).await;

    index_without_key.wait_task(response_without_key.uid()).await.succeeded();
    index_with_key.wait_task(response_with_key.uid()).await.succeeded();

    let (response, code) = server.list_indexes(None, None).await;
    assert_eq!(code, 200);
    assert!(response["results"].is_array());
    let arr = response["results"].as_array().unwrap();
    assert_eq!(arr.len(), 2);
    assert!(arr.iter().any(|entry| entry["uid"] == index_without_key.uid && entry["primaryKey"] == Value::Null));
    assert!(arr.iter().any(|entry| entry["uid"] == index_with_key.uid && entry["primaryKey"] == "key"));
}

#[actix_rt::test]
async fn get_and_paginate_indexes() {
    let server = Server::new_shared();

    let mut indices_names = Vec::new();
    const NB_INDEXES: usize = 50;
    for _ in 0..NB_INDEXES {
        let index = server.unique_index();
        indices_names.push(index.uid.clone());
        let (response, _status_code) = index.create(None).await;
        index.wait_task(response.uid()).await.succeeded();
    }
    indices_names.sort();

    // basic
    let (response, code) = server.list_indexes(None, None).await;
    assert_eq!(code, 200);
    assert_eq!(response["limit"], json!(20));
    assert_eq!(response["offset"], json!(0));
    assert_eq!(response["total"], json!(NB_INDEXES));
    assert!(response["results"].is_array());

Review comment (bug):
```suggestion
    let (response, code) = server.list_indexes(None, None).await; // here we should retrieve the first 1000 indexes just to be sure we'll find ours
    assert_eq!(code, 200);
    assert!(response["results"].is_array());
    let arr = response["results"].as_array().unwrap();
    assert_eq!(arr.len(), 2); // This becomes wrong if another test is using indexes at the same time, we should remove it
```

Code after:
async fn no_index_return_empty_list() {
    let server = Server::new().await;
    let (response, code) = server.list_indexes(None, None).await;
    assert_eq!(code, 200);
    assert!(response["results"].is_array());
    assert!(response["results"].as_array().unwrap().is_empty());
}

#[actix_rt::test]
async fn list_multiple_indexes() {
    let server = Server::new_shared();

    let index_without_key = server.unique_index();
    let (response_without_key, _status_code) = index_without_key.create(None).await;

    let index_with_key = server.unique_index();
    let (response_with_key, _status_code) = index_with_key.create(Some("key")).await;

    index_without_key.wait_task(response_without_key.uid()).await.succeeded();
    index_with_key.wait_task(response_with_key.uid()).await.succeeded();

    let (response, code) = server.list_indexes(None, Some(1000)).await;
    assert_eq!(code, 200);
    assert!(response["results"].is_array());
    let arr = response["results"].as_array().unwrap();
    assert!(arr.len() >= 2, "Expected at least 2 indexes.");
    assert!(arr
        .iter()
        .any(|entry| entry["uid"] == index_without_key.uid && entry["primaryKey"] == Value::Null));
    assert!(arr
        .iter()
        .any(|entry| entry["uid"] == index_with_key.uid && entry["primaryKey"] == "key"));
}

#[actix_rt::test]
async fn get_and_paginate_indexes() {
    let server = Server::new().await;
    const NB_INDEXES: usize = 50;
    for i in 0..NB_INDEXES {
        server.index(format!("test_{i:02}")).create(None).await;
        server.index(format!("test_{i:02}")).wait_task(i as u64).await;
    }

    // basic
    let (response, code) = server.list_indexes(None, None).await;
    assert_eq!(code, 200);
    assert_eq!(response["limit"], json!(20));
    assert_eq!(response["offset"], json!(0));
    assert_eq!(response["total"], json!(NB_INDEXES));
    assert!(response["results"].is_array());
    let arr = response["results"].as_array().unwrap();