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

Code before:
            "title": "Captain Marvel",
            "desc": "a Shazam ersatz",
            "weaknesses": ["magic", "power instability"],
            "outfit": {
                "has_cape": false
            }
        },
        "id": "3",
    }])
});

#[actix_rt::test]
async fn nested_search_on_title_with_prefix_wildcard() {
    let server = Server::new().await;
    let index = index_with_documents(&server, &NESTED_SEARCH_DOCUMENTS).await;

    // Wildcard should match to 'details.' attribute
    index
        .search(
            json!({"q": "Captain Marvel", "attributesToSearchOn": ["*.title"]}),
            |response, code| {
                snapshot!(code, @"200 OK");
                snapshot!(response["hits"].as_array().unwrap().len(), @"2");
            },
        )
        .await;
}

#[actix_rt::test]
async fn nested_search_with_suffix_wildcard() {
    let server = Server::new().await;
    let index = index_with_documents(&server, &NESTED_SEARCH_DOCUMENTS).await;

    // Wildcard should match to any attribute inside 'details.'
    // It's worth noting the difference between 'details.*' and '*.title'
    index
        .search(
            json!({"q": "Captain Marvel", "attributesToSearchOn": ["details.*"]}),
            |response, code| {
                snapshot!(code, @"200 OK");
                snapshot!(response["hits"].as_array().unwrap().len(), @"3");
            },
        )
        .await;

    // Should return 1 document (ids: 1)
    index
        .search(
            json!({"q": "gold", "attributesToSearchOn": ["details.*"]}),
            |response, code| {
                snapshot!(code, @"200 OK");

Review comment (suggestion):
I understand you want to keep the test tiny, the below changes will keep it small but will provide more information about the resulting documents:
```suggestion
    index
        .search(
            json!({"q": "Captain Marvel", "attributesToSearchOn": ["*.title"], "attributesToRetrieve": ["id"]}),
            |response, code| {
                snapshot!(code, @"200 OK");
                snapshot!(response["hits"], @"<placeholder>");
            },
        )
        .await;
```

Code after:
            "title": "Captain Marvel",
            "desc": "a Shazam ersatz",
            "weaknesses": ["magic", "power instability"],
            "outfit": {
                "has_cape": false
            }
        },
        "id": "3",
    }])
});

#[actix_rt::test]
async fn nested_search_on_title_with_prefix_wildcard() {
    let server = Server::new().await;
    let index = index_with_documents(&server, &NESTED_SEARCH_DOCUMENTS).await;

    // Wildcard should match to 'details.' attribute
    index
        .search(
            json!({"q": "Captain Marvel", "attributesToSearchOn": ["*.title"], "attributesToRetrieve": ["id"]}),
            |response, code| {
                snapshot!(code, @"200 OK");
                snapshot!(json_string!(response["hits"]),
                    @r###"
                [
                  {
                    "id": "3"
                  },
                  {
                    "id": "2"
                  }
                ]"###);
            },
        )
        .await;
}

#[actix_rt::test]
async fn nested_search_with_suffix_wildcard() {
    let server = Server::new().await;
    let index = index_with_documents(&server, &NESTED_SEARCH_DOCUMENTS).await;

    // Wildcard should match to any attribute inside 'details.'
    // It's worth noting the difference between 'details.*' and '*.title'
    index
        .search(
            json!({"q": "Captain Marvel", "attributesToSearchOn": ["details.*"], "attributesToRetrieve": ["id"]}),
            |response, code| {
                snapshot!(code, @"200 OK");
                snapshot!(json_string!(response["hits"]),
                    @r###"