Lines
97.83 %
Functions
100 %
Branches
//! Multi-split transactions created through the page: every row is one
//! independent pair, with and without a tag on one of its legs.
use anyhow::{Result, ensure};
use super::checks::check_page;
use super::harness::{Harness, with_harness};
use super::page::{login, open, reply_id, submit};
use super::rows::{Split, fill_splits};
use super::store::{leg_tags, legs, snapshot};
/// Creates `splits` on a fresh create page and checks what was stored.
async fn create(h: &Harness, name: &str, splits: &[Split]) -> Result<()> {
open(h, "/transaction/new").await?;
fill_splits(h, splits).await?;
check_page(h, name, &[]).await?;
let reply = submit(h).await?;
ensure!(reply.contains("created with ID"), "{name}: {reply}");
let stored = snapshot(h, reply_id(&reply)?).await?;
let mut expected: Vec<String> = splits.iter().flat_map(|split| split.legs(h)).collect();
expected.sort();
ensure!(legs(&stored) == expected, "{name}: {stored:#?}");
let mut tags: Vec<String> = splits.iter().filter_map(|s| s.leg_tag(h)).collect();
tags.sort();
ensure!(leg_tags(&stored) == tags, "{name}: {stored:#?}");
check_page(h, &format!("{name}-created"), &[]).await
}
/// `splits` as typed, then again with a tag on the `to` leg of the first
/// row and the `from` leg of the last.
async fn create_both(h: &Harness, name: &str, splits: Vec<Split>) -> Result<()> {
login(h).await?;
create(h, name, &splits).await?;
let mut tagged = splits.clone();
if let Some(first) = tagged.first_mut() {
*first = first.tagged("to");
if let Some(last) = tagged.last_mut().filter(|_| splits.len() > 1) {
*last = last.tagged("from");
create(h, &format!("{name}-tagged"), &tagged).await
#[supp_macro::shared_runtime_test]
async fn one_from_account_pays_two_to_accounts() -> Result<()> {
with_harness(|h| {
Box::pin(create_both(
h,
"new-one-from-two-to",
vec![
Split::plain("Suica", "JR", "199"),
Split::plain("Suica", "McDonalds", "600"),
],
))
})
.await
async fn two_rows_with_different_from_accounts() -> Result<()> {
"new-two-from",
Split::plain("Wallet", "McDonalds", "500"),
async fn three_rows_store_three_pairs() -> Result<()> {
"new-three-rows",
Split::plain("Bank", "Suica", "3000"),
async fn a_converted_row_beside_a_same_currency_row() -> Result<()> {
let converted = Split {
commodity: "EUR",
to_commodity: Some("JPY"),
to_amount: Some("1600"),
..Split::plain("Bank", "Suica", "10")
};
"new-mixed-currency",
vec![converted, Split::plain("Suica", "JR", "199")],
async fn rows_in_two_currencies_without_a_conversion() -> Result<()> {
let euro = Split {
..Split::plain("Bank", "Wallet", "20")
"new-two-currencies",
vec![Split::plain("Suica", "JR", "199"), euro],