For a public demo: no login on any address, everyone is "Demo visitor" (actor demo), a note at the top of every page, the back office's and the client's (#demo-note), and the invented demo data added at start when the database is empty (the server drops it every night). Every file upload is refused with a message (documents, the office photo, the client's uploads; a contract version keeps its text without the file), a mail server in its settings is refused, so nothing leaves it, and it needs a place for the files and their key (the demo's own files and the signed copies). seed-demo also runs in it. Sign out leads home. Checked: config test (address, files, no mail), tests/demo.rs (the note, an upload refused and nothing kept, a version with text only, the journal's actor), a local run on an empty database (seeds itself: 27 documents, the clients and contracts) and screenshots light and dark, desk and phone (PROBLEMS: 0).
94 lines
2.9 KiB
Rust
94 lines
2.9 KiB
Rust
//! The public demo (`VISA_DEMO=1`, demoapp.lannadesk.com): no login, a
|
|
//! note on every page, everything can be changed, but no file comes in.
|
|
|
|
use axum::http::StatusCode;
|
|
use sqlx::PgPool;
|
|
use visa::config::Auth;
|
|
|
|
use crate::common::{pdf, with_auth};
|
|
|
|
#[sqlx::test(migrator = "visa::db::MIGRATOR")]
|
|
async fn the_demo_says_so_and_takes_no_uploads(pool: PgPool) {
|
|
let app = with_auth(pool.clone(), Auth::Demo);
|
|
let today = visa::dates::today();
|
|
visa::seed::demo(&pool, today).await.unwrap();
|
|
visa::seed::legal::demo(&pool, app.st.files.as_ref(), today)
|
|
.await
|
|
.unwrap();
|
|
|
|
let t = app.get("/desk").await.text();
|
|
assert!(t.contains("id=\"demo-note\""), "{t}");
|
|
assert!(t.contains("Everyone here is a demo visitor"));
|
|
assert!(!t.contains("Sign out"));
|
|
|
|
// a document upload is refused, and nothing is kept
|
|
let person: i64 = sqlx::query_scalar("SELECT min(id) FROM people")
|
|
.fetch_one(&pool)
|
|
.await
|
|
.unwrap();
|
|
let docs = || async {
|
|
sqlx::query_scalar::<_, i64>("SELECT count(*) FROM documents")
|
|
.fetch_one(&pool)
|
|
.await
|
|
.unwrap()
|
|
};
|
|
let before = docs().await;
|
|
let scan = pdf("not in the demo");
|
|
let r = app
|
|
.upload(
|
|
&format!("/people/{person}/documents"),
|
|
&[("kind", "passport-photo-page")],
|
|
&[("scan.pdf", &scan)],
|
|
)
|
|
.await;
|
|
assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY);
|
|
assert!(
|
|
r.text().contains("Uploads are off in the demo"),
|
|
"{}",
|
|
r.text()
|
|
);
|
|
assert_eq!(docs().await, before);
|
|
|
|
// a contract's new version: the text is taken, a file is not
|
|
let contract: i64 = sqlx::query_scalar("SELECT min(id) FROM contracts")
|
|
.fetch_one(&pool)
|
|
.await
|
|
.unwrap();
|
|
let base = format!("/contracts/{contract}/versions");
|
|
let r = app
|
|
.upload(
|
|
&base,
|
|
&[("note", "Signed scan"), ("body", "# 1. Term\nOne year.")],
|
|
&[("signed.pdf", &scan)],
|
|
)
|
|
.await;
|
|
assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY);
|
|
assert!(
|
|
r.text()
|
|
.contains("Uploads are off in the demo. Paste the text")
|
|
);
|
|
let r = app
|
|
.upload(
|
|
&base,
|
|
&[
|
|
("note", "A visitor's change"),
|
|
("body", "# 1. Term\nOne year."),
|
|
],
|
|
&[],
|
|
)
|
|
.await;
|
|
assert_eq!(r.status, StatusCode::SEE_OTHER, "{}", r.text());
|
|
assert_eq!(docs().await, before);
|
|
|
|
// changes are the demo visitor's
|
|
let actor: String = sqlx::query_scalar("SELECT actor FROM journal ORDER BY seq DESC LIMIT 1")
|
|
.fetch_one(&pool)
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(actor, "demo");
|
|
// there is nobody to sign out
|
|
let r = app.post("/logout", &[]).await;
|
|
assert_eq!(r.status, StatusCode::SEE_OTHER);
|
|
assert_eq!(r.location(), "/desk");
|
|
}
|