Cleaned up repository layer.

This commit is contained in:
2026-10-26 12:31:04 +01:00
parent 2850f5c54b
commit 49194f07bf
10 changed files with 172 additions and 509 deletions
+10 -32
View File
@@ -144,32 +144,14 @@ fn encode(secret: UserAppSecret) -> UserAppSecretRow {
#[cfg(test)]
mod tests {
use chrono::{Duration, Utc};
use super::*;
fn row() -> UserAppSecretRow {
let created_at = Utc::now();
UserAppSecretRow {
id: Uuid::new_v4(),
app_id: Uuid::new_v4(),
secret_hash: vec![0; 32],
expires_at: created_at + Duration::days(1),
created_at,
}
}
fn foreign_key_violation(constraint: Constraint) -> DatabaseError {
DatabaseError::ForeignKeyViolation {
constraint,
source: sqlx::Error::Protocol("test database cause".to_owned()),
}
}
#[test]
fn classifies_user_app_secret_upsert_foreign_key_violation() {
let error = classify_upsert_error(foreign_key_violation(Constraint::UserAppSecretApp));
fn classifies_upsert_error_app_foreign_key_violation() {
let error = classify_upsert_error(DatabaseError::ForeignKeyViolation {
constraint: Constraint::UserAppSecretApp,
source: sqlx::Error::Protocol("test database cause".to_owned()),
});
assert!(matches!(
error,
RepositoryError::ReferenceViolation {
@@ -181,15 +163,11 @@ mod tests {
}
#[test]
fn keeps_unknown_upsert_foreign_keys_generic() {
let error = classify_upsert_error(foreign_key_violation(Constraint::Unnamed));
fn classifies_upsert_error_unknown_foreign_key_violation() {
let error = classify_upsert_error(DatabaseError::ForeignKeyViolation {
constraint: Constraint::Unnamed,
source: sqlx::Error::Protocol("test database cause".to_owned()),
});
assert!(matches!(error, RepositoryError::Database(_)));
}
#[test]
fn round_trips_through_rows() {
let secret = decode(row()).unwrap();
let round_trip = decode(encode(secret.clone())).unwrap();
assert_eq!(round_trip, secret);
}
}