fix: set proper filter_expression format

This commit is contained in:
Bastian Gruber 2024-11-13 11:27:10 -04:00
Родитель 13908171a8
Коммит a486b51698
3 изменённых файлов: 19 добавлений и 15 удалений

Просмотреть файл

@ -1603,10 +1603,12 @@ mod test_filtering_records {
last_modified: 100,
deleted: false,
attachment: None,
fields: json!({"filter_expression": "app_version|versionCompare('4.0') >= 0"})
.as_object()
.unwrap()
.clone(),
fields: json!({
"filter_expression": "env.version|versionCompare(\"128.0a1\") > 0"
})
.as_object()
.unwrap()
.clone(),
}];
api_client.expect_collection_url().returning(|| {
"http://rs.example.com/v1/buckets/main/collections/test-collection".into()
@ -1620,7 +1622,7 @@ mod test_filtering_records {
});
let context = RemoteSettingsContext {
app_version: Some("4.4".to_string()),
app_version: Some("129.0.0".to_string()),
..Default::default()
};
@ -1650,10 +1652,12 @@ mod test_filtering_records {
last_modified: 100,
deleted: false,
attachment: None,
fields: json!({"filter_expression": "app_version|versionCompare('4.0') >= 0"})
.as_object()
.unwrap()
.clone(),
fields: json!({
"filter_expression": "env.version|versionCompare(\"128.0a1\") > 0"
})
.as_object()
.unwrap()
.clone(),
}];
api_client.expect_collection_url().returning(|| {
"http://rs.example.com/v1/buckets/main/collections/test-collection".into()
@ -1667,7 +1671,7 @@ mod test_filtering_records {
});
let context = RemoteSettingsContext {
app_version: Some("3.9".to_string()),
app_version: Some("127.0.0.".to_string()),
..Default::default()
};

Просмотреть файл

@ -26,16 +26,15 @@ impl JexlFilter {
pub(crate) fn new(context: Option<RemoteSettingsContext>) -> Self {
let env_context = match context {
Some(ctx) => {
serde_json::to_value(ctx).expect("Failed to serialize RemoteSettingsContext")
let serialized_context =
serde_json::to_value(ctx).expect("Failed to serialize RemoteSettingsContext");
json!({ "env": serialized_context })
}
None => json!({}),
None => json!({ "env": {} }),
};
Self {
evaluator: Evaluator::new()
// We want to add more transforms later on. We started with `versionCompare`.
// https://remote-settings.readthedocs.io/en/latest/target-filters.html#transforms
// The goal is to get on pare with the desktop.
.with_transform("versionCompare", |args| Ok(version_compare(args)?)),
context: env_context,
}

Просмотреть файл

@ -44,6 +44,7 @@ pub struct RemoteSettingsContext {
/// The delivery channel of the application (e.g "nightly")
pub channel: String,
/// User visible version string (e.g. "1.0.3")
#[serde(rename = "version")]
pub app_version: Option<String>,
/// Build identifier generated by the CI system (e.g. "1234/A")
pub app_build: Option<String>,