#![warn(missing_docs)]
pub mod apps;
pub mod signals;
#[cfg(native)]
pub mod builder;
#[cfg(native)]
pub mod discovery;
#[cfg(native)]
pub mod hooks;
#[cfg(native)]
pub mod registry;
#[cfg(native)]
pub mod validation;
pub use reinhardt_http::{Request, Response, StreamBody, StreamingResponse};
#[cfg(native)]
#[allow(deprecated)]
pub use reinhardt_conf::settings::{DatabaseConfig, MiddlewareConfig, Settings, TemplateConfig};
pub use reinhardt_core::exception::{Error, Result};
#[cfg(native)]
pub use reinhardt_server::{HttpServer, serve};
pub use reinhardt_http::{Handler, Middleware, MiddlewareChain};
#[cfg(native)]
pub use inventory;
#[cfg(native)]
pub use apps::{
AppCommandConfig, AppLocaleConfig, AppMediaConfig, AppStaticFilesConfig, AppVendorAsset,
BaseCommand, get_app_commands, get_app_locales, get_app_media, get_app_static_files,
};
pub use apps::{
AppConfig, AppError, AppLabel, AppResult, Apps, LocaleProvider, MediaProvider,
StaticFilesProvider,
};
#[cfg(native)]
pub use builder::{
Application, ApplicationBuilder, ApplicationDatabaseConfig, BuildError, BuildResult,
RouteConfig,
};
#[cfg(native)]
pub use registry::{
MODELS, ModelMetadata, RELATIONSHIPS, RelationshipMetadata, RelationshipType,
ReverseRelationMetadata, ReverseRelationType, finalize_reverse_relations, find_model,
get_models_for_app, get_registered_models, get_registered_relationships,
get_relationships_for_model, get_relationships_to_model, get_reverse_relations_for_model,
register_reverse_relation,
};
#[cfg(native)]
pub use discovery::{
MigrationMetadata, RelationMetadata, RelationType, build_reverse_relations,
create_reverse_relation, discover_all_models, discover_migrations, discover_models,
};
#[cfg(native)]
pub use validation::{
ValidationError, ValidationResult, check_circular_relationships, check_duplicate_model_names,
check_duplicate_table_names, validate_registry,
};
#[cfg(test)]
mod tests {
use super::*;
use bytes::Bytes;
use hyper::{HeaderMap, Method, Uri, Version};
#[test]
fn test_request_query_params() {
let uri = Uri::from_static("/test?foo=bar&baz=qux");
let request = Request::builder()
.method(Method::GET)
.uri(uri)
.version(Version::HTTP_11)
.headers(HeaderMap::new())
.body(Bytes::new())
.build()
.unwrap();
assert_eq!(request.query_params.get("foo"), Some(&"bar".to_string()));
assert_eq!(request.query_params.get("baz"), Some(&"qux".to_string()));
}
#[test]
fn test_response_creation() {
let response = Response::ok();
assert_eq!(response.status, hyper::StatusCode::OK);
let response = Response::created();
assert_eq!(response.status, hyper::StatusCode::CREATED);
let response = Response::not_found();
assert_eq!(response.status, hyper::StatusCode::NOT_FOUND);
}
#[test]
fn test_response_with_json_unit() {
use serde_json::json;
let data = json!({
"message": "Hello, world!"
});
let response = Response::ok().with_json(&data).unwrap();
let body_str = String::from_utf8(response.body.to_vec()).unwrap();
let parsed: serde_json::Value = serde_json::from_str(&body_str).unwrap();
assert_eq!(parsed["message"], "Hello, world!");
assert_eq!(
response.headers.get(hyper::header::CONTENT_TYPE).unwrap(),
"application/json"
);
}
#[test]
fn test_error_status_codes() {
assert_eq!(Error::NotFound("test".into()).status_code(), 404);
assert_eq!(Error::Authentication("test".into()).status_code(), 401);
assert_eq!(Error::Authorization("test".into()).status_code(), 403);
assert_eq!(Error::Validation("test".into()).status_code(), 400);
assert_eq!(Error::Internal("test".into()).status_code(), 500);
}
}