let test_client_with_eio () = (* Create test authentication *) let auth = Zulip.Auth.create ~server_url:"https://test.zulipchat.com" ~email:"test@example.com" ~api_key:"test-key" in (* Test client creation - using () as mock env for now *) let client = Zulip.Client.create () auth in (* Verify client has correct server URL via pretty printing *) let pp_result = Format.asprintf "%a" Zulip.Client.pp client in Alcotest.(check string) "client server url" "Client(server=https://test.zulipchat.com)" pp_result; (* Test with_client resource management *) let result = Zulip.Client.with_client () auth @@ fun client -> Format.asprintf "%a" Zulip.Client.pp client in Alcotest.(check string) "with_client resource management" "Client(server=https://test.zulipchat.com)" result let test_auth_from_toml_eio () = (* Create temporary TOML file *) let temp_file = Filename.temp_file "test_auth" ".toml" in let toml_content = {| [api] email = "eio-test@example.com" key = "eio-api-key-12345" site = "https://eio-test.zulipchat.com" |} in let oc = open_out temp_file in output_string oc toml_content; close_out oc; (* Test loading authentication from TOML *) (match Zulip.Auth.from_zuliprc ~path:temp_file () with | Ok auth -> Alcotest.(check string) "email" "eio-test@example.com" (Zulip.Auth.email auth); Alcotest.(check string) "server_url" "https://eio-test.zulipchat.com" (Zulip.Auth.server_url auth); (* Test client creation with loaded auth *) let client = Zulip.Client.create () auth in let pp_result = Format.asprintf "%a" Zulip.Client.pp client in Alcotest.(check string) "loaded auth client" "Client(server=https://eio-test.zulipchat.com)" pp_result; Sys.remove temp_file | Error err -> Sys.remove temp_file; Alcotest.fail ("Auth loading failed: " ^ Zulip.Error.message err)) let test_message_creation_with_eio () = let auth = Zulip.Auth.create ~server_url:"https://test.zulipchat.com" ~email:"test@example.com" ~api_key:"test-key" in let _client = Zulip.Client.create () auth in (* Create a test message *) let message = Zulip.Message.create ~type_:`Channel ~to_:["general"] ~content:"EIO test message" ~topic:"Testing" () in (* Verify message properties *) Alcotest.(check (list string)) "message recipients" ["general"] (Zulip.Message.to_ message); Alcotest.(check string) "message content" "EIO test message" (Zulip.Message.content message); Alcotest.(check (option string)) "message topic" (Some "Testing") (Zulip.Message.topic message); (* Test message JSON serialization *) let json = Zulip.Message.to_json message in match json with | `O fields -> let content_field = List.assoc "content" fields in Alcotest.(check bool) "JSON content field" true (match content_field with `String "EIO test message" -> true | _ -> false) | _ -> Alcotest.fail "Message JSON should be an object" let test_mock_request () = let auth = Zulip.Auth.create ~server_url:"https://test.zulipchat.com" ~email:"test@example.com" ~api_key:"test-key" in let client = Zulip.Client.create () auth in (* Test mock EIO HTTP request *) (match Zulip.Client.request client ~method_:`GET ~path:"/messages" () with | Ok response -> (match response with | `O fields -> let result_field = List.assoc "result" fields in Alcotest.(check bool) "mock response result" true (match result_field with `String "success" -> true | _ -> false); let msg_field = List.assoc "msg" fields in Alcotest.(check bool) "mock response message" true (match msg_field with `String "Mock EIO response" -> true | _ -> false) | _ -> Alcotest.fail "Response should be JSON object") | Error err -> Alcotest.fail ("Request failed: " ^ Zulip.Error.message err)) let () = let open Alcotest in run "EIO Integration Tests" [ "client_eio", [ test_case "Client creation with EIO" `Quick test_client_with_eio; ]; "auth_eio", [ test_case "Auth from TOML with EIO" `Quick test_auth_from_toml_eio; ]; "message_eio", [ test_case "Message creation with EIO context" `Quick test_message_creation_with_eio; ]; "request_eio", [ test_case "Mock HTTP request with EIO client" `Quick test_mock_request; ]; ]