Repository: meilisearch/meilisearch
File: crates/meilisearch/tests/tasks/mod.rs (Rust)

Code before:

    let (response, code) =
        index.filtered_tasks(&["indexCreation", "documentAdditionOrUpdate"], &[], &[]).await;
    assert_eq!(code, 200, "{response}");
    assert_eq!(response["results"].as_array().unwrap().len(), 2);
}

#[actix_rt::test]
async fn list_tasks_invalid_canceled_by_filter() {
    let server = Server::new_shared();
    let index = server.unique_index();
    let (task, _status_code) = index.create(None).await;
    index.wait_task(task.uid()).await.succeeded();
    index
        .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
        .await;

    let (response, code) = index.filtered_tasks(&[], &[], &["0"]).await;
    assert_eq!(code, 200, "{response}");
    assert_eq!(response["results"].as_array().unwrap().len(), 0);
}

#[actix_rt::test]
async fn list_tasks_status_and_type_filtered() {
    let server = Server::new_shared();
    let index = server.unique_index();
    let (task, _status_code) = index.create(None).await;
    index.wait_task(task.uid()).await.succeeded();
    index
        .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
        .await;

    let (response, code) = index.filtered_tasks(&["indexCreation"], &["failed"], &[]).await;
    assert_eq!(code, 200, "{response}");
    assert_eq!(response["results"].as_array().unwrap().len(), 0);

    let (response, code) = index
        .filtered_tasks(
            &["indexCreation", "documentAdditionOrUpdate"],
            &["succeeded", "processing", "enqueued"],
            &[],
        )
        .await;
    assert_eq!(code, 200, "{response}");
    assert_eq!(response["results"].as_array().unwrap().len(), 2);
}

macro_rules! assert_valid_summarized_task {
    ($response:expr, $task_type:literal, $index:tt) => {{
        assert_eq!($response.as_object().unwrap().len(), 5);
        assert!($response["taskUid"].as_u64().is_some());

Review comment (suggestion):
```suggestion
    // Do not use a shared server because we want to assert stuff against the global list of tasks
    let server = Server::new().await;
    let index = server.index("test");
```

Code after:
    assert_eq!(response["results"].as_array().unwrap().len(), 1);

    let (response, code) =
        index.filtered_tasks(&["indexCreation", "documentAdditionOrUpdate"], &[], &[]).await;
    assert_eq!(code, 200, "{response}");
    assert_eq!(response["results"].as_array().unwrap().len(), 2);
}

#[actix_rt::test]
async fn list_tasks_invalid_canceled_by_filter() {
    let server = Server::new_shared();
    let index = server.unique_index();
    let (task, _status_code) = index.create(None).await;
    index.wait_task(task.uid()).await.succeeded();
    let (task, _code) = index
        .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
        .await;

    let (response, code) =
        index.filtered_tasks(&[], &[], &[format!("{}", task.uid()).as_str()]).await;
    assert_eq!(code, 200, "{response}");
    assert_eq!(response["results"].as_array().unwrap().len(), 0);
}

#[actix_rt::test]
async fn list_tasks_status_and_type_filtered() {
    // Do not use a shared server because we want to assert stuff against the global list of tasks
    let server = Server::new().await;
    let index = server.index("test");
    let (task, _status_code) = index.create(None).await;
    index.wait_task(task.uid()).await.succeeded();
    index
        .add_documents(serde_json::from_str(include_str!("../assets/test_set.json")).unwrap(), None)
        .await;

    let (response, code) = index.filtered_tasks(&["indexCreation"], &["failed"], &[]).await;
    assert_eq!(code, 200, "{response}");
    assert_eq!(response["results"].as_array().unwrap().len(), 0);

    let (response, code) = index
        .filtered_tasks(
            &["indexCreation", "documentAdditionOrUpdate"],
            &["succeeded", "processing", "enqueued"],
            &[],
        )
        .await;
    assert_eq!(code, 200, "{response}");
    assert_eq!(response["results"].as_array().unwrap().len(), 2);
}

macro_rules! assert_valid_summarized_task {