Lines
100 %
Functions
Branches
use server::command::PaginationInfo;
use super::Failure;
use super::query::{page_totals, row};
use finance::tag::Tag;
use finance::transaction::Transaction;
use server::command::FinanceEntity;
use server::timezone::Tz;
use std::collections::HashMap;
use uuid::Uuid;
fn info(total_count: i64, has_more: bool) -> PaginationInfo {
PaginationInfo {
total_count,
limit: 10,
offset: 0,
has_more,
}
#[test]
fn totals_come_from_the_pagination() {
let info = info(42, true);
assert!(matches!(page_totals(Some(&info)), Ok((42, true))));
fn missing_pagination_is_internal() {
assert!(matches!(page_totals(None), Err(Failure::Internal(_))));
fn negative_total_is_internal() {
let info = info(-1, false);
assert!(matches!(
page_totals(Some(&info)),
Err(Failure::Internal(_))
));
fn a_padded_note_key_is_the_row_note() {
let now = chrono::Utc::now();
let entity = FinanceEntity::Transaction(Transaction {
id: Uuid::new_v4(),
post_date: now,
enter_date: now,
});
let padded = Tag {
tag_name: "note ".to_string(),
tag_value: "lunch".to_string(),
description: None,
};
let tags = HashMap::from([(padded.tag_name.clone(), FinanceEntity::Tag(padded))]);
let shown = row(&entity, &tags, None, Tz::UTC).unwrap();
assert_eq!(shown.note, "lunch");