Skip to content

Commit ea7444d

Browse files
authored
Merge pull request #14 from github/copilot/fix-7
Improve test coverage from 80.68% to 85.42% and add comprehensive unit tests
2 parents 35efbda + 89ad5e9 commit ea7444d

File tree

7 files changed

+684
-0
lines changed

7 files changed

+684
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tmp/
55
spec/integration/tmp/
66
tarballs/
77
vendor/gems/
8+
vendor/bundle/
89
.idea
910
.byebug_history
1011
.local/
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# frozen_string_literal: true
2+
3+
require "rack/test"
4+
5+
describe Hooks::App::HealthEndpoint do
6+
include Rack::Test::Methods
7+
8+
def app
9+
described_class
10+
end
11+
12+
before do
13+
# Mock API start_time for consistent uptime calculation
14+
allow(Hooks::App::API).to receive(:start_time).and_return(Time.parse("2024-12-31T23:59:00Z"))
15+
end
16+
17+
describe "GET /" do
18+
it "returns health status as JSON" do
19+
get "/"
20+
21+
expect(last_response.status).to eq(200)
22+
expect(last_response.headers["Content-Type"]).to include("application/json")
23+
end
24+
25+
it "includes health status in response" do
26+
get "/"
27+
28+
response_data = JSON.parse(last_response.body)
29+
expect(response_data["status"]).to eq("healthy")
30+
end
31+
32+
it "includes timestamp in ISO8601 format" do
33+
get "/"
34+
35+
response_data = JSON.parse(last_response.body)
36+
expect(response_data["timestamp"]).to eq(TIME_MOCK)
37+
end
38+
39+
it "includes version information" do
40+
get "/"
41+
42+
response_data = JSON.parse(last_response.body)
43+
expect(response_data["version"]).to eq(Hooks::VERSION)
44+
end
45+
46+
it "includes uptime in seconds" do
47+
get "/"
48+
49+
response_data = JSON.parse(last_response.body)
50+
expect(response_data["uptime_seconds"]).to be_a(Integer)
51+
expect(response_data["uptime_seconds"]).to eq(60) # 1 minute difference
52+
end
53+
54+
it "returns valid JSON structure" do
55+
get "/"
56+
57+
expect { JSON.parse(last_response.body) }.not_to raise_error
58+
59+
response_data = JSON.parse(last_response.body)
60+
expect(response_data).to have_key("status")
61+
expect(response_data).to have_key("timestamp")
62+
expect(response_data).to have_key("version")
63+
expect(response_data).to have_key("uptime_seconds")
64+
end
65+
66+
it "calculates uptime correctly" do
67+
# Test with different start time
68+
different_start = Time.parse("2024-12-31T23:58:30Z")
69+
allow(Hooks::App::API).to receive(:start_time).and_return(different_start)
70+
71+
get "/"
72+
73+
response_data = JSON.parse(last_response.body)
74+
expect(response_data["uptime_seconds"]).to eq(90) # 1.5 minutes difference
75+
end
76+
end
77+
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# frozen_string_literal: true
2+
3+
require "rack/test"
4+
5+
describe Hooks::App::VersionEndpoint do
6+
include Rack::Test::Methods
7+
8+
def app
9+
described_class
10+
end
11+
12+
describe "GET /" do
13+
it "returns version information as JSON" do
14+
get "/"
15+
16+
expect(last_response.status).to eq(200)
17+
expect(last_response.headers["Content-Type"]).to include("application/json")
18+
end
19+
20+
it "includes version number in response" do
21+
get "/"
22+
23+
response_data = JSON.parse(last_response.body)
24+
expect(response_data["version"]).to eq(Hooks::VERSION)
25+
end
26+
27+
it "includes timestamp in ISO8601 format" do
28+
get "/"
29+
30+
response_data = JSON.parse(last_response.body)
31+
expect(response_data["timestamp"]).to eq(TIME_MOCK)
32+
end
33+
34+
it "returns valid JSON structure" do
35+
get "/"
36+
37+
expect { JSON.parse(last_response.body) }.not_to raise_error
38+
39+
response_data = JSON.parse(last_response.body)
40+
expect(response_data).to have_key("version")
41+
expect(response_data).to have_key("timestamp")
42+
end
43+
44+
it "version matches expected format" do
45+
get "/"
46+
47+
response_data = JSON.parse(last_response.body)
48+
expect(response_data["version"]).to match(/^\d+\.\d+\.\d+$/)
49+
end
50+
end
51+
end

0 commit comments

Comments
 (0)