Lines
100 %
Functions
Branches
use super::*;
const PADDED: &str = "note\t";
async fn link_padded_note(pool: &PgPool, tx_id: Uuid, value: &str) -> anyhow::Result<()> {
let tag_id = Uuid::new_v4();
sqlx::query("INSERT INTO tags (id, tag_name, tag_value) VALUES ($1, $2, $3)")
.bind(tag_id)
.bind(PADDED)
.bind(value)
.execute(pool)
.await?;
sqlx::query("INSERT INTO transaction_tags (tx_id, tag_id) VALUES ($1, $2)")
.bind(tx_id)
Ok(())
}
#[local_db_sqlx_test]
async fn a_new_note_replaces_a_padded_stored_note(pool: PgPool) -> anyhow::Result<()> {
let fx = fixture().await?;
let tx_id = fx.create_tx(None).await?;
link_padded_note(&pool, tx_id, "old").await?;
UpdateTransaction::new()
.user_id(fx.user.id)
.transaction_id(tx_id)
.note("new".to_string())
.run()
assert_eq!(fx.tx_tags(tx_id).await?, vec![pair("note", "new")]);
async fn a_blank_note_removes_a_padded_stored_note(pool: PgPool) -> anyhow::Result<()> {
.note(" ".to_string())
assert!(fx.tx_tags(tx_id).await?.is_empty());
async fn replacing_the_tags_keeps_a_padded_stored_note(pool: PgPool) -> anyhow::Result<()> {
link_padded_note(&pool, tx_id, "kept").await?;
.tags(tag_map(&[("cat", "food")]))
assert_eq!(
fx.tx_tags(tx_id).await?,
vec![pair("cat", "food"), pair(PADDED, "kept")]
);