Repository: meilisearch/meilisearch
File: crates/meilisearch/tests/search/facet_search.rs (Rust)

Code before:

#[actix_rt::test]
async fn add_documents_and_deactivate_facet_search() {
    let server = Server::new().await;
    let index = server.index("test");

    let documents = DOCUMENTS.clone();
    let (response, _code) = index.add_documents(documents, None).await;
    index.wait_task(response.uid()).await;
    let (response, code) = index
        .update_settings(json!({
            "facetSearch": false,
            "filterableAttributes": ["genres"],
        }))
        .await;
    assert_eq!("202", code.as_str(), "{:?}", response);
    index.wait_task(response.uid()).await;

    let (response, code) =
        index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await;

    assert_eq!(code, 400, "{}", response);
    snapshot!(response, @r###"
    {
      "message": "The facet search is disabled for this index",
      "code": "invalid_facet_search_disabled",
      "type": "invalid_request",
      "link": "https://docs.meilisearch.com/errors#invalid_facet_search_disabled"
    }
    "###);
}

#[actix_rt::test]
async fn deactivate_facet_search_and_add_documents() {
    let server = Server::new().await;
    let index = server.index("test");

    let (response, code) = index
        .update_settings(json!({
            "facetSearch": false,
            "filterableAttributes": ["genres"],
        }))
        .await;
    assert_eq!("202", code.as_str(), "{:?}", response);
    index.wait_task(response.uid()).await;
    let documents = DOCUMENTS.clone();
    let (response, _code) = index.add_documents(documents, None).await;
    index.wait_task(response.uid()).await;

    let (response, code) =
        index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await;

Review comment (suggestion):
Minor suggestion that might not fit the actual naming strategy in other parts of the program, but I find `invalid` a bit out of place here.

As in, `invalid_search_vector` makes sense because it indicates the search vector itself is not valid. `invalid_facet_search_disabled` is less clear—what exactly is invalid here?

That said, it could also be read as "Invalid: facet search disabled", I guess, but I'm not sure there's precedent in the existing code.

```suggestion
      "code": "facet_search_disabled",
```

Code after:

#[actix_rt::test]
async fn add_documents_and_deactivate_facet_search() {
    let server = Server::new().await;
    let index = server.index("test");

    let documents = DOCUMENTS.clone();
    let (response, _code) = index.add_documents(documents, None).await;
    index.wait_task(response.uid()).await;
    let (response, code) = index
        .update_settings(json!({
            "facetSearch": false,
            "filterableAttributes": ["genres"],
        }))
        .await;
    assert_eq!("202", code.as_str(), "{:?}", response);
    index.wait_task(response.uid()).await;

    let (response, code) =
        index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await;

    assert_eq!(code, 400, "{}", response);
    snapshot!(response, @r###"
    {
      "message": "The facet search is disabled for this index",
      "code": "facet_search_disabled",
      "type": "invalid_request",
      "link": "https://docs.meilisearch.com/errors#facet_search_disabled"
    }
    "###);
}

#[actix_rt::test]
async fn deactivate_facet_search_and_add_documents() {
    let server = Server::new().await;
    let index = server.index("test");

    let (response, code) = index
        .update_settings(json!({
            "facetSearch": false,
            "filterableAttributes": ["genres"],
        }))
        .await;
    assert_eq!("202", code.as_str(), "{:?}", response);
    index.wait_task(response.uid()).await;
    let documents = DOCUMENTS.clone();
    let (response, _code) = index.add_documents(documents, None).await;
    index.wait_task(response.uid()).await;

    let (response, code) =
        index.facet_search(json!({"facetName": "genres", "facetQuery": "a"})).await;