Lines
95.83 %
Functions
100 %
Branches
//! Each report command's parameter contract, pinned as golden text before the
//! reports move onto form descriptors (plan 0016 M3k). Set
//! `REPORT_FIXTURES_BLESS=1` to rewrite the fixtures after a deliberate change.
mod activity;
mod balance;
mod breakdown;
mod damage;
use tokio::sync::OnceCell;
use super::super::{CmdError, CmdResult, FilterEntity, ReportFilter};
use super::fixture::render::outcome;
use super::fixture::seed::{self, Ledger};
use crate::db::install_test_pool;
static CONTEXT: OnceCell<()> = OnceCell::const_new();
async fn setup() {
CONTEXT
.get_or_init(|| async { crate::telemetry::init_test_logging() })
.await;
}
/// One report's cases, rendered in order and compared with its fixture.
struct Golden {
file: &'static str,
text: String,
impl Golden {
fn new(file: &'static str) -> Self {
Self {
file,
text: String::new(),
fn case(&mut self, ledger: &Ledger, title: &str, result: Result<Option<CmdResult>, CmdError>) {
if !self.text.is_empty() {
self.text.push('\n');
self.text.push_str(&format!("== {title}\n"));
self.text.push_str(&outcome(ledger, result));
fn check(self) -> anyhow::Result<()> {
let path = format!(
"{}/tests/fixtures/reports/{}",
env!("CARGO_MANIFEST_DIR"),
self.file
);
if std::env::var_os("REPORT_FIXTURES_BLESS").is_some() {
std::fs::write(&path, &self.text)?;
return Ok(());
assert_eq!(std::fs::read_to_string(&path)?, self.text, "{path}");
Ok(())
async fn ledger() -> anyhow::Result<Ledger> {
let user = crate::user::User {
id: sqlx::types::Uuid::new_v4(),
};
user.commit().await?;
seed::seed(user).await
fn tag(entity: FilterEntity, name: &str, value: &str) -> ReportFilter {
ReportFilter::Tag {
entity,
name: name.to_owned(),
value: value.to_owned(),
fn account_type(value: &str) -> ReportFilter {
tag(FilterEntity::Account, "type", value)
fn project_home() -> ReportFilter {
tag(FilterEntity::Transaction, "project", "home")