1
use sqlx::PgPool;
2
use supp_macro::local_db_sqlx_test;
3

            
4
use super::*;
5
use crate::db::install_test_pool;
6
use crate::lossless::seed;
7

            
8
2
async fn setup() {}
9

            
10
#[local_db_sqlx_test]
11
async fn a_snapshot_holds_everything_of_the_transaction(pool: PgPool) -> anyhow::Result<()> {
12
    let fixture = seed(&pool).await?;
13
    let user = User { id: fixture.user };
14
    let Some(snapshot) = user.transaction_snapshot(fixture.transaction).await? else {
15
        anyhow::bail!("the seeded transaction is missing");
16
    };
17
    assert_eq!(snapshot.transaction.id, fixture.transaction);
18
    assert_eq!(snapshot.splits.len(), 4);
19
    assert_eq!(snapshot.split_tags.len(), snapshot.splits.len());
20
    assert!(!snapshot.tags.is_empty());
21
    let splits = user.get_transaction_splits(fixture.transaction).await?;
22
    assert_eq!(
23
4
        snapshot.splits.iter().map(|s| s.id).collect::<Vec<_>>(),
24
4
        splits.iter().map(|s| s.id).collect::<Vec<_>>()
25
    );
26
}
27

            
28
#[local_db_sqlx_test]
29
async fn a_missing_transaction_has_no_snapshot(pool: PgPool) -> anyhow::Result<()> {
30
    let fixture = seed(&pool).await?;
31
    let user = User { id: fixture.user };
32
    assert!(user.transaction_snapshot(Uuid::new_v4()).await?.is_none());
33
}