Lines
100 %
Functions
Branches
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AccountSuggestion {
pub id: String,
pub name: String,
pub currency: Option<String>,
}
pub struct CommoditySuggestion {
pub symbol: String,
pub struct TagSuggestion {
pub value: Option<String>,
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn account_suggestion_serializes_with_correct_field_names() {
let suggestion = AccountSuggestion {
id: "acc-123".into(),
currency: Some("cur-456".into()),
name: "Checking".into(),
};
let json = serde_json::to_value(&suggestion).unwrap();
assert!(json.get("id").is_some(), "must have 'id' field");
assert!(json.get("name").is_some(), "must have 'name' field");
assert!(json.get("currency").is_some(), "must have 'currency' field");
fn account_suggestion_deserializes_from_api_response() {
let json = r#"{
"id": "acc-123",
"currency": "cur-456",
"name": "Checking"
}"#;
let suggestion: AccountSuggestion = serde_json::from_str(json).unwrap();
assert_eq!(suggestion.id, "acc-123");
assert_eq!(suggestion.currency, Some("cur-456".into()));
assert_eq!(suggestion.name, "Checking");
fn commodity_suggestion_serializes_correctly() {
let suggestion = CommoditySuggestion {
id: "com-123".into(),
symbol: "USD".into(),
name: "US Dollar".into(),
assert!(json.get("symbol").is_some(), "must have 'symbol' field");
fn tag_suggestion_serializes_correctly() {
let suggestion = TagSuggestion {
name: "category".into(),
value: Some("groceries".into()),
assert!(json.get("value").is_some(), "must have 'value' field");