@@ -38,35 +38,37 @@ def create_tool(
3838 expect ( runner . invoke ) . to eq ( "query" => "test" )
3939 end
4040
41- it "can perform POST HTTP requests" do
42- script = <<~JS
43- function invoke(params) {
44- result = http.post("https://example.com/api",
45- {
46- headers: { TestHeader: "TestValue" },
47- body: JSON.stringify({ data: params.data })
48- }
49- );
41+ it "can perform HTTP requests with various verbs" do
42+ [ :post , :put , :delete , :patch ] . each do |verb |
43+ script = <<~JS
44+ function invoke(params) {
45+ result = http.#{ verb } ("https://example.com/api",
46+ {
47+ headers: { TestHeader: "TestValue" },
48+ body: JSON.stringify({ data: params.data })
49+ }
50+ );
5051
51- return result.body;
52- }
53- JS
52+ return result.body;
53+ }
54+ JS
5455
55- tool = create_tool ( script : script )
56- runner = tool . runner ( { "data" => "test data" } , llm : nil , bot_user : nil , context : { } )
56+ tool = create_tool ( script : script )
57+ runner = tool . runner ( { "data" => "test data" } , llm : nil , bot_user : nil , context : { } )
5758
58- stub_request ( :post , "https://example.com/api" ) . with (
59- body : "{\" data\" :\" test data\" }" ,
60- headers : {
61- "Accept" => "*/*" ,
62- "Testheader" => "TestValue" ,
63- "User-Agent" => "Discourse AI Bot 1.0 (https://www.discourse.org)" ,
64- } ,
65- ) . to_return ( status : 200 , body : "Success" , headers : { } )
59+ stub_request ( verb , "https://example.com/api" ) . with (
60+ body : "{\" data\" :\" test data\" }" ,
61+ headers : {
62+ "Accept" => "*/*" ,
63+ "Testheader" => "TestValue" ,
64+ "User-Agent" => "Discourse AI Bot 1.0 (https://www.discourse.org)" ,
65+ } ,
66+ ) . to_return ( status : 200 , body : "Success" , headers : { } )
6667
67- result = runner . invoke
68+ result = runner . invoke
6869
69- expect ( result ) . to eq ( "Success" )
70+ expect ( result ) . to eq ( "Success" )
71+ end
7072 end
7173
7274 it "can perform GET HTTP requests, with 1 param" do
0 commit comments