azure-devops 0.1.0

Idiomatic Rust client for Azure DevOps REST APIs
Documentation
/// Serialize an enum variant to its camelCase JSON string representation.
/// Used by query parameter builders across all API client modules.
pub(crate) fn enum_to_str<T: serde::Serialize>(val: &T) -> String {
    serde_json::to_string(val)
        .unwrap_or_default()
        .trim_matches('"')
        .into()
}

/// Convert query params from `Vec<(String, String)>` to `Vec<(&str, &str)>`.
/// Used by all API client modules when calling HTTP methods.
pub(crate) fn ref_query(params: &[(String, String)]) -> Vec<(&str, &str)> {
    params
        .iter()
        .map(|(k, v)| (k.as_str(), v.as_str()))
        .collect()
}

#[cfg(test)]
mod tests {
    use super::*;
    use serde::Serialize;

    #[derive(Serialize)]
    #[serde(rename_all = "camelCase")]
    enum TestEnum {
        SomeValue,
        AnotherValue,
    }

    #[test]
    fn enum_to_str_returns_camel_case() {
        assert_eq!(enum_to_str(&TestEnum::SomeValue), "someValue");
        assert_eq!(enum_to_str(&TestEnum::AnotherValue), "anotherValue");
    }

    #[test]
    fn ref_query_converts_to_str_slices() {
        let input = vec![
            ("key1".to_string(), "value1".to_string()),
            ("key2".to_string(), "value2".to_string()),
        ];
        let result = ref_query(&input);
        assert_eq!(result.len(), 2);
        assert_eq!(result[0], ("key1", "value1"));
        assert_eq!(result[1], ("key2", "value2"));
    }

    #[test]
    fn ref_query_handles_empty_input() {
        let input: Vec<(String, String)> = vec![];
        let result = ref_query(&input);
        assert!(result.is_empty());
    }
}