in components/search/src/selector.rs [366:577]
fn test_filter_engine_configuration_returns_basic_engines() {
let selector = Arc::new(SearchEngineSelector::new());
let config_overrides_result = Arc::clone(&selector).set_config_overrides(
json!({
"data": [
{
"identifier": "overrides-engine",
"partnerCode": "overrides-partner-code",
"clickUrl": "https://example.com/click-url",
"telemetrySuffix": "overrides-telemetry-suffix",
"urls": {
"search": {
"base": "https://example.com/search-overrides",
"method": "GET",
"params": []
}
}
}
]
})
.to_string(),
);
let config_result = Arc::clone(&selector).set_search_config(
json!({
"data": [
{
"recordType": "engine",
"identifier": "test1",
"base": {
"name": "Test 1",
"classification": "general",
"urls": {
"search": {
"base": "https://example.com/1",
"method": "GET",
"params": [{
"name": "search-name",
"enterpriseValue": "enterprise-value",
}],
"searchTermParamName": "q"
},
"suggestions": {
"base": "https://example.com/suggestions",
"method": "POST",
"params": [{
"name": "suggestion-name",
"value": "suggestion-value",
}],
"searchTermParamName": "suggest"
},
"trending": {
"base": "https://example.com/trending",
"method": "GET",
"params": [{
"name": "trending-name",
"experimentConfig": "trending-experiment-value",
}]
},
"searchForm": {
"base": "https://example.com/search-form",
"method": "GET",
"params": [{
"name": "search-form-name",
"value": "search-form-value",
}]
}
}
},
"variants": [{
"environment": {
"allRegionsAndLocales": true
}
}],
},
{
"recordType": "engine",
"identifier": "test2",
"base": {
"name": "Test 2",
// No classification specified to test fallback.
"urls": {
"search": {
"base": "https://example.com/2",
"method": "GET",
"searchTermParamName": "search"
}
}
},
"variants": [{
"environment": {
"allRegionsAndLocales": true
}
}],
},
{
"recordType": "defaultEngines",
"globalDefault": "test1",
"globalDefaultPrivate": "test2"
}
]
})
.to_string(),
);
assert!(
config_result.is_ok(),
"Should have set the configuration successfully. {:?}",
config_result
);
assert!(
config_overrides_result.is_ok(),
"Should have set the configuration overrides successfully. {:?}",
config_overrides_result
);
let result = selector.filter_engine_configuration(SearchUserEnvironment {
..Default::default()
});
assert!(
result.is_ok(),
"Should have filtered the configuration without error. {:?}",
result
);
assert_eq!(
result.unwrap(),
RefinedSearchConfig {
engines: vec!(
SearchEngineDefinition {
charset: "UTF-8".to_string(),
classification: SearchEngineClassification::General,
identifier: "test1".to_string(),
name: "Test 1".to_string(),
urls: SearchEngineUrls {
search: SearchEngineUrl {
base: "https://example.com/1".to_string(),
method: "GET".to_string(),
params: vec![SearchUrlParam {
name: "search-name".to_string(),
value: None,
enterprise_value: Some("enterprise-value".to_string()),
experiment_config: None
}],
search_term_param_name: Some("q".to_string())
},
suggestions: Some(SearchEngineUrl {
base: "https://example.com/suggestions".to_string(),
method: "POST".to_string(),
params: vec![SearchUrlParam {
name: "suggestion-name".to_string(),
value: Some("suggestion-value".to_string()),
enterprise_value: None,
experiment_config: None
}],
search_term_param_name: Some("suggest".to_string())
}),
trending: Some(SearchEngineUrl {
base: "https://example.com/trending".to_string(),
method: "GET".to_string(),
params: vec![SearchUrlParam {
name: "trending-name".to_string(),
value: None,
enterprise_value: None,
experiment_config: Some(
"trending-experiment-value".to_string()
)
}],
search_term_param_name: None
}),
search_form: Some(SearchEngineUrl {
base: "https://example.com/search-form".to_string(),
method: "GET".to_string(),
params: vec![SearchUrlParam {
name: "search-form-name".to_string(),
value: Some("search-form-value".to_string()),
experiment_config: None,
enterprise_value: None,
}],
search_term_param_name: None,
}),
},
..Default::default()
},
SearchEngineDefinition {
aliases: Vec::new(),
charset: "UTF-8".to_string(),
classification: SearchEngineClassification::Unknown,
identifier: "test2".to_string(),
name: "Test 2".to_string(),
optional: false,
order_hint: None,
partner_code: String::new(),
telemetry_suffix: String::new(),
urls: SearchEngineUrls {
search: SearchEngineUrl {
base: "https://example.com/2".to_string(),
method: "GET".to_string(),
params: Vec::new(),
search_term_param_name: Some("search".to_string())
},
suggestions: None,
trending: None,
search_form: None
},
click_url: None,
}
),
app_default_engine_id: Some("test1".to_string()),
app_private_default_engine_id: Some("test2".to_string())
}
)
}