-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JEXL evaluator access from Swift and Kotlin #4813
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4813 +/- ##
==========================================
+ Coverage 81.49% 81.64% +0.14%
==========================================
Files 49 50 +1
Lines 5653 5660 +7
==========================================
+ Hits 4607 4621 +14
+ Misses 1046 1039 -7
Continue to review full report at Codecov.
|
a587631
to
23fa587
Compare
@@ -34,7 +34,7 @@ import org.robolectric.RobolectricTestRunner | |||
import java.util.concurrent.Executors | |||
|
|||
@RunWith(RobolectricTestRunner::class) | |||
class NimbusTest { | |||
class NimbusTests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the rename, I think I accidentally ran a re-format on this file.
@@ -292,7 +363,8 @@ class NimbusTest { | |||
"id": "test-experiment", | |||
"last_modified": 1602197324372 | |||
}]} | |||
""".trimIndent()) | |||
""".trimIndent() | |||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nerp. No extra changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Looks good to me - it would be awesome if we can add a couple more tests cases in the kotlin/swift code, but otherwise no need to block on my review!
I am absolutely in love with exposing the ability to run targeting by the consumers 🚀 This should allow us to improve our end-to-end testing story as well 🕺
} | ||
|
||
@Test | ||
fun `jexl can be run against the json context`() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add more complex jexl statements (at the very least something with "ors" and "and")?
match json.as_object() { | ||
Some(obj) => Ok(obj.clone()), | ||
_ => Err(uniffi::deps::anyhow::anyhow!( | ||
"Unexpected JSON-non-object in the bagging area" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm can we add tests for a non-object json? to make sure the exception is handled correctly by this - I think the invalid json case is covered by the bindings side custom types right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added tests, but we try hard to make sure strings that don't code for objects enter the system.
#[derive(Deserialize, Serialize, Debug, Clone, Default)] | ||
pub struct Matcher { | ||
pub app_name: String, | ||
pub app_id: String, | ||
pub channel: String, | ||
pub app_display_version: Option<String>, | ||
pub app_min_version: Option<String>, | ||
pub app_max_version: Option<String>, | ||
pub app_build: Option<String>, | ||
pub app_min_build: Option<String>, | ||
pub app_max_build: Option<String>, | ||
pub architecture: Option<String>, | ||
pub device_manufacturer: Option<String>, | ||
pub device_model: Option<String>, | ||
pub locale: Option<String>, | ||
pub os: Option<String>, | ||
pub os_version: Option<String>, | ||
pub android_sdk_version: Option<String>, | ||
pub debug_tags: Vec<String>, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍
#[macro_use] | ||
use nimbus::error::Result; | ||
|
||
#[cfg(feature = "rkv-safe-mode")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity, why is this necessary? I know it's in the other test files, but does it have any implication on targeting tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's because we actually use a DB in testing. I don't know definitively, except it doesn't work without it. It's cargo cult by this time.
messageHelper.evalJexl("test_value_from_json == 42") | ||
} | ||
|
||
assertTrue( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍 🎉 🚀
23fa587
to
e5797ca
Compare
Fixes EXP-2158.
This PR refactors the targeting infrastructure to allow JEXL to be available for external applications.
This is relatively specialised: it allows evaluation against the targeting attributes Nimbus uses, and allows a JSON object/Codable to be add extra variables.
Pull Request checklist
[ci full]
to the PR title.