Lines
100 %
Functions
Branches
use super::*;
#[local_db_sqlx_test]
async fn test_edit_replaces_symbol_name_and_tags(pool: PgPool) -> Result<(), anyhow::Error> {
let fx = fixture().await?;
let commodity = fx.commodity("OLD", "Old name").await?;
fx.set_tag(commodity, "kind", "stock").await?;
fx.set_tag(commodity, "color", "red").await?;
let revision = fx.revision(commodity).await?;
fx.edit(
commodity,
("NEW", "New name"),
vec![tag("kind", "bond"), tag("isin", "X1")],
revision,
)
.await?;
assert_eq!(
pairs(&fx.stored(commodity).await?),
[
("isin", "X1"),
("kind", "bond"),
("name", "New name"),
("symbol", "NEW")
]
);
}
async fn test_edit_without_changes_is_a_no_op(pool: PgPool) -> Result<(), anyhow::Error> {
let commodity = fx.commodity("USD", "Dollar").await?;
fx.set_tag(commodity, "kind", "fiat").await?;
let before = fx.stored(commodity).await?;
let ids: Vec<Uuid> = before.tags.iter().map(|tag| tag.id).collect();
let others = before.tags.iter().filter(|t| t.tag_name == "kind").cloned();
("USD", "Dollar"),
others.collect(),
before.revision(),
let after = fx.stored(commodity).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_symbol_and_name(
pool: PgPool,
) -> Result<(), anyhow::Error> {
fx.edit(commodity, ("USD", "Dollar"), vec![], revision)
[("name", "Dollar"), ("symbol", "USD")]
async fn test_edit_changes_a_description(pool: PgPool) -> Result<(), anyhow::Error> {
let described = Tag {
description: Some("note".to_string()),
..tag("kind", "fiat")
};
fx.edit(commodity, ("USD", "Dollar"), vec![described], revision)
let stored = fx.stored(commodity).await?;
let kept = stored.tags.iter().find(|t| t.tag_name == "kind");
assert_eq!(kept.and_then(|t| t.description.as_deref()), Some("note"));
async fn test_edit_trims_the_symbol_name_and_tag_keys(pool: PgPool) -> Result<(), anyhow::Error> {
(" EUR ", " Euro "),
vec![tag(" kind ", " coin ")],
[("kind", "coin"), ("name", "Euro"), ("symbol", "EUR")]
async fn test_edit_removes_and_replaces_tags_stored_with_padded_names(
link_raw(&pool, commodity, " note", "x").await?;
link_raw(&pool, commodity, "symbol ", "OLD").await?;
fx.edit(commodity, ("EUR", "Dollar"), vec![], revision)
[("name", "Dollar"), ("symbol", "EUR")]