@@ -433,6 +433,93 @@ public function testAddAssets()
433433 $ this ->assertEquals ('Asset already exists in bundle ' , $ response ->json ()['error ' ]['message ' ]);
434434 }
435435
436+ public function testPingReturnsOkWhenRemotePongSucceeds ()
437+ {
438+ $ devLink = DevLink::factory ()->create ([
439+ 'url ' => 'https://remote-instance.test ' ,
440+ 'access_token ' => 'token ' ,
441+ ]);
442+
443+ Http::fake ([
444+ 'remote-instance.test/* ' => Http::response (['status ' => 'ok ' ], 200 ),
445+ ]);
446+
447+ $ response = $ this ->apiCall ('GET ' , route ('api.devlink.ping ' , ['devLink ' => $ devLink ->id ]));
448+
449+ $ response ->assertStatus (200 );
450+ $ response ->assertJson (['status ' => 'ok ' ]);
451+ }
452+
453+ public function testPingReturnsAuthorizationRequiredWhenRemotePongReturnsUnauthorized ()
454+ {
455+ $ devLink = DevLink::factory ()->create ([
456+ 'url ' => 'https://remote-instance.test ' ,
457+ 'access_token ' => 'token ' ,
458+ ]);
459+
460+ Http::fake ([
461+ 'remote-instance.test/* ' => Http::response (['message ' => 'Unauthorized ' ], 401 ),
462+ ]);
463+
464+ $ response = $ this ->apiCall ('GET ' , route ('api.devlink.ping ' , ['devLink ' => $ devLink ->id ]));
465+
466+ $ response ->assertStatus (200 );
467+ $ response ->assertJson (['status ' => 'authorization_required ' ]);
468+ }
469+
470+ public function testPingReturnsAuthorizationRequiredWhenRemotePongReturnsForbidden ()
471+ {
472+ $ devLink = DevLink::factory ()->create ([
473+ 'url ' => 'https://remote-instance.test ' ,
474+ 'access_token ' => 'token ' ,
475+ ]);
476+
477+ Http::fake ([
478+ 'remote-instance.test/* ' => Http::response (['message ' => 'Forbidden ' ], 403 ),
479+ ]);
480+
481+ $ response = $ this ->apiCall ('GET ' , route ('api.devlink.ping ' , ['devLink ' => $ devLink ->id ]));
482+
483+ $ response ->assertStatus (200 );
484+ $ response ->assertJson (['status ' => 'authorization_required ' ]);
485+ }
486+
487+ public function testPingReturnsErrorWhenRemotePongFails ()
488+ {
489+ $ devLink = DevLink::factory ()->create ([
490+ 'url ' => 'https://remote-instance.test ' ,
491+ 'access_token ' => 'token ' ,
492+ ]);
493+
494+ Http::fake ([
495+ 'remote-instance.test/* ' => Http::response (['message ' => 'Server error ' ], 500 ),
496+ ]);
497+
498+ $ response = $ this ->apiCall ('GET ' , route ('api.devlink.ping ' , ['devLink ' => $ devLink ->id ]));
499+
500+ $ response ->assertStatus (200 );
501+ $ response ->assertJson (['status ' => 'error ' ]);
502+ }
503+
504+ public function testPingReturnsErrorWhenRemotePongCannotConnect ()
505+ {
506+ $ devLink = DevLink::factory ()->create ([
507+ 'url ' => 'https://remote-instance.test ' ,
508+ 'access_token ' => 'token ' ,
509+ ]);
510+
511+ Http::fake ([
512+ 'remote-instance.test/* ' => function () {
513+ throw new ConnectionException ('Connection failed ' );
514+ },
515+ ]);
516+
517+ $ response = $ this ->apiCall ('GET ' , route ('api.devlink.ping ' , ['devLink ' => $ devLink ->id ]));
518+
519+ $ response ->assertStatus (200 );
520+ $ response ->assertJson (['status ' => 'error ' ]);
521+ }
522+
436523 public function testInstallRemoteAsset ()
437524 {
438525 $ screen = Screen::factory ()->create ();
0 commit comments