@@ -153,4 +153,110 @@ class ApiV1PackagesControllerTest < ActionDispatch::IntegrationTest
153
153
assert_equal actual_response . length , 1
154
154
assert_equal actual_response . first [ 'name' ] , @package . name
155
155
end
156
+
157
+ test 'ping package' do
158
+ get ping_api_v1_registry_package_path ( registry_id : @registry . name , id : @package . name )
159
+ assert_response :success
160
+
161
+ actual_response = Oj . load ( @response . body )
162
+ assert_equal actual_response [ 'message' ] , 'pong'
163
+ end
164
+
165
+ test 'ping package with repos.ecosyste.ms user agent' do
166
+ # Mock the async methods to verify they're called
167
+ Package . any_instance . expects ( :sync_async ) . once
168
+ Package . any_instance . expects ( :update_repo_metadata_async ) . once
169
+
170
+ get ping_api_v1_registry_package_path ( registry_id : @registry . name , id : @package . name ) ,
171
+ headers : { 'User-Agent' => 'repos.ecosyste.ms/1.0' }
172
+ assert_response :success
173
+
174
+ actual_response = Oj . load ( @response . body )
175
+ assert_equal actual_response [ 'message' ] , 'pong'
176
+ end
177
+
178
+ test 'ping package with different user agent' do
179
+ # Mock the async methods to verify sync is called but not update_repo_metadata_async
180
+ Package . any_instance . expects ( :sync_async ) . once
181
+ Package . any_instance . expects ( :update_repo_metadata_async ) . never
182
+
183
+ get ping_api_v1_registry_package_path ( registry_id : @registry . name , id : @package . name ) ,
184
+ headers : { 'User-Agent' => 'other-service/1.0' }
185
+ assert_response :success
186
+
187
+ actual_response = Oj . load ( @response . body )
188
+ assert_equal actual_response [ 'message' ] , 'pong'
189
+ end
190
+
191
+ test 'ping nonexistent package' do
192
+ Registry . any_instance . expects ( :sync_package_async ) . with ( 'nonexistent' ) . once
193
+
194
+ get ping_api_v1_registry_package_path ( registry_id : @registry . name , id : 'nonexistent' )
195
+ assert_response :success
196
+
197
+ actual_response = Oj . load ( @response . body )
198
+ assert_equal actual_response [ 'message' ] , 'pong'
199
+ end
200
+
201
+ test 'ping all packages by repository url' do
202
+ @package . update ( repository_url : 'https://github.com/rust-random/rand' )
203
+
204
+ Package . any_instance . expects ( :sync_async ) . once
205
+ Package . any_instance . expects ( :update_repo_metadata_async ) . never
206
+
207
+ get ping_api_v1_packages_path ( repository_url : 'https://github.com/rust-random/rand' )
208
+ assert_response :success
209
+
210
+ actual_response = Oj . load ( @response . body )
211
+ assert_equal actual_response [ 'message' ] , 'pong'
212
+ end
213
+
214
+ test 'ping all packages by repository url with repos.ecosyste.ms user agent' do
215
+ @package . update ( repository_url : 'https://github.com/rust-random/rand' )
216
+
217
+ Package . any_instance . expects ( :sync_async ) . once
218
+ Package . any_instance . expects ( :update_repo_metadata_async ) . once
219
+
220
+ get ping_api_v1_packages_path ( repository_url : 'https://github.com/rust-random/rand' ) ,
221
+ headers : { 'User-Agent' => 'repos.ecosyste.ms/1.0' }
222
+ assert_response :success
223
+
224
+ actual_response = Oj . load ( @response . body )
225
+ assert_equal actual_response [ 'message' ] , 'pong'
226
+ end
227
+
228
+ test 'ping all packages without repository url' do
229
+ get ping_api_v1_packages_path
230
+ assert_response :success
231
+
232
+ actual_response = Oj . load ( @response . body )
233
+ assert_equal actual_response [ 'message' ] , 'pong'
234
+ end
235
+
236
+ test 'ping package with advisories.ecosyste.ms user agent' do
237
+ # Mock the async methods to verify they're called
238
+ Package . any_instance . expects ( :sync_async ) . once
239
+ Package . any_instance . expects ( :update_advisories_async ) . once
240
+
241
+ get ping_api_v1_registry_package_path ( registry_id : @registry . name , id : @package . name ) ,
242
+ headers : { 'User-Agent' => 'advisories.ecosyste.ms/1.0' }
243
+ assert_response :success
244
+
245
+ actual_response = Oj . load ( @response . body )
246
+ assert_equal actual_response [ 'message' ] , 'pong'
247
+ end
248
+
249
+ test 'ping all packages by repository url with advisories.ecosyste.ms user agent' do
250
+ @package . update ( repository_url : 'https://github.com/rust-random/rand' )
251
+
252
+ Package . any_instance . expects ( :sync_async ) . once
253
+ Package . any_instance . expects ( :update_advisories_async ) . once
254
+
255
+ get ping_api_v1_packages_path ( repository_url : 'https://github.com/rust-random/rand' ) ,
256
+ headers : { 'User-Agent' => 'advisories.ecosyste.ms/1.0' }
257
+ assert_response :success
258
+
259
+ actual_response = Oj . load ( @response . body )
260
+ assert_equal actual_response [ 'message' ] , 'pong'
261
+ end
156
262
end
0 commit comments