71 lines
1.8 KiB
Rust
71 lines
1.8 KiB
Rust
mod test_context;
|
|
mod test_requests;
|
|
use actix_web::body::MessageBody;
|
|
use actix_web::dev::ServiceResponse;
|
|
use actix_web::test;
|
|
use chrono::{NaiveDate, NaiveDateTime};
|
|
pub use test_context::{setup, teardown, DbTestContext};
|
|
pub use test_requests::RequestConfig;
|
|
pub use test_requests::{read_body, test_delete, test_get, test_post, test_put};
|
|
|
|
pub use actix_http::StatusCode;
|
|
|
|
macro_rules! assert_snapshot {
|
|
($x:expr) => {
|
|
insta::with_settings!({snapshot_path => "../../../snapshots"}, {
|
|
insta::assert_snapshot!($x);
|
|
});
|
|
};
|
|
}
|
|
|
|
macro_rules! assert_mail_snapshot {
|
|
($x:expr) => {
|
|
insta::with_settings!({filters => vec![
|
|
(r"[[:alnum:]]{40}", "boundary"),
|
|
("(?m)Date: .*$", "Date: Date")
|
|
]}, {
|
|
insta::assert_snapshot!($x);
|
|
});
|
|
};
|
|
}
|
|
|
|
pub(crate) use assert_mail_snapshot;
|
|
pub(crate) use assert_snapshot;
|
|
|
|
pub trait NaiveDateTimeExt {
|
|
fn from_ymd_and_hms(
|
|
year: i32,
|
|
month: u32,
|
|
day: u32,
|
|
hour: u32,
|
|
minute: u32,
|
|
second: u32,
|
|
) -> Option<NaiveDateTime>;
|
|
}
|
|
|
|
impl NaiveDateTimeExt for NaiveDateTime {
|
|
fn from_ymd_and_hms(
|
|
year: i32,
|
|
month: u32,
|
|
day: u32,
|
|
hour: u32,
|
|
minute: u32,
|
|
second: u32,
|
|
) -> Option<NaiveDateTime> {
|
|
NaiveDate::from_ymd_opt(year, month, day)?.and_hms_opt(hour, minute, second)
|
|
}
|
|
}
|
|
|
|
pub trait ServiceResponseExt {
|
|
async fn into_status_and_body(self) -> (StatusCode, String);
|
|
}
|
|
|
|
impl<B> ServiceResponseExt for ServiceResponse<B> where B: MessageBody {
|
|
async fn into_status_and_body(self) -> (StatusCode, String) {
|
|
let status = self.status();
|
|
let response = String::from_utf8(test::read_body(self).await.to_vec()).unwrap();
|
|
|
|
(status, response)
|
|
}
|
|
}
|