mmex_lib 0.1.2-beta.1

Library for interacting with Money Manager EX data and logic
Documentation
mod common;
use chrono::NaiveDate;
use mmex_lib::domain::payees::PayeeId;
use mmex_lib::domain::transactions::{
    Transaction, TransactionCode, TransactionId, TransactionStatus,
};
use mmex_lib::domain::types::{AccountId, Money};
use rust_decimal_macros::dec;
use mmex_lib::domain::MmexDate;

#[test]
fn test_transaction_full_crud() {
    let ctx = common::setup_test_db();
    let service = ctx.transactions();

    let mut tx = Transaction {
        id: TransactionId { v1: 0 },
        account_id: AccountId { v1: 1 },
        to_account_id: None,
        payee_id: PayeeId { v1: 1 },
        trans_code: TransactionCode::Withdrawal,
        amount: Money::from(dec!(50.0)),
        status: TransactionStatus::None,
        transaction_number: None,
        notes: None,
        category_id: None,
        date: Some(MmexDate::from(NaiveDate::from_ymd_opt(2026, 2, 25).unwrap())),
        to_amount: None,
    };

    // 1. Create
    let created = service.create_transaction(&tx).unwrap();
    tx.id = created.id;

    // 2. Update
    tx.amount = Money::from(dec!(75.0));
    service.update_transaction(&tx).expect("Failed update");
    let found = service.get_transaction_by_id(tx.id).unwrap().unwrap();
    assert_eq!(found.amount.to_decimal(), dec!(75.0));

    // 3. Delete
    service.delete_transaction(tx.id).expect("Failed delete");
    let after_delete = service.get_transaction_by_id(tx.id).unwrap();
    assert!(after_delete.is_none());
}