Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 8 additions & 40 deletions crates/consolebook-server/tests/acknowledgments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! invented.

use axum::body::Body;
use axum::http::header::{CONTENT_TYPE, COOKIE, SET_COOKIE};
use axum::http::header::{CONTENT_TYPE, COOKIE};
use axum::http::{Request, StatusCode};
use consolebook_server::acknowledgments::{self, AckRefusal, AttestedKind, TraineeAckKind};
use consolebook_server::capabilities::{self, Capability, RoleBundle};
Expand All @@ -17,11 +17,11 @@ use consolebook_server::programs::{
RecordType, ScaleDef, ScaleKind, VersionContent,
};
use consolebook_server::training_sessions::{self, Disposition, SessionInput};
use consolebook_server::{assignments, data_dir::DataDir, enrollments, setup, storage, users};
use consolebook_server::{assignments, data_dir::DataDir, enrollments, setup, storage};
use http_body_util::BodyExt;
use tower::ServiceExt;

const PASSWORD: &str = "invented-passphrase-1";
mod support;

/// Every rule off: an open draft seals directly, which keeps each test
/// record cheap — acknowledgment behavior is independent of how the
Expand Down Expand Up @@ -55,7 +55,7 @@ impl Fixture {
"Example County Communications",
"avery.admin",
"Avery Admin",
PASSWORD,
support::password(),
)
.await
.expect("initialize")
Expand All @@ -72,34 +72,11 @@ impl Fixture {
}

async fn login(&self, username: &str, password: &str) -> String {
let response = self
.app()
.oneshot(
Request::builder()
.method("POST")
.uri("/api/auth/login")
.header(CONTENT_TYPE, "application/json")
.body(Body::from(
serde_json::json!({ "username": username, "password": password })
.to_string(),
))
.expect("request"),
)
.await
.expect("response");
assert_eq!(response.status(), StatusCode::OK, "login {username}");
let cookie = response
.headers()
.get(SET_COOKIE)
.expect("cookie")
.to_str()
.expect("ascii");
let (pair, _) = cookie.split_once(';').expect("attrs");
pair.split_once('=').expect("pair").1.to_string()
support::login(self.app(), username, password).await
}

async fn user_with_role(&self, username: &str, display_name: &str, role: RoleBundle) -> i64 {
let created = users::create_with_reset_code(
support::user_with_role(
&self.pool,
self.admin_id,
username,
Expand All @@ -109,15 +86,6 @@ impl Fixture {
role,
)
.await
.expect("create")
.expect("accepted");
assert_eq!(
users::use_reset_code(&self.pool, username, &created.reset_code.raw, PASSWORD)
.await
.expect("reset"),
users::ResetOutcome::Done
);
created.id
}

async fn notice_count(&self, user_id: i64, kind: &str) -> i64 {
Expand Down Expand Up @@ -832,8 +800,8 @@ async fn acknowledgment_api_round_trip() {
// A second, unfinalized draft stays out of the trainee's reach.
let open_id = draft_for(&fx, s.jordan_id, s.enrollment_id, "2026-06-03").await;

let taylor = fx.login("taylor.api", PASSWORD).await;
let casey = fx.login("casey.api", PASSWORD).await;
let taylor = fx.login("taylor.api", support::password()).await;
let casey = fx.login("casey.api", support::password()).await;

let (status, body) = request(fx.app(), "GET", "/api/my/records", Some(&taylor), None).await;
assert_eq!(status, StatusCode::OK);
Expand Down
50 changes: 8 additions & 42 deletions crates/consolebook-server/tests/amendments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! contract raw. Every fixture is invented.

use axum::body::Body;
use axum::http::header::{CONTENT_TYPE, COOKIE, SET_COOKIE};
use axum::http::header::{CONTENT_TYPE, COOKIE};
use axum::http::{Request, StatusCode};
use consolebook_server::acknowledgments::{self, TraineeAckKind};
use consolebook_server::amendments::{self, AmendRefusal};
Expand All @@ -20,13 +20,11 @@ use consolebook_server::programs::{
RecordType, ScaleDef, ScaleKind, VersionContent,
};
use consolebook_server::training_sessions::{self, Disposition, SessionInput};
use consolebook_server::{
assignments, canonical, data_dir::DataDir, enrollments, setup, storage, users,
};
use consolebook_server::{assignments, canonical, data_dir::DataDir, enrollments, setup, storage};
use http_body_util::BodyExt;
use tower::ServiceExt;

const PASSWORD: &str = "invented-passphrase-1";
mod support;

const OPEN_POLICY: PolicyDef = PolicyDef {
review_approved: false,
Expand Down Expand Up @@ -63,7 +61,7 @@ impl Fixture {
"Example County Communications",
"avery.admin",
"Avery Admin",
PASSWORD,
support::password(),
)
.await
.expect("initialize")
Expand All @@ -80,34 +78,11 @@ impl Fixture {
}

async fn login(&self, username: &str, password: &str) -> String {
let response = self
.app()
.oneshot(
Request::builder()
.method("POST")
.uri("/api/auth/login")
.header(CONTENT_TYPE, "application/json")
.body(Body::from(
serde_json::json!({ "username": username, "password": password })
.to_string(),
))
.expect("request"),
)
.await
.expect("response");
assert_eq!(response.status(), StatusCode::OK, "login {username}");
let cookie = response
.headers()
.get(SET_COOKIE)
.expect("cookie")
.to_str()
.expect("ascii");
let (pair, _) = cookie.split_once(';').expect("attrs");
pair.split_once('=').expect("pair").1.to_string()
support::login(self.app(), username, password).await
}

async fn user_with_role(&self, username: &str, display_name: &str, role: RoleBundle) -> i64 {
let created = users::create_with_reset_code(
support::user_with_role(
&self.pool,
self.admin_id,
username,
Expand All @@ -117,15 +92,6 @@ impl Fixture {
role,
)
.await
.expect("create")
.expect("accepted");
assert_eq!(
users::use_reset_code(&self.pool, username, &created.reset_code.raw, PASSWORD)
.await
.expect("reset"),
users::ResetOutcome::Done
);
created.id
}

async fn notice_count(&self, user_id: i64, kind: &str) -> i64 {
Expand Down Expand Up @@ -863,8 +829,8 @@ async fn amendment_api_round_trip() {
.await
.expect("call")
.expect("sealed");
let casey = fx.login("casey.api", PASSWORD).await;
let taylor = fx.login("taylor.api", PASSWORD).await;
let casey = fx.login("casey.api", support::password()).await;
let taylor = fx.login("taylor.api", support::password()).await;

let (status, body) = request(
fx.app(),
Expand Down
Loading
Loading