in components/search/src/filter.rs [862:1045]
fn test_from_configuration_details_merges_sub_variants() {
let result = SearchEngineDefinition::from_configuration_details(
"test",
Lazy::force(&ENGINE_BASE).clone(),
&JSONEngineVariant {
environment: JSONVariantEnvironment {
all_regions_and_locales: true,
..Default::default()
},
optional: true,
partner_code: Some("trek".to_string()),
telemetry_suffix: Some("star".to_string()),
urls: Some(JSONEngineUrls {
search: Some(JSONEngineUrl {
base: Some("https://example.com/variant".to_string()),
method: Some(JSONEngineMethod::Get),
params: Some(vec![SearchUrlParam {
name: "variant".to_string(),
value: Some("test variant".to_string()),
enterprise_value: None,
experiment_config: None,
}]),
search_term_param_name: Some("ship".to_string()),
}),
suggestions: Some(JSONEngineUrl {
base: Some("https://example.com/suggestions-variant".to_string()),
method: Some(JSONEngineMethod::Get),
params: Some(vec![SearchUrlParam {
name: "suggest-variant".to_string(),
value: Some("sugg test variant".to_string()),
enterprise_value: None,
experiment_config: None,
}]),
search_term_param_name: Some("variant".to_string()),
}),
trending: Some(JSONEngineUrl {
base: Some("https://example.com/trending-variant".to_string()),
method: Some(JSONEngineMethod::Get),
params: Some(vec![SearchUrlParam {
name: "trend-variant".to_string(),
value: Some("trend test variant".to_string()),
enterprise_value: None,
experiment_config: None,
}]),
search_term_param_name: Some("trend".to_string()),
}),
search_form: Some(JSONEngineUrl {
base: Some("https://example.com/search-form-variant".to_string()),
method: Some(crate::JSONEngineMethod::Get),
params: Some(vec![SearchUrlParam {
name: "search-form-variant".to_string(),
value: Some("search form variant".to_string()),
enterprise_value: None,
experiment_config: None,
}]),
search_term_param_name: None,
}),
}),
// This would be the list of sub-variants for this part of the
// configuration, however it is not used as the actual sub-variant
// to be merged is passed as the third argument to
// `from_configuration_details`.
sub_variants: vec![],
},
&Some(JSONEngineVariant {
environment: JSONVariantEnvironment {
all_regions_and_locales: true,
..Default::default()
},
optional: true,
partner_code: Some("trek2".to_string()),
telemetry_suffix: Some("star2".to_string()),
urls: Some(JSONEngineUrls {
search: Some(JSONEngineUrl {
base: Some("https://example.com/subvariant".to_string()),
method: Some(JSONEngineMethod::Get),
params: Some(vec![SearchUrlParam {
name: "subvariant".to_string(),
value: Some("test subvariant".to_string()),
enterprise_value: None,
experiment_config: None,
}]),
search_term_param_name: Some("shuttle".to_string()),
}),
suggestions: Some(JSONEngineUrl {
base: Some("https://example.com/suggestions-subvariant".to_string()),
method: Some(JSONEngineMethod::Get),
params: Some(vec![SearchUrlParam {
name: "suggest-subvariant".to_string(),
value: Some("sugg test subvariant".to_string()),
enterprise_value: None,
experiment_config: None,
}]),
search_term_param_name: Some("subvariant".to_string()),
}),
trending: Some(JSONEngineUrl {
base: Some("https://example.com/trending-subvariant".to_string()),
method: Some(JSONEngineMethod::Get),
params: Some(vec![SearchUrlParam {
name: "trend-subvariant".to_string(),
value: Some("trend test subvariant".to_string()),
enterprise_value: None,
experiment_config: None,
}]),
search_term_param_name: Some("subtrend".to_string()),
}),
search_form: Some(JSONEngineUrl {
base: Some("https://example.com/search-form-subvariant".to_string()),
method: Some(crate::JSONEngineMethod::Get),
params: Some(vec![SearchUrlParam {
name: "search-form-subvariant".to_string(),
value: Some("search form subvariant".to_string()),
enterprise_value: None,
experiment_config: None,
}]),
search_term_param_name: None,
}),
}),
sub_variants: vec![],
}),
);
assert_eq!(
result,
SearchEngineDefinition {
aliases: vec!["foo".to_string(), "bar".to_string()],
charset: "ISO-8859-15".to_string(),
classification: SearchEngineClassification::Unknown,
identifier: "test".to_string(),
partner_code: "trek2".to_string(),
name: "Test".to_string(),
optional: true,
order_hint: None,
telemetry_suffix: "star2".to_string(),
urls: SearchEngineUrls {
search: SearchEngineUrl {
base: "https://example.com/subvariant".to_string(),
method: "GET".to_string(),
params: vec![SearchUrlParam {
name: "subvariant".to_string(),
value: Some("test subvariant".to_string()),
enterprise_value: None,
experiment_config: None,
}],
search_term_param_name: Some("shuttle".to_string()),
},
suggestions: Some(SearchEngineUrl {
base: "https://example.com/suggestions-subvariant".to_string(),
method: "GET".to_string(),
params: vec![SearchUrlParam {
name: "suggest-subvariant".to_string(),
value: Some("sugg test subvariant".to_string()),
enterprise_value: None,
experiment_config: None,
}],
search_term_param_name: Some("subvariant".to_string()),
}),
trending: Some(SearchEngineUrl {
base: "https://example.com/trending-subvariant".to_string(),
method: "GET".to_string(),
params: vec![SearchUrlParam {
name: "trend-subvariant".to_string(),
value: Some("trend test subvariant".to_string()),
enterprise_value: None,
experiment_config: None,
}],
search_term_param_name: Some("subtrend".to_string()),
}),
search_form: Some(SearchEngineUrl {
base: "https://example.com/search-form-subvariant".to_string(),
method: "GET".to_string(),
params: vec![SearchUrlParam {
name: "search-form-subvariant".to_string(),
value: Some("search form subvariant".to_string()),
enterprise_value: None,
experiment_config: None,
}],
search_term_param_name: None,
}),
},
click_url: None
}
)
}