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

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

    assert_eq!(res.status(), 202);

    let bytes = test::read_body(res).await;
    let decoded = Encoder::Brotli.decode(bytes);
    let parsed_response =
        serde_json::from_slice::<Value>(decoded.into().as_ref()).expect("Expecting valid json");

    assert_eq!(parsed_response["taskUid"], 0);
    assert_eq!(parsed_response["indexUid"], "test");
}

#[actix_rt::test]
async fn create_index_with_zlib_encoded_request() {
    let server = Server::new().await;
    let index = server.index_with_encoder("test", Encoder::Deflate);
    let (response, code) = index.create(None).await;

    assert_eq!(code, 202);

    assert_eq!(response["status"], "enqueued");

    let response = index.wait_task(0).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_brotli_encoded_request() {
    let server = Server::new().await;
    let index = server.index_with_encoder("test", Encoder::Brotli);
    let (response, code) = index.create(None).await;

Review comment (refactor):
I had to remove this as it appears to be different locally and in the CI, so it's hard to know the actual taskUid here...

Code after:
    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;

    assert_eq!(res.status(), 202);

    let bytes = test::read_body(res).await;
    let decoded = Encoder::Brotli.decode(bytes);
    let parsed_response =
        serde_json::from_slice::<Value>(decoded.into().as_ref()).expect("Expecting valid json");

    assert_eq!(parsed_response["indexUid"], "test");
}

#[actix_rt::test]
async fn create_index_with_zlib_encoded_request() {
    let server = Server::new_shared();
    let index = server.unique_index_with_encoder(Encoder::Deflate);
    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_brotli_encoded_request() {
    let server = Server::new_shared();
    let index = server.unique_index_with_encoder(Encoder::Brotli);
    let (response, code) = index.create(None).await;