Lines
100 %
Functions
Branches
//! Creating an account with a name its parent already holds succeeds and
//! shows the duplicate-name notice; the rename side is in the manage tests.
use axum::{Router, body::Body, http::Request, http::StatusCode, routing::post};
use server::command::account_name::duplicate_name_notice;
use web::model::User;
use web::pages::account::create::account_create_submit;
use web::pages::forms::message::escaped;
use crate::common::create_mock_user;
use crate::common::new_page::{Reply, send_to};
use crate::common::tenant::provision_tenant;
async fn create(user: &User, name: &str) -> Reply {
let router = Router::new().route("/account/create/submit", post(account_create_submit));
let body = serde_urlencoded::to_string([("name", name)]).expect("urlencoded");
let request = Request::builder()
.method("POST")
.uri("/account/create/submit")
.header("content-type", "application/x-www-form-urlencoded")
.body(Body::from(body))
.expect("request");
send_to(router, user, request).await
}
#[supp_macro::shared_runtime_test]
async fn a_twin_create_succeeds_with_the_notice() {
let user = create_mock_user();
provision_tenant(user.id).await;
let first = create(&user, "Cafe").await;
let twin = create(&user, "Cafe").await;
let notice = escaped(&duplicate_name_notice("Cafe")).expect("renders");
assert_eq!(first.status, StatusCode::OK, "{}", first.body);
assert!(!first.body.contains(¬ice), "{}", first.body);
assert_eq!(twin.status, StatusCode::OK, "{}", twin.body);
assert!(twin.body.starts_with("New account id: "), "{}", twin.body);
assert!(twin.body.ends_with(&format!(". {notice}")), "{}", twin.body);
async fn a_markup_name_is_escaped_in_the_twin_reply() {
let name = "<img src=x onerror=1>";
create(&user, name).await;
let twin = create(&user, name).await;
assert!(!twin.body.contains("<img"), "{}", twin.body);
assert!(twin.body.contains("<img"), "{}", twin.body);