Skip to content

Commit 53854a4

Browse files
-- Adding new api Client#healthcheck
1 parent efcf63c commit 53854a4

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

lib/crewai/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def initialize(access_token: nil, uri_base: nil, configuration: nil)
99
@http = HTTP.new(configuration: @configuration)
1010
end
1111

12+
def healthcheck
13+
parse(@http.get("/healthcheck"))
14+
end
15+
1216
def inputs
1317
parse(@http.get("/inputs"))
1418
end
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe CrewAI::Client do
4+
let(:configuration) do
5+
CrewAI::Configuration.new.tap do |c|
6+
c.access_token = "test-token"
7+
c.uri_base = "https://test.crewai.com"
8+
end
9+
end
10+
let(:client) { described_class.new(configuration: configuration) }
11+
let(:uri_base) { "https://test.crewai.com" }
12+
13+
describe "#healthcheck" do
14+
context "when healthy" do
15+
before do
16+
stub_request(:get, "#{uri_base}/healthcheck")
17+
.to_return(
18+
status: 200,
19+
body: { "status" => "healthy", "version" => "1.13.0" }.to_json,
20+
headers: { "Content-Type" => "application/json" }
21+
)
22+
end
23+
24+
it "returns a hash with status healthy" do
25+
expect(client.healthcheck).to eq({ "status" => "healthy", "version" => "1.13.0" })
26+
end
27+
28+
it "GETs /healthcheck" do
29+
client.healthcheck
30+
expect(a_request(:get, "#{uri_base}/healthcheck")).to have_been_made.once
31+
end
32+
end
33+
34+
context "when unauthorized" do
35+
before do
36+
stub_request(:get, "#{uri_base}/healthcheck")
37+
.to_return(
38+
status: 401,
39+
body: { "message" => "Unauthorized" }.to_json,
40+
headers: { "Content-Type" => "application/json" }
41+
)
42+
end
43+
44+
it "raises CrewAI::AuthenticationError" do
45+
expect { client.healthcheck }.to raise_error(CrewAI::AuthenticationError, /Unauthorized/)
46+
end
47+
end
48+
49+
context "when server error" do
50+
before do
51+
stub_request(:get, "#{uri_base}/healthcheck")
52+
.to_return(
53+
status: 500,
54+
body: { "message" => "Internal Server Error" }.to_json,
55+
headers: { "Content-Type" => "application/json" }
56+
)
57+
end
58+
59+
it "raises CrewAI::ServerError" do
60+
expect { client.healthcheck }.to raise_error(CrewAI::ServerError)
61+
end
62+
end
63+
end
64+
end

0 commit comments

Comments
 (0)