mod common;

#[test]
fn test_read_query_string_and_args() {
    let ditto = common::get_inactive_builder_ditto(None).unwrap();
    test_read_query_string_and_args_impl(ditto);

    let ditto = common::get_inactive_revamp_ditto(None).unwrap();
    test_read_query_string_and_args_impl(ditto);
}

fn test_read_query_string_and_args_impl(ditto: dittolive_ditto::prelude::Ditto) {
    let observer = ditto
        .store()
        .register_observer_v2(
            (
                "SELECT * FROM users WHERE name = :name",
                serde_json::json!({ "name": "Joe Shmo" }),
            ),
            |_query_result| {},
        )
        .unwrap();

    let query_string = observer.query_string();
    assert_eq!(query_string, "SELECT * FROM users WHERE name = :name");

    let query_args = observer
        .query_arguments()
        .expect("observer should have args");
    let query_args = serde_json::to_value(query_args).unwrap();
    assert_eq!(query_args, serde_json::json!({ "name": "Joe Shmo" }));
}
