Skip to content

Commit fabd568

Browse files
committed
feat(test): add helper method for deprecated tests
1 parent fe931ca commit fabd568

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

spec/spec_helper.rb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,37 @@ def typesense_healthy?(host = 'localhost', port = 8108)
3434
false
3535
end
3636

37+
def typesense_version
38+
WebMock.allow_net_connect!
39+
conn = Faraday.new('http://localhost:8108')
40+
response = conn.get('/debug') do |req|
41+
req.headers['X-TYPESENSE-API-KEY'] = 'xyz'
42+
end
43+
44+
if response.status == 200 && !response.body.empty?
45+
debug_info = JSON.parse(response.body)
46+
debug_info['version']
47+
end
48+
rescue StandardError
49+
nil
50+
ensure
51+
WebMock.disable_net_connect!(allow_localhost: true)
52+
end
53+
54+
def typesense_v30_or_above?
55+
version = typesense_version
56+
return false unless version
57+
58+
return true if version == 'nightly'
59+
60+
if version.match(/^v(\d+)/)
61+
major_version = Regexp.last_match(1).to_i
62+
return major_version >= 30
63+
end
64+
65+
false
66+
end
67+
3768
def ensure_typesense_running
3869
if typesense_healthy?
3970
puts '✅ Typesense is already running and healthy, ready for use in integration tests'
@@ -96,7 +127,6 @@ def stop_typesense_if_started
96127

97128
config.before(:suite) do
98129
ensure_typesense_running
99-
WebMock.disable_net_connect!
100130
end
101131

102132
config.after(:suite) do

0 commit comments

Comments
 (0)