movie-night-nuevo/tests/Unit/MoviesTest.php

50 lines
2 KiB
PHP
Raw Normal View History

2025-12-12 23:07:04 -06:00
<?php
use App\Models\Movie;
use App\Models\User;
use App\Services\OmdbService;
use Illuminate\Support\Facades\Http;
test('that OmdbService returns a movie when searching', function () {
config()->set('services.omdb.api_url', 'https://omdbapi.fake/?apikey=');
config()->set('services.omdb.api_key', 'abcd123');
$movieModel = new Movie();
$service = new OmdbService($movieModel);
User::factory()->create();
Http::fake([
'*' => Http::response([
"Title" => "Batman",
"Year" => "1989",
"Rated" => "PG-13",
"Released" => "23 Jun 1989",
"Runtime" => "126 min",
"Genre" => "Action",
"Adventure", "Director" => "Tim Burton",
"Writer" => "Bob Kane, Sam Hamm, Warren Skaaren",
"Actors" => "Michael Keaton, Jack Nicholson, Kim Basinger",
"Plot" => "The Dark Knight of Gotham City begins his war on crime with his first major enemy being Jack Napier, a criminal who becomes the clownishly homicidal Joker.",
"Language" => "English, French, Spanish",
"Country" => "United States, United Kingdom",
"Awards" => "Won 1 Oscar. 13 wins & 30 nominations total",
"Poster" => "https://m.media-amazon.com/images/M/MV5BYzZmZWViM2EtNzhlMi00NzBlLWE0MWEtZDFjMjk3YjIyNTBhXkEyXkFqcGc@._V1_SX300.jpg",
"Ratings" => '[{"Source" => "Internet Movie Database","Value":"7.5/10"},{"Source":"Rotten Tomatoes","Value":"77%"},{"Source":"Metacritic","Value":"69/100"}]',
"Metascore" => "69",
"imdbRating" => "7.5",
"imdbVotes" => "425,785",
"imdbID" => "tt0096895",
"Type" => "movie",
"DVD" => "N/A",
"BoxOffice" => "$251,409,241",
"Production" => "N/A",
"Website" => "N/A",
"Response" => "True",
])
]);
$movie = $service->search("batman");
expect($movie)->toBeInstanceOf(Movie::class);
expect($movie->imdb_id)->toBe('tt0096895');
});