//! Consumer of the generated crate, compiled and run by `cargo test` inside //! that crate. Every path, signature and re-export named here has to resolve //! for the file to build at all. use fixture_client::contexts::user::{fetch_user_context, UserContextData, UserContextParams}; use fixture_client::functions::echo::call_echo; use fixture_client::functions::find_user::call_find_user; use fixture_client::functions::rename_user::call_rename_user; use fixture_client::functions::whoami::call_whoami; use fixture_client::mutations::update_profile::call_update_profile; use fixture_client::types::{ EchoInput, EchoOutput, FindUserInput, FindUserOutput, OrderOutput, RenameUserInput, RenameUserOutput, UpdateProfileInput, UpdateProfileOutput, UserOrdersOutput, UserProfileOutput, WhoamiOutput, }; use fixture_client::{MizanClient, MizanConfig, MizanError}; async fn every_generated_entry_point(client: &MizanClient) -> Result<(), MizanError> { let echoed: EchoOutput = call_echo( client, &EchoInput { text: "hello".to_string() }, ).await?; let identity: WhoamiOutput = call_whoami(client).await?; let found: Option = call_find_user( client, &FindUserInput { user_id: 1 }, ).await?; let renamed: RenameUserOutput = call_rename_user( client, &RenameUserInput { user_id: 1, name: "renamed".to_string() }, ).await?; let updated: UpdateProfileOutput = call_update_profile( client, &UpdateProfileInput { user_id: 1, name: "renamed".to_string() }, ).await?; let bundle: UserContextData = fetch_user_context( client, &UserContextParams { user_id: 1 }, ).await?; let orders: UserOrdersOutput = bundle.user_orders; let profile: UserProfileOutput = bundle.user_profile; println!( "{} {} {} {} {} {} {}", echoed.message, identity.authenticated, found.is_some(), renamed.name, updated.ok, orders.len(), profile.name, ); Ok(()) } #[test] fn generated_entry_points_build_a_callable_future() { let client = MizanClient::new(MizanConfig { base_url: "http://127.0.0.1:9/api/mizan".to_string(), session: false, ..MizanConfig::default() }); drop(every_generated_entry_point(&client)); } #[test] fn generated_types_decode_the_wire_shape() { let raw = r#"{ "user_orders": [{"id": 7, "user_id": 1, "total": 42}], "user_profile": {"user_id": 1, "name": "ryth"} }"#; let bundle: UserContextData = serde_json::from_str(raw).expect("context bundle decodes"); assert_eq!(bundle.user_profile.user_id, 1); assert_eq!(bundle.user_profile.name, "ryth"); assert_eq!(bundle.user_orders.len(), 1); let order: &OrderOutput = &bundle.user_orders[0]; assert_eq!(order.id, 7); assert_eq!(order.total, 42); let echoed: EchoOutput = serde_json::from_str(r#"{"message": "hi"}"#).expect("echo output decodes"); assert_eq!(echoed.message, "hi"); let encoded = serde_json::to_string(&EchoInput { text: "hi".to_string() }) .expect("echo input encodes"); assert_eq!(encoded, r#"{"text":"hi"}"#); }