How use async_graphql::Lookahead in test function

Hello, I need help...
I have something like this:

use async_graphql::{InputObject, Lookahead, SimpleObject};

impl GqlRootObject for Account {
    fn generate_projection(lookahead: Lookahead, language: Language) -> Document {
        let mut keys = vec![
            "account_id".to_string(),
            "name".to_string(),
            "status".to_string(),
        ];

        if lookahead.field("text").exists() {
            keys.push(format!("text_{}", language).to_string());
        }

        if lookahead.field("domain").exists() {
            keys.push("domain".to_string());
        }

        create_projection_from_keys(keys)
    }
}

I want to write test for this function, something like:

#[test]
    fn test_generate_projection_with_text_field() {
        // Mock a Lookahead object with "text" field requested
        let lookahead = Lookahead::new(|field| field.name() == "text");

        // Generate projection with English language
        let projection = Account::generate_projection(lookahead, Language::English);

        // Assert that the projection includes the necessary fields
        assert_eq!(
            projection,
            doc! {
                "account_id": 1,
                "name": 1,
                "status": 1,
                "text_en": 1
            }
        );
    }

But Lookahead::new is private and can't be directly used for testing, I need to find an alternative approach. How to do it?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.