1
use server::command::PaginationInfo;
2

            
3
use super::Failure;
4
use super::query::{page_totals, row};
5
use finance::tag::Tag;
6
use finance::transaction::Transaction;
7
use server::command::FinanceEntity;
8
use server::timezone::Tz;
9
use std::collections::HashMap;
10
use uuid::Uuid;
11

            
12
2
fn info(total_count: i64, has_more: bool) -> PaginationInfo {
13
2
    PaginationInfo {
14
2
        total_count,
15
2
        limit: 10,
16
2
        offset: 0,
17
2
        has_more,
18
2
    }
19
2
}
20

            
21
#[test]
22
1
fn totals_come_from_the_pagination() {
23
1
    let info = info(42, true);
24
1
    assert!(matches!(page_totals(Some(&info)), Ok((42, true))));
25
1
}
26

            
27
#[test]
28
1
fn missing_pagination_is_internal() {
29
1
    assert!(matches!(page_totals(None), Err(Failure::Internal(_))));
30
1
}
31

            
32
#[test]
33
1
fn negative_total_is_internal() {
34
1
    let info = info(-1, false);
35
1
    assert!(matches!(
36
1
        page_totals(Some(&info)),
37
        Err(Failure::Internal(_))
38
    ));
39
1
}
40

            
41
#[test]
42
1
fn a_padded_note_key_is_the_row_note() {
43
1
    let now = chrono::Utc::now();
44
1
    let entity = FinanceEntity::Transaction(Transaction {
45
1
        id: Uuid::new_v4(),
46
1
        post_date: now,
47
1
        enter_date: now,
48
1
    });
49
1
    let padded = Tag {
50
1
        id: Uuid::new_v4(),
51
1
        tag_name: "note ".to_string(),
52
1
        tag_value: "lunch".to_string(),
53
1
        description: None,
54
1
    };
55
1
    let tags = HashMap::from([(padded.tag_name.clone(), FinanceEntity::Tag(padded))]);
56
1
    let shown = row(&entity, &tags, None, Tz::UTC).unwrap();
57
1
    assert_eq!(shown.note, "lunch");
58
1
}