1
use super::*;
2

            
3
const ACTIVITY: &str = "/report/activity";
4

            
5
34
fn name_in(path: &str, query: &str) -> Option<String> {
6
34
    retired_in(path, query).map(|(name, _)| name)
7
34
}
8

            
9
#[test]
10
2
fn retired_names_are_found_in_any_position_and_encoding() {
11
2
    for (query, want) in [
12
2
        ("tag_filters=%7B%7D", Some("tag_filters")),
13
2
        ("a=1&tag_filter_mode=visual", Some("tag_filter_mode")),
14
2
        ("tag%5Ffilters=x", Some("tag_filters")),
15
2
        ("groups=%5B%5D", Some("groups")),
16
2
        ("a=1&groups_mode=script", Some("groups_mode")),
17
2
        ("groups.0.name=Income&groups.0.flip=yes", None),
18
2
        ("filter=%28and%29&from=2026-01-01", None),
19
2
        ("", None),
20
2
    ] {
21
16
        assert_eq!(name_in(ACTIVITY, query).as_deref(), want, "{query}");
22
    }
23
2
}
24

            
25
#[test]
26
2
fn the_balance_report_also_refuses_its_old_names_with_the_new_key() {
27
2
    for path in [
28
2
        "/report/balance",
29
2
        "/report/balance/chart.svg",
30
2
        "/api/report/balance/chart.json",
31
2
    ] {
32
6
        for (query, name, hint) in [
33
6
            ("target_commodity_id=x", "target_commodity_id", "use target"),
34
6
            ("a=1&date_from=2026-01-01", "date_from", "use from"),
35
6
            ("as_of=2026-01-01", "as_of", "use as-of"),
36
6
        ] {
37
18
            assert_eq!(
38
18
                retired_in(path, query),
39
18
                Some((name.to_string(), hint)),
40
                "{path}?{query}"
41
            );
42
        }
43
6
        assert_eq!(name_in(path, "as-of=2026-01-01&from=2026-01-01"), None);
44
    }
45
2
}
46

            
47
#[test]
48
2
fn the_category_report_refuses_its_old_names_with_the_new_key() {
49
2
    for path in [
50
2
        "/report/category-breakdown",
51
2
        "/report/category-breakdown/chart.json",
52
2
        "/api/report/category-breakdown/export.csv",
53
2
    ] {
54
6
        for (query, name, hint) in [
55
6
            ("target_commodity_id=x", "target_commodity_id", "use target"),
56
6
            ("a=1&date_from=2026-01-01", "date_from", "use from"),
57
6
            ("date_to=2026-01-01", "date_to", "use to"),
58
6
            ("period_grouping=month", "period_grouping", "use grouping"),
59
6
            ("tag_name=kind", "tag_name", "use tag"),
60
6
            ("sort_order=name_asc", "sort_order", "use sort"),
61
6
            (
62
6
                "exclude_uncategorized=on",
63
6
                "exclude_uncategorized",
64
6
                "use include-uncategorized",
65
6
            ),
66
6
            (
67
6
                "include_uncategorized=on",
68
6
                "include_uncategorized",
69
6
                "use include-uncategorized",
70
6
            ),
71
6
        ] {
72
48
            assert_eq!(
73
48
                retired_in(path, query),
74
48
                Some((name.to_string(), hint)),
75
                "{path}?{query}"
76
            );
77
        }
78
6
        let new = "from=2026-01-01&to=2026-01-31&grouping=month&tag=k&sort=name_asc&include-uncategorized=no";
79
6
        assert_eq!(name_in(path, new), None);
80
    }
81
2
}
82

            
83
#[test]
84
2
fn the_activity_report_refuses_its_old_names_with_the_new_key() {
85
2
    for path in [
86
2
        "/report/activity",
87
2
        "/report/activity/chart.svg",
88
2
        "/api/report/activity/chart.json",
89
2
    ] {
90
6
        for (query, name, hint) in [
91
6
            ("target_commodity_id=x", "target_commodity_id", "use target"),
92
6
            ("a=1&date_from=2026-01-01", "date_from", "use from"),
93
6
            ("date_to=2026-01-01", "date_to", "use to"),
94
6
            ("period_grouping=month", "period_grouping", "use grouping"),
95
6
        ] {
96
24
            assert_eq!(
97
24
                retired_in(path, query),
98
24
                Some((name.to_string(), hint)),
99
                "{path}?{query}"
100
            );
101
        }
102
6
        assert_eq!(
103
6
            name_in(path, "from=2026-01-01&to=2026-01-31&grouping=month"),
104
6
            None
105
        );
106
    }
107
2
}