koel/tests/Feature/ScrobbleTest.php

33 lines
837 B
PHP
Raw Normal View History

2016-05-30 05:50:59 +00:00
<?php
2017-02-14 06:53:02 +00:00
namespace Tests\Feature;
2016-05-30 05:50:59 +00:00
use App\Models\Song;
2018-08-24 15:27:19 +00:00
use App\Models\User;
2018-08-18 13:19:40 +00:00
use App\Services\LastfmService;
2016-05-30 05:50:59 +00:00
2017-08-05 16:56:11 +00:00
class ScrobbleTest extends TestCase
2016-05-30 05:50:59 +00:00
{
public function testLastfmScrobble(): void
2016-05-30 05:50:59 +00:00
{
2018-09-04 06:25:24 +00:00
$this->withoutEvents();
static::createSampleMediaSet();
2018-09-04 06:25:24 +00:00
$song = Song::first();
/** @var User $user */
$user = User::factory()->create();
2018-09-04 06:25:24 +00:00
$user->setPreference('lastfm_session_key', 'foo');
2016-05-30 05:50:59 +00:00
2020-09-13 22:04:07 +00:00
$timestamp = time();
2016-05-30 05:50:59 +00:00
static::mockIocDependency(LastfmService::class)
2018-09-04 06:25:24 +00:00
->shouldReceive('scrobble')
2020-09-13 22:04:07 +00:00
->with($song->album->artist->name, $song->title, $timestamp, $song->album->name, 'foo')
2018-08-24 15:27:19 +00:00
->once();
2016-05-30 05:50:59 +00:00
2020-09-13 22:04:07 +00:00
$response = $this->postAsUser("/api/{$song->id}/scrobble", ['timestamp' => $timestamp], $user);
$response->assertStatus(204);
2016-05-30 05:50:59 +00:00
}
}