use actix_web::{test, App, http::StatusCode, web}; use tera::Tera; use threefold_marketplace::config::builder::{init_app_config, ConfigurationBuilder}; use threefold_marketplace::routes::configure_routes; use threefold_marketplace::utils; #[actix_rt::test] async fn test_rent_product_returns_404_when_mocks_disabled() { // Initialize global config with mocks disabled before app starts let mut cfg = ConfigurationBuilder::testing().build(); cfg.enable_mock_data = false; // It's okay if already set in other tests; if set, this will Err and we skip let _ = init_app_config(cfg); // Initialize Tera templates and register custom functions (mirror main.rs) let mut tera = Tera::new("src/views/**/*.html").expect("failed to load templates"); utils::register_tera_functions(&mut tera); let app = test::init_service( App::new() .app_data(web::Data::new(tera)) .configure(configure_routes) ).await; let req = test::TestRequest::post() .uri("/api/products/test-product/rent") .set_json(&serde_json::json!({ "duration": "monthly" })) .to_request(); let resp = test::call_service(&app, req).await; assert_eq!(resp.status(), StatusCode::NOT_FOUND); } #[actix_rt::test] async fn test_marketplace_dashboard_loads_with_mocks_disabled() { // Initialize global config with mocks disabled before app starts let mut cfg = ConfigurationBuilder::testing().build(); cfg.enable_mock_data = false; let _ = init_app_config(cfg); // Initialize Tera templates and register custom functions (mirror main.rs) let mut tera = Tera::new("src/views/**/*.html").expect("failed to load templates"); utils::register_tera_functions(&mut tera); let app = test::init_service( App::new() .app_data(web::Data::new(tera)) .configure(configure_routes) ).await; let req = test::TestRequest::get() .uri("/marketplace") .to_request(); let resp = test::call_service(&app, req).await; assert_eq!(resp.status(), StatusCode::OK); }