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;
use crate::script::{compile_script, create_script};
#[sqlx::test(migrator = "server::db::MIGRATOR")]
async fn scripts_are_labelled_with_their_state(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 plain = create_script(&user, "(+ 1 2)".to_string(), Some("plain".to_string())).await?;
let off = create_script(&user, "(+ 1 2)".to_string(), Some("off".to_string())).await?;
user.set_script_enabled(off, false).await?;
let old = user
.create_script(compile_script("(+ 1 2)")?, Some("old".to_string()))
.await?;
user.set_script_enabled(old, false).await?;
let unnamed = create_script(&user, "(+ 1 2)".to_string(), None).await?;
let listed = options(user_id, Source::Scripts).await?;
let seen: Vec<_> = listed.iter().map(|o| (o.id, o.label.as_str())).collect();
assert_eq!(
seen,
[
(off, "off (disabled)"),
(old, "old (disabled, no source)"),
(plain, "plain"),
(unnamed, "unnamed"),
]
);
form_options(user_id, "scripts").await?,
format!(
"((:id \"{off}\" :label \"off (disabled)\" :alias \"off\") \
(:id \"{old}\" :label \"old (disabled, no source)\" :alias \"old\") \
(:id \"{plain}\" :label \"plain\" :alias \"plain\") \
(:id \"{unnamed}\" :label \"unnamed\" :alias \"unnamed\"))"
)
Ok(())
}
async fn a_bytecode_only_script_is_labelled_no_source(pool: PgPool) -> anyhow::Result<()> {
assert_eq!(listed.len(), 1);
(listed[0].id, listed[0].label.as_str()),
(old, "old (no source)")
async fn no_scripts_is_an_empty_list(pool: PgPool) -> anyhow::Result<()> {
assert_eq!(form_options(user_id, "scripts").await?, "()");