Cleaned up repository layer.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user