tests: testing getting default logo

This commit is contained in:
Philippe Loctaux 2023-03-05 00:42:36 +01:00
parent a4ff4bca20
commit fa1498bb67
3 changed files with 53 additions and 1 deletions

View file

@ -15,6 +15,30 @@ async fn logo(mut db: Connection<Database>) -> Result<FileFromBytes> {
Ok(FileFromBytes::from(settings.business_logo()))
}
#[cfg(test)]
mod test {
use crate::tests::*;
#[test]
fn logo() {
// Setup http server
let client = setup_rocket_testing();
// Make request
let response = client.get(uri!(super::logo)).dispatch();
assert_eq!(response.status(), Status::Ok);
// Assert size of logo
let logo_length = response.into_bytes().expect("bytes containing logo").len();
use settings::DEFAULT_BUSINESS_LOGO;
assert_eq!(
logo_length,
DEFAULT_BUSINESS_LOGO.len(),
"Invalid logo size in bytes, value was `{logo_length}`",
);
}
}
#[get("/setup")]
async fn setup() -> Page {
Page::Setup()

View file

@ -0,0 +1,28 @@
use crate::rocket_setup;
use rocket::local::blocking::Client;
use rocket::{Build, Rocket};
pub use rocket::http::Status;
pub use rocket::uri;
fn rocket_with_memory_database() -> Rocket<Build> {
use rocket::figment::util::map;
use rocket::Config;
// Custom config
// - rocket defaults
// - from `Rocket.toml`
// - from env variables
// - from code below
let options = map!["url" => ":memory:"];
let config = Config::figment().merge(("databases", map!["ezidam" => &options]));
let rocket_builder = rocket::custom(config);
// Setup server
rocket_setup(rocket_builder)
}
pub fn setup_rocket_testing() -> Client {
Client::tracked(rocket_with_memory_database()).expect("valid rocket instance")
}

View file

@ -21,7 +21,7 @@ pub struct Settings {
}
const DEFAULT_BUSINESS_NAME: &str = "ezidam";
const DEFAULT_BUSINESS_LOGO: &[u8] = include_bytes!("../../../logo/ezidam.png");
pub const DEFAULT_BUSINESS_LOGO: &[u8] = include_bytes!("../../../logo/ezidam.png");
impl From<DatabaseSettings> for Settings {
fn from(db: DatabaseSettings) -> Self {