My agentic slop goes here. Not intended for anyone else!
1let test_client_with_eio () =
2 (* Create test authentication *)
3 let auth = Zulip.Auth.create
4 ~server_url:"https://test.zulipchat.com"
5 ~email:"test@example.com"
6 ~api_key:"test-key" in
7
8 (* Test client creation - using () as mock env for now *)
9 let client = Zulip.Client.create () auth in
10
11 (* Verify client has correct server URL via pretty printing *)
12 let pp_result = Format.asprintf "%a" Zulip.Client.pp client in
13 Alcotest.(check string) "client server url" "Client(server=https://test.zulipchat.com)" pp_result;
14
15 (* Test with_client resource management *)
16 let result = Zulip.Client.with_client () auth @@ fun client ->
17 Format.asprintf "%a" Zulip.Client.pp client in
18
19 Alcotest.(check string) "with_client resource management"
20 "Client(server=https://test.zulipchat.com)" result
21
22let test_auth_from_toml_eio () =
23 (* Create temporary TOML file *)
24 let temp_file = Filename.temp_file "test_auth" ".toml" in
25 let toml_content = {|
26[api]
27email = "eio-test@example.com"
28key = "eio-api-key-12345"
29site = "https://eio-test.zulipchat.com"
30|} in
31
32 let oc = open_out temp_file in
33 output_string oc toml_content;
34 close_out oc;
35
36 (* Test loading authentication from TOML *)
37 (match Zulip.Auth.from_zuliprc ~path:temp_file () with
38 | Ok auth ->
39 Alcotest.(check string) "email" "eio-test@example.com" (Zulip.Auth.email auth);
40 Alcotest.(check string) "server_url" "https://eio-test.zulipchat.com" (Zulip.Auth.server_url auth);
41
42 (* Test client creation with loaded auth *)
43 let client = Zulip.Client.create () auth in
44 let pp_result = Format.asprintf "%a" Zulip.Client.pp client in
45 Alcotest.(check string) "loaded auth client"
46 "Client(server=https://eio-test.zulipchat.com)" pp_result;
47
48 Sys.remove temp_file
49 | Error err ->
50 Sys.remove temp_file;
51 Alcotest.fail ("Auth loading failed: " ^ Zulip.Error.message err))
52
53let test_message_creation_with_eio () =
54 let auth = Zulip.Auth.create
55 ~server_url:"https://test.zulipchat.com"
56 ~email:"test@example.com"
57 ~api_key:"test-key" in
58
59 let _client = Zulip.Client.create () auth in
60
61 (* Create a test message *)
62 let message = Zulip.Message.create
63 ~type_:`Channel
64 ~to_:["general"]
65 ~content:"EIO test message"
66 ~topic:"Testing"
67 () in
68
69 (* Verify message properties *)
70 Alcotest.(check (list string)) "message recipients" ["general"] (Zulip.Message.to_ message);
71 Alcotest.(check string) "message content" "EIO test message" (Zulip.Message.content message);
72 Alcotest.(check (option string)) "message topic" (Some "Testing") (Zulip.Message.topic message);
73
74 (* Test message JSON serialization *)
75 let json = Zulip.Message.to_json message in
76 match json with
77 | `O fields ->
78 let content_field = List.assoc "content" fields in
79 Alcotest.(check bool) "JSON content field" true
80 (match content_field with `String "EIO test message" -> true | _ -> false)
81 | _ -> Alcotest.fail "Message JSON should be an object"
82
83let test_mock_request () =
84 let auth = Zulip.Auth.create
85 ~server_url:"https://test.zulipchat.com"
86 ~email:"test@example.com"
87 ~api_key:"test-key" in
88
89 let client = Zulip.Client.create () auth in
90
91 (* Test mock EIO HTTP request *)
92 (match Zulip.Client.request client ~method_:`GET ~path:"/messages" () with
93 | Ok response ->
94 (match response with
95 | `O fields ->
96 let result_field = List.assoc "result" fields in
97 Alcotest.(check bool) "mock response result" true
98 (match result_field with `String "success" -> true | _ -> false);
99 let msg_field = List.assoc "msg" fields in
100 Alcotest.(check bool) "mock response message" true
101 (match msg_field with `String "Mock EIO response" -> true | _ -> false)
102 | _ -> Alcotest.fail "Response should be JSON object")
103 | Error err ->
104 Alcotest.fail ("Request failed: " ^ Zulip.Error.message err))
105
106let () =
107 let open Alcotest in
108 run "EIO Integration Tests" [
109 "client_eio", [
110 test_case "Client creation with EIO" `Quick test_client_with_eio;
111 ];
112 "auth_eio", [
113 test_case "Auth from TOML with EIO" `Quick test_auth_from_toml_eio;
114 ];
115 "message_eio", [
116 test_case "Message creation with EIO context" `Quick test_message_creation_with_eio;
117 ];
118 "request_eio", [
119 test_case "Mock HTTP request with EIO client" `Quick test_mock_request;
120 ];
121 ]