Lines
100 %
Functions
Branches
use super::*;
#[local_db_sqlx_test]
async fn test_edit_renames_reparents_and_replaces_tags(pool: PgPool) -> Result<(), anyhow::Error> {
let fx = fixture().await?;
let parent = fx.account("Parent", None).await?;
let account = fx.account("Old", None).await?;
fx.set_tag(account, "type", "asset").await?;
fx.set_tag(account, "color", "red").await?;
let revision = fx.revision(account).await?;
fx.edit(
account,
"New",
Some(parent),
vec![tag("type", "bank"), tag("iban", "X1")],
revision,
)
.await?;
let stored = fx.stored(account).await?;
assert_eq!(stored.parent, Some(parent));
assert_eq!(
pairs(&stored),
[("iban", "X1"), ("name", "New"), ("type", "bank")]
);
}
async fn test_edit_without_changes_is_a_no_op(pool: PgPool) -> Result<(), anyhow::Error> {
let account = fx.account("Cash", None).await?;
let before = fx.stored(account).await?;
let ids: Vec<Uuid> = before.tags.iter().map(|tag| tag.id).collect();
let tags = before.tags.iter().filter(|t| t.tag_name != "name").cloned();
fx.edit(account, "Cash", None, tags.collect(), before.revision())
let after = fx.stored(account).await?;
assert_eq!(after.revision(), before.revision());
assert_eq!(after.tags.iter().map(|tag| tag.id).collect::<Vec<_>>(), ids);
async fn test_edit_without_tags_clears_them_but_keeps_the_name(
pool: PgPool,
) -> Result<(), anyhow::Error> {
fx.edit(account, "Cash", None, vec![], revision).await?;
assert_eq!(pairs(&fx.stored(account).await?), [("name", "Cash")]);
async fn test_edit_to_the_root_and_a_changed_description(
let account = fx.account("Child", Some(parent)).await?;
let described = Tag {
description: Some("kind".to_string()),
..tag("type", "asset")
};
fx.edit(account, "Child", None, vec![described], revision)
assert_eq!(stored.parent, None);
let kept = stored.tags.iter().find(|t| t.tag_name == "type");
assert_eq!(kept.and_then(|t| t.description.as_deref()), Some("kind"));
async fn test_edit_keys_tags_by_their_trimmed_names(pool: PgPool) -> Result<(), anyhow::Error> {
"Cash",
None,
vec![tag(" type ", " liability ")],
pairs(&fx.stored(account).await?),
[("name", "Cash"), ("type", "liability")]
async fn test_edit_removes_and_replaces_tags_stored_with_padded_names(
link_raw(&pool, account, " note", "x").await?;
link_raw(&pool, account, "type ", "old").await?;
fx.edit(account, "Cash", None, vec![tag("type", "new")], revision)
[("name", "Cash"), ("type", "new")]