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

Code before:
    let server = Server::new().await;
    let index = server.index("test");
    let (response, code) = index.create(None).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"], json!(null));
}

#[actix_rt::test]
async fn create_index_with_gzip_encoded_request() {
    let server = Server::new().await;
    let index = server.index_with_encoder("test", Encoder::Gzip);
    let (response, code) = index.create(None).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"], json!(null));
}

#[actix_rt::test]
async fn create_index_with_gzip_encoded_request_and_receiving_brotli_encoded_response() {
    let server = Server::new().await;
    let app = server.init_web_app().await;

    let body = serde_json::to_string(&json!({
        "uid": "test",
        "primaryKey": None::<&str>,
    }))
    .unwrap();
    let req = test::TestRequest::post()
        .uri("/indexes")
        .insert_header(Encoder::Gzip.header().unwrap())
        .insert_header((ACCEPT_ENCODING, "br"))
        .insert_header(ContentType::json())
        .set_payload(Encoder::Gzip.encode(body))
        .to_request();

    let res = test::call_service(&app, req).await;

Review comment (refactor):
Same as above, we could use a shared server.

But this time we don’t have the right function to do it with an encoder.
Could you create a new method on the `Server<Shared>` called `unique_index_with_encoder` that takes the encoder by parameter?

Here’s the current one you need to duplicate:
https://github.com/meilisearch/meilisearch/blob/7f20c13f3fc374faa0b812d4e21de541ed95746a/meilisearch/tests/common/server.rs#L301-L310

Code after:
    let server = Server::new_shared();
    let index = server.unique_index();
    let (response, code) = index.create(None).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"], json!(null));
}

#[actix_rt::test]
async fn create_index_with_gzip_encoded_request() {
    let server = Server::new_shared();
    let index = server.unique_index_with_encoder(Encoder::Gzip);
    let (response, code) = index.create(None).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"], json!(null));
}

#[actix_rt::test]
async fn create_index_with_gzip_encoded_request_and_receiving_brotli_encoded_response() {
    let server = Server::new_shared();
    let app = server.init_web_app().await;

    let body = serde_json::to_string(&json!({
        "uid": "test",
        "primaryKey": None::<&str>,
    }))
    .unwrap();
    let req = test::TestRequest::post()
        .uri("/indexes")
        .insert_header(Encoder::Gzip.header().unwrap())
        .insert_header((ACCEPT_ENCODING, "br"))
        .insert_header(ContentType::json())
        .set_payload(Encoder::Gzip.encode(body))
        .to_request();

    let res = test::call_service(&app, req).await;