1
//! Saving a tag twice from one edit page: the second save must not be stale.
2

            
3
use anyhow::{Result, anyhow, ensure};
4
use server::command::{CmdResult, tag::CreateTag};
5
use uuid::Uuid;
6

            
7
use super::harness::{Harness, with_harness};
8
use super::page::{login, open, set_text, submit};
9

            
10
1
async fn tag(h: &Harness) -> Result<Uuid> {
11
1
    let created = CreateTag::new()
12
1
        .user_id(h.tenant.id)
13
1
        .name("kind".to_string())
14
1
        .value("fiat".to_string())
15
1
        .run()
16
1
        .await
17
        .map_err(|e| anyhow!("{e:?}"))?;
18
1
    match created {
19
1
        Some(CmdResult::Uuid(id)) => Ok(id),
20
        other => Err(anyhow!("unexpected create result {other:?}")),
21
    }
22
1
}
23

            
24
1
async fn save_twice(h: &Harness) -> Result<()> {
25
1
    let id = tag(h).await?;
26
1
    login(h).await?;
27
1
    open(h, &format!("/tag/edit/{id}")).await?;
28
1
    for value in ["crypto", "stock"] {
29
2
        set_text(h, "value", value).await?;
30
2
        let reply = submit(h).await?;
31
2
        ensure!(reply.starts_with("Tag updated"), "{reply}");
32
    }
33
1
    Ok(())
34
1
}
35

            
36
#[supp_macro::shared_runtime_test]
37
1
async fn a_second_tag_save_from_the_same_page_is_not_stale() -> Result<()> {
38
1
    with_harness(|h| Box::pin(save_twice(h))).await
39
}