2016-05-30 13:50:59 +08:00
|
|
|
<?php
|
|
|
|
|
2017-02-14 14:53:02 +08:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2016-05-30 13:50:59 +08:00
|
|
|
use App\Models\Song;
|
2018-08-24 17:27:19 +02:00
|
|
|
use App\Models\User;
|
2018-08-18 15:19:40 +02:00
|
|
|
use App\Services\LastfmService;
|
2016-05-30 13:50:59 +08:00
|
|
|
|
2017-08-05 17:56:11 +01:00
|
|
|
class ScrobbleTest extends TestCase
|
2016-05-30 13:50:59 +08:00
|
|
|
{
|
2020-11-14 17:57:25 +01:00
|
|
|
public function testLastfmScrobble(): void
|
2016-05-30 13:50:59 +08:00
|
|
|
{
|
2018-09-04 13:25:24 +07:00
|
|
|
$this->withoutEvents();
|
|
|
|
|
|
|
|
/** @var User $user */
|
2020-11-14 17:57:25 +01:00
|
|
|
$user = User::factory()->create();
|
2021-06-04 18:19:34 +02:00
|
|
|
|
|
|
|
/** @var Song $song */
|
|
|
|
$song = Song::factory()->create();
|
2016-05-30 13:50:59 +08:00
|
|
|
|
2020-09-14 00:04:07 +02:00
|
|
|
$timestamp = time();
|
2016-05-30 13:50:59 +08:00
|
|
|
|
2020-12-23 00:01:49 +01:00
|
|
|
self::mock(LastfmService::class)
|
2018-09-04 13:25:24 +07:00
|
|
|
->shouldReceive('scrobble')
|
2021-06-04 18:19:34 +02:00
|
|
|
->with($song->album->artist->name, $song->title, $timestamp, $song->album->name, $user->lastfm_session_key)
|
2018-08-24 17:27:19 +02:00
|
|
|
->once();
|
2016-05-30 13:50:59 +08:00
|
|
|
|
2021-06-04 18:19:34 +02:00
|
|
|
$this->postAsUser("/api/$song->id/scrobble", ['timestamp' => $timestamp], $user)
|
|
|
|
->assertNoContent();
|
2016-05-30 13:50:59 +08:00
|
|
|
}
|
|
|
|
}
|