2020-04-27 18:55:12 +00:00
|
|
|
<?php
|
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
namespace Tests\Unit\Jobs;
|
2020-04-27 18:55:12 +00:00
|
|
|
|
|
|
|
use App\Jobs\ScrobbleJob;
|
|
|
|
use App\Models\Song;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Services\LastfmService;
|
|
|
|
use Mockery;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class ScrobbleJobTest extends TestCase
|
|
|
|
{
|
2021-06-04 16:31:45 +00:00
|
|
|
public function testHandle(): void
|
2020-04-27 18:55:12 +00:00
|
|
|
{
|
2021-06-04 16:31:45 +00:00
|
|
|
/** @var User $user */
|
|
|
|
$user = User::factory()->create();
|
2020-04-27 18:55:12 +00:00
|
|
|
|
2021-06-04 16:31:45 +00:00
|
|
|
/** @var Song $song */
|
|
|
|
$song = Song::factory()->make();
|
2020-04-27 18:55:12 +00:00
|
|
|
|
2021-06-04 16:31:45 +00:00
|
|
|
$job = new ScrobbleJob($user, $song, 100);
|
|
|
|
|
|
|
|
$lastfm = Mockery::mock(LastfmService::class);
|
|
|
|
|
|
|
|
$lastfm->shouldReceive('scrobble')
|
2020-04-27 18:55:12 +00:00
|
|
|
->once()
|
2021-06-04 16:31:45 +00:00
|
|
|
->with($song->artist->name, $song->title, 100, $song->album->name, $user->lastfm_session_key);
|
2020-04-27 18:55:12 +00:00
|
|
|
|
2021-06-04 16:31:45 +00:00
|
|
|
$job->handle($lastfm);
|
2020-04-27 18:55:12 +00:00
|
|
|
}
|
|
|
|
}
|