let test_auth_from_toml_string () = let toml_content = {| [api] email = "test@example.com" key = "test-api-key" site = "https://test.zulipchat.com" |} in (* Create a temporary file *) let temp_file = Filename.temp_file "zuliprc" ".toml" in let oc = open_out temp_file in output_string oc toml_content; close_out oc; (* Test parsing *) (match Zulip.Auth.from_zuliprc ~path:temp_file () with | Ok auth -> Alcotest.(check string) "email" "test@example.com" (Zulip.Auth.email auth); Alcotest.(check string) "server_url" "https://test.zulipchat.com" (Zulip.Auth.server_url auth); (* Clean up *) Sys.remove temp_file | Error err -> Sys.remove temp_file; Alcotest.fail ("Failed to parse TOML: " ^ Zulip.Error.message err)) let test_auth_from_toml_root_level () = let toml_content = {| email = "root@example.com" key = "root-api-key" site = "https://root.zulipchat.com" |} in let temp_file = Filename.temp_file "zuliprc" ".toml" in let oc = open_out temp_file in output_string oc toml_content; close_out oc; (match Zulip.Auth.from_zuliprc ~path:temp_file () with | Ok auth -> Alcotest.(check string) "email" "root@example.com" (Zulip.Auth.email auth); Alcotest.(check string) "server_url" "https://root.zulipchat.com" (Zulip.Auth.server_url auth); Sys.remove temp_file | Error err -> Sys.remove temp_file; Alcotest.fail ("Failed to parse root level TOML: " ^ Zulip.Error.message err)) let test_auth_missing_fields () = let toml_content = {| [api] email = "incomplete@example.com" # Missing key and site |} in let temp_file = Filename.temp_file "zuliprc" ".toml" in let oc = open_out temp_file in output_string oc toml_content; close_out oc; (match Zulip.Auth.from_zuliprc ~path:temp_file () with | Ok _ -> Sys.remove temp_file; Alcotest.fail "Should have failed with missing fields" | Error err -> Sys.remove temp_file; Alcotest.(check bool) "has config_missing error" true (String.contains (Zulip.Error.message err) 'M')) let () = let open Alcotest in run "TOML Support Tests" [ "auth_toml", [ test_case "Parse TOML with [api] section" `Quick test_auth_from_toml_string; test_case "Parse TOML with root level config" `Quick test_auth_from_toml_root_level; test_case "Handle missing required fields" `Quick test_auth_missing_fields; ]; ]