1
use super::*;
2

            
3
#[test]
4
2
fn a_busy_form_submit_is_a_409_with_the_conflict_message() {
5
2
    let message = "The data changed while saving; try again";
6
2
    let err = failure_error(
7
2
        "Transaction edit failed",
8
2
        Failure::Internal(rpc::host_failure::busy_condition(message)),
9
2
    );
10
2
    assert_eq!(err, WebError::new(StatusCode::CONFLICT, message));
11
2
}
12

            
13
#[test]
14
2
fn a_form_submit_on_a_deleted_entity_is_a_404() {
15
2
    let message = "Transaction not found";
16
2
    let err = failure_error(
17
2
        "Transaction edit failed",
18
2
        Failure::Internal(rpc::host_failure::not_found_condition(message, None)),
19
2
    );
20
2
    assert_eq!(err, WebError::not_found(message));
21
2
}
22

            
23
#[test]
24
2
fn a_form_native_condition_answers_with_its_own_status() {
25
2
    let args = failure_error(
26
2
        "Tag set failed",
27
2
        Failure::Internal(rpc::natives::forms::args_error("blank tag")),
28
2
    );
29
2
    assert_eq!(args, WebError::bad_request("blank tag"));
30
2
}
31

            
32
#[test]
33
2
fn a_form_submit_on_an_unreachable_database_is_a_503_not_an_internal_error() {
34
2
    let message = "No connection-pool slot became free in time";
35
2
    let err = failure_error(
36
2
        "Transaction create failed",
37
2
        Failure::Internal(rpc::host_failure::unavailable_condition(message)),
38
2
    );
39
2
    assert_eq!(
40
2
        err,
41
2
        WebError::unavailable("The service is temporarily unavailable")
42
    );
43
2
}
44

            
45
#[test]
46
2
fn a_form_submit_fault_is_logged_once_by_the_web_edge() {
47
2
    let captured = server::log_capture::Captured::default();
48
2
    let _logs = tracing::subscriber::set_default(captured.subscriber());
49

            
50
2
    let err = failure_error(
51
2
        "Transaction edit failed",
52
2
        Failure::Internal(std::io::Error::other("DATABASE_URL is not provided").into()),
53
2
    );
54

            
55
2
    assert_eq!(err.status, StatusCode::INTERNAL_SERVER_ERROR);
56
2
    assert_eq!(captured.error_lines(), 1);
57
2
}