2022-08-08 16:00:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Services;
|
|
|
|
|
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Models\Song;
|
|
|
|
use App\Services\ApiClients\YouTubeClient;
|
|
|
|
use App\Services\YouTubeService;
|
|
|
|
use Illuminate\Cache\Repository;
|
2024-01-04 21:51:32 +00:00
|
|
|
use Illuminate\Support\Facades\File;
|
2022-08-08 16:00:59 +00:00
|
|
|
use Mockery;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-01-11 12:41:33 +00:00
|
|
|
use function Tests\test_path;
|
|
|
|
|
2022-08-08 16:00:59 +00:00
|
|
|
class YouTubeServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testSearchVideosRelatedToSong(): void
|
|
|
|
{
|
|
|
|
/** @var Song $song */
|
|
|
|
$song = Song::factory()->for(Artist::factory()->create(['name' => 'Bar']))->create(['title' => 'Foo']);
|
|
|
|
$client = Mockery::mock(YouTubeClient::class);
|
|
|
|
|
|
|
|
$client->shouldReceive('get')
|
|
|
|
->with('search?part=snippet&type=video&maxResults=10&pageToken=my-token&q=Foo+Bar')
|
2024-01-06 11:31:50 +00:00
|
|
|
->andReturn(json_decode(File::get(test_path('blobs/youtube/search.json'))));
|
2022-08-08 16:00:59 +00:00
|
|
|
|
|
|
|
$service = new YouTubeService($client, app(Repository::class));
|
|
|
|
$response = $service->searchVideosRelatedToSong($song, 'my-token');
|
|
|
|
|
2022-10-07 14:25:44 +00:00
|
|
|
self::assertSame('Slipknot - Snuff [OFFICIAL VIDEO]', $response->items[0]->snippet->title);
|
2022-08-08 16:00:59 +00:00
|
|
|
self::assertNotNull(cache()->get('5becf539115b18b2df11c39adbc2bdfa'));
|
|
|
|
}
|
|
|
|
}
|