Martin Berg Alstad 5d5e6393ac First working API.
Simple auth by creating sessions and storing in db
2024-08-29 16:43:04 +02:00

35 lines
831 B
Rust

use lib::axum::wrappers::Count;
use lib::diesel_crud_trait::CrudError;
pub(crate) fn map_count(count: Result<usize, CrudError>) -> Result<Count, CrudError> {
match count {
Ok(0) => Err(CrudError::NotFound),
Ok(n) => Ok(n.into()),
Err(err) => Err(err),
}
}
#[cfg(test)]
mod tests {
use super::*;
use lib::diesel_crud_trait::CrudError;
#[test]
fn test_map_count_0_is_not_found() {
assert_eq!(map_count(Ok(0)), Err(CrudError::NotFound));
}
#[test]
fn test_map_count_n_is_count() {
assert_eq!(map_count(Ok(1)), Ok(1.into()));
}
#[test]
fn test_map_count_error_is_error() {
assert_eq!(
map_count(Err(CrudError::PoolError("error".to_string()))),
Err(CrudError::PoolError("error".to_string()))
);
}
}