summaryrefslogtreecommitdiff
path: root/rust/actualbudget_queries/tests/actualbudget_transactions.rs
blob: ee05daa86e78a228b8783f280ae70fc4cce35913 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
pub mod common;

use actualbudget_queries::actualbudget_transactions::{get_all_actualbudget_transactions, get_first_actualbudget_transaction_date};
use common::{db_url::DB_URL, get_reference_data::{get_accounts, get_categories}, transaction_matchers::get_transaction_matchers};
use diesel::{Connection, SqliteConnection};

#[test]
fn given_test_database_when_get_all_transactions_then_return_transactions() {
    let connection = &mut SqliteConnection::establish(DB_URL).unwrap();
    let accounts = get_accounts(connection);
    let categories = get_categories(connection);

    let transactions = get_all_actualbudget_transactions(connection);

    assert!(transactions.is_ok());
    let transactions = transactions.unwrap();
    let transaction_matchers = get_transaction_matchers();
    assert_eq!(transaction_matchers.len(), transactions.len());
    for transaction_matcher in transaction_matchers {
        assert!(transactions.iter().any(|t| transaction_matcher(t, &accounts, &categories)));
    }
}

#[test]
fn given_test_database_when_get_first_transaction_date_then_return_01_aug_2024() {
    let connection = &mut SqliteConnection::establish(DB_URL).unwrap();

    let date = get_first_actualbudget_transaction_date(connection);

    assert!(date.is_ok());
    let date = date.unwrap();
    assert_eq!("01", date.day());
    assert_eq!("08", date.month());
    assert_eq!("2024", date.year());
}