11defmodule TamaEx.AgenticTest do
22 use ExUnit.Case
3+ import TestHelpers
34 doctest TamaEx.Agentic
45
56 alias TamaEx.Agentic
67
78 setup do
89 bypass = Bypass . open ( )
9- client = TamaEx . client ( base_url: "http://localhost:#{ bypass . port } /agentic" )
10-
11- { :ok , bypass: bypass , client: client }
10+ { :ok , bypass: bypass }
1211 end
1312
1413 describe "create_message/3 - client validation" do
15- test "validates required client namespace" , % { client: _client } do
14+ test "validates required client namespace" do
1615 # Test with wrong namespace
17- client = TamaEx . client ( base_url: "https://api.example.com/ provision")
16+ client = mock_client ( " provision")
1817
1918 body = % {
2019 "recipient" => "user-123" ,
@@ -51,7 +50,8 @@ defmodule TamaEx.AgenticTest do
5150 end
5251
5352 describe "create_message/3 - message validation" do
54- test "handles invalid message params" , % { client: client } do
53+ test "handles invalid message params" do
54+ client = mock_client ( "agentic" )
5555 # Test with missing required fields
5656 invalid_body = % {
5757 "content" => "Hello, world!"
@@ -63,7 +63,9 @@ defmodule TamaEx.AgenticTest do
6363 end
6464 end
6565
66- test "validates message structure with missing author" , % { client: client } do
66+ test "validates message structure with missing author" do
67+ client = mock_client ( "agentic" )
68+
6769 invalid_body = % {
6870 "recipient" => "user-123" ,
6971 "content" => "Hello, world!" ,
@@ -79,7 +81,10 @@ defmodule TamaEx.AgenticTest do
7981 end
8082
8183 describe "create_message/3 - non-streaming requests" do
82- test "handles successful non-streaming response" , % { bypass: bypass , client: client } do
84+ test "handles successful non-streaming response" , % { bypass: bypass } do
85+ base_url = "http://localhost:#{ bypass . port } "
86+ client = mock_client ( "agentic" , base_url )
87+
8388 Bypass . expect ( bypass , "POST" , "/agentic/messages" , fn conn ->
8489 { :ok , body , conn } = Plug.Conn . read_body ( conn )
8590 request_data = Jason . decode! ( body )
@@ -138,7 +143,10 @@ defmodule TamaEx.AgenticTest do
138143 assert response_body [ "message" ] [ "content" ] == "Hello, world!"
139144 end
140145
141- test "handles non-streaming request with custom options" , % { bypass: bypass , client: client } do
146+ test "handles non-streaming request with custom options" , % { bypass: bypass } do
147+ base_url = "http://localhost:#{ bypass . port } "
148+ client = mock_client ( "agentic" , base_url )
149+
142150 Bypass . expect ( bypass , "POST" , "/agentic/messages" , fn conn ->
143151 # Check headers
144152 assert Plug.Conn . get_req_header ( conn , "authorization" ) == [ "Bearer test-token" ]
@@ -194,7 +202,9 @@ defmodule TamaEx.AgenticTest do
194202 end
195203
196204 describe "create_message/3 - streaming requests" do
197- test "raises error when stream is true but no callback provided" , % { client: client } do
205+ test "raises error when stream is true but no callback provided" do
206+ client = mock_client ( "agentic" )
207+
198208 body = % {
199209 "recipient" => "user-123" ,
200210 "content" => "Hello, streaming world!" ,
@@ -228,7 +238,9 @@ defmodule TamaEx.AgenticTest do
228238 end
229239 end
230240
231- test "handles streaming response with callback" , % { bypass: bypass , client: client } do
241+ test "handles streaming response with callback" , % { bypass: bypass } do
242+ base_url = "http://localhost:#{ bypass . port } "
243+ client = mock_client ( "agentic" , base_url )
232244 test_pid = self ( )
233245
234246 Bypass . expect ( bypass , "POST" , "/agentic/messages" , fn conn ->
@@ -336,7 +348,9 @@ defmodule TamaEx.AgenticTest do
336348 assert final_chunk [ "message" ] [ "final_content" ] == "Hello streaming world!"
337349 end
338350
339- test "handles streaming with atom keys in body" , % { bypass: bypass , client: client } do
351+ test "handles streaming with atom keys in body" , % { bypass: bypass } do
352+ base_url = "http://localhost:#{ bypass . port } "
353+ client = mock_client ( "agentic" , base_url )
340354 test_pid = self ( )
341355
342356 Bypass . expect ( bypass , "POST" , "/agentic/messages" , fn conn ->
@@ -395,7 +409,9 @@ defmodule TamaEx.AgenticTest do
395409 end
396410
397411 describe "data parsing functionality" do
398- test "handles mixed streaming data formats" , % { bypass: bypass , client: client } do
412+ test "handles mixed streaming data formats" , % { bypass: bypass } do
413+ base_url = "http://localhost:#{ bypass . port } "
414+ client = mock_client ( "agentic" , base_url )
399415 test_pid = self ( )
400416
401417 Bypass . expect ( bypass , "POST" , "/agentic/messages" , fn conn ->
@@ -449,7 +465,9 @@ defmodule TamaEx.AgenticTest do
449465 end
450466
451467 describe "timeout handling" do
452- test "uses default timeout when not specified" , % { bypass: bypass , client: client } do
468+ test "uses default timeout when not specified" , % { bypass: bypass } do
469+ base_url = "http://localhost:#{ bypass . port } "
470+ client = mock_client ( "agentic" , base_url )
453471 # We can't directly test the timeout value, but we can verify the request is made
454472 Bypass . expect ( bypass , "POST" , "/agentic/messages" , fn conn ->
455473 # Simulate a request that would benefit from long timeout
@@ -486,7 +504,10 @@ defmodule TamaEx.AgenticTest do
486504 assert response_body [ "id" ] == "timeout-test-123"
487505 end
488506
489- test "uses custom timeout when specified" , % { bypass: bypass , client: client } do
507+ test "uses custom timeout when specified" , % { bypass: bypass } do
508+ base_url = "http://localhost:#{ bypass . port } "
509+ client = mock_client ( "agentic" , base_url )
510+
490511 Bypass . expect ( bypass , "POST" , "/agentic/messages" , fn conn ->
491512 response_data = % {
492513 id: "custom-timeout-456" ,
0 commit comments