mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Fix bad endpoint call
This commit is contained in:
@@ -248,6 +248,11 @@ class TmdbClient
|
||||
*/
|
||||
public function getTvSeason(int $tvId, int $seasonNumber): ?array
|
||||
{
|
||||
// Validate parameters to avoid unnecessary API calls with invalid IDs
|
||||
if ($tvId <= 0 || $seasonNumber < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->get('/tv/'.$tvId.'/season/'.$seasonNumber);
|
||||
}
|
||||
|
||||
@@ -261,6 +266,11 @@ class TmdbClient
|
||||
*/
|
||||
public function getTvEpisode(int $tvId, int $seasonNumber, int $episodeNumber): ?array
|
||||
{
|
||||
// Validate parameters to avoid unnecessary API calls with invalid IDs
|
||||
if ($tvId <= 0 || $seasonNumber < 0 || $episodeNumber < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->get('/tv/'.$tvId.'/season/'.$seasonNumber.'/episode/'.$episodeNumber);
|
||||
}
|
||||
|
||||
|
||||
@@ -138,6 +138,17 @@ class TraktService
|
||||
int|string $episode,
|
||||
string $extended = 'min'
|
||||
): ?array {
|
||||
// Validate parameters to avoid unnecessary API calls with invalid IDs
|
||||
$showIdInt = is_numeric($showId) ? (int) $showId : 0;
|
||||
$seasonInt = is_numeric($season) ? (int) $season : -1;
|
||||
$episodeInt = is_numeric($episode) ? (int) $episode : -1;
|
||||
|
||||
// For numeric show IDs, validate they are positive
|
||||
// Season and episode must be non-negative (season 0 can be specials)
|
||||
if (($showIdInt <= 0 && is_numeric($showId)) || $seasonInt < 0 || $episodeInt < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$extended = match ($extended) {
|
||||
'aliases', 'full', 'full,aliases' => $extended,
|
||||
default => 'min',
|
||||
|
||||
@@ -540,5 +540,93 @@ class TmdbClientTest extends TestCase
|
||||
$result = $this->client->searchMovies('Test');
|
||||
$this->assertNull($result);
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// PARAMETER VALIDATION TESTS
|
||||
// =========================================================================
|
||||
|
||||
public function test_get_tv_season_returns_null_for_invalid_tv_id(): void
|
||||
{
|
||||
// Should not make any API call
|
||||
Http::fake();
|
||||
|
||||
$this->assertNull($this->client->getTvSeason(0, 1));
|
||||
$this->assertNull($this->client->getTvSeason(-1, 1));
|
||||
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_get_tv_season_returns_null_for_negative_season(): void
|
||||
{
|
||||
// Should not make any API call
|
||||
Http::fake();
|
||||
|
||||
$this->assertNull($this->client->getTvSeason(1396, -1));
|
||||
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_get_tv_episode_returns_null_for_invalid_tv_id(): void
|
||||
{
|
||||
// Should not make any API call
|
||||
Http::fake();
|
||||
|
||||
$this->assertNull($this->client->getTvEpisode(0, 1, 1));
|
||||
$this->assertNull($this->client->getTvEpisode(-1, 1, 1));
|
||||
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_get_tv_episode_returns_null_for_negative_season(): void
|
||||
{
|
||||
// Should not make any API call
|
||||
Http::fake();
|
||||
|
||||
$this->assertNull($this->client->getTvEpisode(1396, -1, 1));
|
||||
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_get_tv_episode_returns_null_for_negative_episode(): void
|
||||
{
|
||||
// Should not make any API call
|
||||
Http::fake();
|
||||
|
||||
$this->assertNull($this->client->getTvEpisode(1396, 1, -1));
|
||||
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_get_tv_season_allows_season_zero_for_specials(): void
|
||||
{
|
||||
Http::fake([
|
||||
'api.themoviedb.org/3/tv/1396/season/0*' => Http::response([
|
||||
'id' => 3577,
|
||||
'season_number' => 0,
|
||||
'name' => 'Specials',
|
||||
]),
|
||||
]);
|
||||
|
||||
$result = $this->client->getTvSeason(1396, 0);
|
||||
|
||||
$this->assertNotNull($result);
|
||||
$this->assertSame(0, $result['season_number']);
|
||||
}
|
||||
|
||||
public function test_get_tv_episode_allows_season_and_episode_zero(): void
|
||||
{
|
||||
Http::fake([
|
||||
'api.themoviedb.org/3/tv/1396/season/0/episode/0*' => Http::response([
|
||||
'id' => 12345,
|
||||
'name' => 'Special Episode',
|
||||
'episode_number' => 0,
|
||||
'season_number' => 0,
|
||||
]),
|
||||
]);
|
||||
|
||||
$result = $this->client->getTvEpisode(1396, 0, 0);
|
||||
|
||||
$this->assertNotNull($result);
|
||||
$this->assertSame(0, $result['episode_number']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user