@@ -165,4 +165,37 @@ class JuliaTest < ActiveSupport::TestCase
165
165
# Should return empty array when all_package_names is empty and no existing packages
166
166
assert_equal @registry . missing_package_names , [ ]
167
167
end
168
+
169
+ test 'fetch_package_metadata handles malformed API response' do
170
+ # Test when API returns a String instead of Hash with packages array
171
+ stub_request ( :get , "https://juliahub.com/app/packages/info" )
172
+ . to_return ( { status : 200 , body : "invalid json response" } )
173
+
174
+ # Should not raise "undefined method 'find' for an instance of String"
175
+ assert_nothing_raised do
176
+ result = @ecosystem . fetch_package_metadata ( 'SomePackage' )
177
+ assert_nil result
178
+ end
179
+ end
180
+
181
+ test 'fetch_package_metadata handles missing packages key' do
182
+ # Test when API returns valid JSON but without packages key
183
+ stub_request ( :get , "https://juliahub.com/app/packages/info" )
184
+ . to_return ( { status : 200 , body : '{"other_key": "value"}' } )
185
+
186
+ # Should not raise "undefined method 'find' for an instance of String"
187
+ assert_nothing_raised do
188
+ result = @ecosystem . fetch_package_metadata ( 'SomePackage' )
189
+ assert_nil result
190
+ end
191
+ end
192
+
193
+ test 'packages method returns array even with malformed response' do
194
+ stub_request ( :get , "https://juliahub.com/app/packages/info" )
195
+ . to_return ( { status : 200 , body : "not json" } )
196
+
197
+ packages = @ecosystem . packages
198
+ assert_kind_of Array , packages
199
+ assert_equal packages , [ ]
200
+ end
168
201
end
0 commit comments