Repository: meilisearch/meilisearch
File: meilisearch-http/tests/documents/add_documents.rs (Rust)

Code before:
    assert_eq!(status_code, 400);
    assert_eq!(
        response["message"],
        json!(
            r#"The `json` payload provided is malformed. `Couldn't serialize document value: invalid type: string "0123456789012345678901234567...890123456789", expected a documents, or a sequence of documents. at line 1 column 102`."#
        )
    );
    assert_eq!(response["code"], json!("malformed_payload"));
    assert_eq!(response["type"], json!("invalid_request"));
    assert_eq!(
        response["link"],
        json!("https://docs.meilisearch.com/errors#malformed_payload")
    );

    // add one more char to the long string to test if the truncating works.
    let document = format!("\"{}m\"", long);
    let req = test::TestRequest::put()
        .uri("/indexes/dog/documents")
        .set_payload(document)
        .insert_header(("content-type", "application/json"))
        .to_request();
    let res = test::call_service(&app, req).await;
    let body = test::read_body(res).await;
    dbg!(&body);
    let response: Value = serde_json::from_slice(&body).unwrap_or_default();
    dbg!(&response);
    assert_eq!(status_code, 400);
    assert_eq!(
        response["message"],
        json!(
            r#"The `json` payload provided is malformed. `Couldn't serialize document value: invalid type: string "0123456789012345678901234567...90123456789m", expected a documents, or a sequence of documents. at line 1 column 103`."#
        )
    );
    assert_eq!(response["code"], json!("malformed_payload"));
    assert_eq!(response["type"], json!("invalid_request"));
    assert_eq!(
        response["link"],
        json!("https://docs.meilisearch.com/errors#malformed_payload")
    );
}

#[actix_rt::test]
async fn error_add_malformed_ndjson_documents() {
    let document = "{\"id\": 1}\n{id: 2}";

    let server = Server::new().await;
    let app = test::init_service(create_app!(
        &server.service.meilisearch,
        &server.service.auth,
        true,
        &server.service.options,

Review comment (suggestion):
```suggestion
    let response: Value = serde_json::from_slice(&body).unwrap_or_default();
```

Code after:
        response["message"],
        json!(
            r#"The `json` payload provided is malformed. `Couldn't serialize document value: invalid type: string "0123456789012345678901234567...890123456789", expected a documents, or a sequence of documents. at line 1 column 102`."#
        )
    );
    assert_eq!(response["code"], json!("malformed_payload"));
    assert_eq!(response["type"], json!("invalid_request"));
    assert_eq!(
        response["link"],
        json!("https://docs.meilisearch.com/errors#malformed_payload")
    );

    // add one more char to the long string to test if the truncating works.
    let document = format!("\"{}m\"", long);
    let req = test::TestRequest::put()
        .uri("/indexes/dog/documents")
        .set_payload(document)
        .insert_header(("content-type", "application/json"))
        .to_request();
    let res = test::call_service(&app, req).await;
    let body = test::read_body(res).await;
    let response: Value = serde_json::from_slice(&body).unwrap_or_default();
    assert_eq!(status_code, 400);
    assert_eq!(
        response["message"],
        json!(
            r#"The `json` payload provided is malformed. `Couldn't serialize document value: invalid type: string "0123456789012345678901234567...90123456789m", expected a documents, or a sequence of documents. at line 1 column 103`."#
        )
    );
    assert_eq!(response["code"], json!("malformed_payload"));
    assert_eq!(response["type"], json!("invalid_request"));
    assert_eq!(
        response["link"],
        json!("https://docs.meilisearch.com/errors#malformed_payload")
    );
}

#[actix_rt::test]
async fn error_add_malformed_ndjson_documents() {
    let document = "{\"id\": 1}\n{id: 2}";

    let server = Server::new().await;
    let app = test::init_service(create_app!(
        &server.service.meilisearch,
        &server.service.auth,
        true,
        &server.service.options,
        analytics::MockAnalytics::new(&server.service.options).0
    ))
    .await;
    // post