Lines
100 %
Functions
Branches
use forms::Source;
use server::user::User;
use sqlx::PgPool;
use super::form_options;
use super::test_seed::seed_user;
use crate::forms::options;
#[sqlx::test(migrator = "server::db::MIGRATOR")]
async fn templates_are_listed_by_name_with_unnamed_last(pool: PgPool) -> anyhow::Result<()> {
let _guard = server::db::install_test_pool(pool.clone());
let user_id = seed_user(&pool).await?;
let user = User { id: user_id };
let unnamed = user.create_template("(a)".into(), None).await?;
let rent = user
.create_template("(b)".into(), Some("rent".into()))
.await?;
let odd = user
.create_template("(c)".into(), Some("a|b".into()))
let listed = options(user_id, Source::Templates).await?;
let seen: Vec<_> = listed.iter().map(|o| (o.id, o.label.as_str())).collect();
assert_eq!(seen, [(odd, "a¦b"), (rent, "rent"), (unnamed, "unnamed")]);
assert_eq!(
form_options(user_id, "templates").await?,
format!(
"((:id \"{odd}\" :label \"a¦b\" :alias \"a¦b\") \
(:id \"{rent}\" :label \"rent\" :alias \"rent\") \
(:id \"{unnamed}\" :label \"unnamed\" :alias \"unnamed\"))"
)
);
Ok(())
}
async fn no_templates_is_an_empty_list(pool: PgPool) -> anyhow::Result<()> {
assert_eq!(form_options(user_id, "templates").await?, "()");
assert!(form_options(user_id, "nope").await.is_err());
async fn templates_sharing_a_name_get_distinct_labels(pool: PgPool) -> anyhow::Result<()> {
user.create_template("(a)".into(), Some("rent".into()))
user.create_template("(b)".into(), Some("rent".into()))
assert_eq!(listed.len(), 2);
assert!(listed[0].id < listed[1].id);
for option in &listed {
let prefix = &option.id.simple().to_string()[..4];
assert_eq!(option.label, format!("rent ‹{prefix}›"));