1
use super::*;
2
use axum::http::StatusCode;
3

            
4
#[test]
5
2
fn the_report_gives_every_transaction_its_outcome() {
6
2
    let (written, untouched) = (Uuid::from_u128(1), Uuid::from_u128(2));
7
2
    let report = report(&[written, untouched], &[written]);
8
2
    let lines: Vec<&str> = report.lines().collect();
9
2
    assert_eq!(
10
2
        lines,
11
2
        [
12
2
            "Processed transactions: 2".to_string(),
13
2
            "Committed transactions: 1".to_string(),
14
2
            format!("{written}: committed"),
15
2
            format!("{untouched}: unchanged"),
16
2
        ]
17
    );
18
2
}
19

            
20
#[test]
21
2
fn script_failure_names_the_transaction_script_and_code() {
22
2
    let failure = TransactionFailure {
23
2
        transaction_id: Uuid::from_u128(7),
24
2
        script_id: Uuid::from_u128(5),
25
2
        code: "COMMODITY-MISMATCH".to_string(),
26
2
        message: "USD vs EUR".to_string(),
27
2
    };
28
2
    let err = script_failure(&failure);
29
2
    assert_eq!(err.status, StatusCode::UNPROCESSABLE_ENTITY);
30
2
    assert_eq!(
31
2
        err.message,
32
2
        format!(
33
            "{}: failed: script {}: COMMODITY-MISMATCH: USD vs EUR (nothing was written)",
34
2
            failure.transaction_id, failure.script_id
35
        )
36
    );
37
2
}