PIMS/tests/Feature/Movies/AdminSearchMoviesTest.php

66 lines
2 KiB
PHP
Raw Normal View History

2025-12-07 03:49:26 +00:00
<?php
namespace Tests\Feature\Movies;
use App\Modules\Movies\Services\Contracts\MovieProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Models\User;
class AdminSearchMoviesTest extends TestCase
{
use RefreshDatabase;
protected function authenticate(): User
{
$user = User::factory()->create();
$this->actingAs($user);
return $user;
}
public function test_requires_authentication(): void
{
$response = $this->getJson('/admin/movies/search?q=test');
// For JSON requests, Laravel returns 401 when unauthenticated
$response->assertStatus(401);
}
public function test_returns_provider_results(): void
{
$this->authenticate();
// Bind a stub provider
$this->app->bind(MovieProvider::class, function () {
return new class implements MovieProvider {
public function search(string $query, int $page = 1): array
{
return [
'results' => collect([
[
'provider' => 'stub',
'provider_id' => 'tt0001',
'title' => 'Stub Movie',
'year' => '2024',
'poster_url' => null,
],
]),
'total' => 1,
'page' => $page,
'has_more' => false,
];
}
public function details(string $id): array { return []; }
};
});
$response = $this->getJson('/admin/movies/search?q=stub');
$response->assertOk()
->assertJson([
'total' => 1,
'page' => 1,
'has_more' => false,
])
->assertJsonPath('results.0.title', 'Stub Movie');
}
}