From 69ccf0c398aed0c24ddec55840859345d2fed52f Mon Sep 17 00:00:00 2001 From: piquel Date: Sun, 22 Nov 2026 21:17:52 +0100 Subject: [PATCH] refactor(auth): the assets' tests live in a tests.rs beside them --- .../src/{assets.rs => assets/mod.rs} | 57 +++---------------- apps/auth-service/src/assets/tests.rs | 42 ++++++++++++++ 2 files changed, 50 insertions(+), 49 deletions(-) rename apps/auth-service/src/{assets.rs => assets/mod.rs} (61%) create mode 100644 apps/auth-service/src/assets/tests.rs diff --git a/apps/auth-service/src/assets.rs b/apps/auth-service/src/assets/mod.rs similarity index 61% rename from apps/auth-service/src/assets.rs rename to apps/auth-service/src/assets/mod.rs index a8d708e02..9c88df6bc 100644 --- a/apps/auth-service/src/assets.rs +++ b/apps/auth-service/src/assets/mod.rs @@ -16,24 +16,24 @@ impl EmbeddedAssets { pub(crate) const STYLESHEET: Asset = sourceorigin_ui::STYLESHEET; /// The passkey script, which runs the pages' passkey ceremonies. pub(crate) const SCRIPT: Asset = - Asset::script("passkey", include_bytes!("../assets/passkey.js")); + Asset::script("passkey", include_bytes!("../../assets/passkey.js")); /// The picture script, which lets the profile's picture form choose its crop. pub(crate) const PICTURE_SCRIPT: Asset = - Asset::script("picture", include_bytes!("../assets/picture.js")); + Asset::script("picture", include_bytes!("../../assets/picture.js")); /// The search script, which ranks the top bar's results as the user types and /// refreshes a live form's results; auth's pages and the dashboard's both /// load it. pub(crate) const SEARCH_SCRIPT: Asset = - Asset::script("search", include_bytes!("../assets/search.js")); + Asset::script("search", include_bytes!("../../assets/search.js")); /// The copy script, whose buttons, and the values beside them, copy a value /// to the clipboard; auth's pages and the dashboard's both load it. pub(crate) const COPY_SCRIPT: Asset = - Asset::script("copy", include_bytes!("../assets/copy.js")); + Asset::script("copy", include_bytes!("../../assets/copy.js")); /// The client form script, which switches a new client's scopes and refresh /// tokens to the defaults of the kind chosen; auth's pages and the /// dashboard's both load it. pub(crate) const CLIENT_FORM_SCRIPT: Asset = - Asset::script("client-form", include_bytes!("../assets/client-form.js")); + Asset::script("client-form", include_bytes!("../../assets/client-form.js")); /// The scripts every page of auth's own loads. pub(crate) const SCRIPTS: [Asset; 5] = [ Self::SCRIPT, @@ -45,7 +45,7 @@ impl EmbeddedAssets { /// The admin dashboard's script, which confirms it with a passkey in a /// dialog on its page. Auth's own pages never load it. pub(crate) const DASHBOARD_SCRIPT: Asset = - Asset::script("dashboard", include_bytes!("../assets/dashboard.js")); + Asset::script("dashboard", include_bytes!("../../assets/dashboard.js")); /// The scripts every dashboard page loads. pub(crate) const DASHBOARD_SCRIPTS: [Asset; 4] = [ Self::DASHBOARD_SCRIPT, @@ -77,47 +77,6 @@ impl EmbeddedAssets { } } +/// Focused coverage of embedded file serving. #[cfg(test)] -mod tests { - //! Focused coverage of embedded file serving. - use super::*; - - /// The pages' stylesheet, typefaces and scripts are served at the paths - /// naming their content or version, as their own type, so they are cached - /// forever. - #[test] - fn the_pages_files_are_immutable() { - for (asset, content_type) in [ - (EmbeddedAssets::STYLESHEET, "text/css; charset=utf-8"), - (EmbeddedAssets::SCRIPT, "text/javascript; charset=utf-8"), - ( - EmbeddedAssets::PICTURE_SCRIPT, - "text/javascript; charset=utf-8", - ), - ( - EmbeddedAssets::DASHBOARD_SCRIPT, - "text/javascript; charset=utf-8", - ), - ( - EmbeddedAssets::SEARCH_SCRIPT, - "text/javascript; charset=utf-8", - ), - ( - EmbeddedAssets::COPY_SCRIPT, - "text/javascript; charset=utf-8", - ), - ( - EmbeddedAssets::CLIENT_FORM_SCRIPT, - "text/javascript; charset=utf-8", - ), - (sourceorigin_ui::FONTS[0], "font/woff2"), - ] { - let response = EmbeddedAssets::serve(&asset.path()).expect("found"); - assert_eq!(response.headers()[header::CONTENT_TYPE], content_type); - assert_eq!( - response.extensions().get::(), - Some(&CacheClass::Immutable) - ); - } - } -} +mod tests; diff --git a/apps/auth-service/src/assets/tests.rs b/apps/auth-service/src/assets/tests.rs new file mode 100644 index 000000000..68ee0fe84 --- /dev/null +++ b/apps/auth-service/src/assets/tests.rs @@ -0,0 +1,42 @@ +//! Focused coverage of embedded file serving. + +use super::*; + +/// The pages' stylesheet, typefaces and scripts are served at the paths +/// naming their content or version, as their own type, so they are cached +/// forever. +#[test] +fn the_pages_files_are_immutable() { + for (asset, content_type) in [ + (EmbeddedAssets::STYLESHEET, "text/css; charset=utf-8"), + (EmbeddedAssets::SCRIPT, "text/javascript; charset=utf-8"), + ( + EmbeddedAssets::PICTURE_SCRIPT, + "text/javascript; charset=utf-8", + ), + ( + EmbeddedAssets::DASHBOARD_SCRIPT, + "text/javascript; charset=utf-8", + ), + ( + EmbeddedAssets::SEARCH_SCRIPT, + "text/javascript; charset=utf-8", + ), + ( + EmbeddedAssets::COPY_SCRIPT, + "text/javascript; charset=utf-8", + ), + ( + EmbeddedAssets::CLIENT_FORM_SCRIPT, + "text/javascript; charset=utf-8", + ), + (sourceorigin_ui::FONTS[0], "font/woff2"), + ] { + let response = EmbeddedAssets::serve(&asset.path()).expect("found"); + assert_eq!(response.headers()[header::CONTENT_TYPE], content_type); + assert_eq!( + response.extensions().get::(), + Some(&CacheClass::Immutable) + ); + } +}