in components/search/src/selector.rs [1084:1332]
fn test_filter_engine_configuration_handles_environments() {
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",
"searchTermParamName": "q"
}
}
},
"variants": [{
"environment": {
"allRegionsAndLocales": true
}
}],
},
{
"recordType": "engine",
"identifier": "test2",
"base": {
"name": "Test 2",
"classification": "general",
"urls": {
"search": {
"base": "https://example.com/2",
"method": "GET",
"searchTermParamName": "search"
}
}
},
"variants": [{
"environment": {
"applications": ["firefox-android", "focus-ios"]
}
}],
},
{
"recordType": "engine",
"identifier": "test3",
"base": {
"name": "Test 3",
"classification": "general",
"urls": {
"search": {
"base": "https://example.com/3",
"method": "GET",
"searchTermParamName": "trek"
}
}
},
"variants": [{
"environment": {
"distributions": ["starship"]
}
}],
},
{
"recordType": "defaultEngines",
"globalDefault": "test1",
}
]
})
.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 mut result = Arc::clone(&selector).filter_engine_configuration(SearchUserEnvironment {
distribution_id: String::new(),
app_name: SearchApplicationName::Firefox,
..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::new(),
search_term_param_name: Some("q".to_string())
},
..Default::default()
},
..Default::default()
},
),
app_default_engine_id: Some("test1".to_string()),
app_private_default_engine_id: None
}, "Should have selected test1 for all matching locales, as the environments do not match for the other two"
);
result = Arc::clone(&selector).filter_engine_configuration(SearchUserEnvironment {
distribution_id: String::new(),
app_name: SearchApplicationName::FocusIos,
..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::new(),
search_term_param_name: Some("q".to_string())
},
..Default::default()
},
..Default::default()
},
SearchEngineDefinition {
charset: "UTF-8".to_string(),
classification: SearchEngineClassification::General,
identifier: "test2".to_string(),
name: "Test 2".to_string(),
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())
},
..Default::default()
},
..Default::default()
},
),
app_default_engine_id: Some("test1".to_string()),
app_private_default_engine_id: None
},
"Should have selected test1 for all matching locales and test2 for matching Focus IOS"
);
result = Arc::clone(&selector).filter_engine_configuration(SearchUserEnvironment {
distribution_id: "starship".to_string(),
app_name: SearchApplicationName::Firefox,
..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::new(),
search_term_param_name: Some("q".to_string())
},
..Default::default()
},
..Default::default()
},
SearchEngineDefinition {
charset: "UTF-8".to_string(),
classification: SearchEngineClassification::General,
identifier: "test3".to_string(),
name: "Test 3".to_string(),
urls: SearchEngineUrls {
search: SearchEngineUrl {
base: "https://example.com/3".to_string(),
method: "GET".to_string(),
params: Vec::new(),
search_term_param_name: Some("trek".to_string())
},
..Default::default()
},
..Default::default()
},
),
app_default_engine_id: Some("test1".to_string()),
app_private_default_engine_id: None
}, "Should have selected test1 for all matching locales and test3 for matching the distribution id"
);
}