koel/tests/Feature/ScrobbleTest.php

36 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;
2018-09-04 06:25:24 +00:00
use Exception;
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
{
2018-09-04 06:25:24 +00:00
/**
* @throws Exception
*/
2018-08-19 21:17:05 +00:00
public function testLastfmScrobble()
2016-05-30 05:50:59 +00:00
{
2018-09-04 06:25:24 +00:00
$this->withoutEvents();
$this->createSampleMediaSet();
$song = Song::first();
/** @var User $user */
2018-08-24 15:27:19 +00:00
$user = factory(User::class)->create();
2018-09-04 06:25:24 +00:00
$user->setPreference('lastfm_session_key', 'foo');
2016-05-30 05:50:59 +00:00
$ts = time();
2018-09-04 06:25:24 +00:00
$this->mockIocDependency(LastfmService::class)
->shouldReceive('scrobble')
2018-08-24 15:27:19 +00:00
->with($song->album->artist->name, $song->title, $ts, $song->album->name, 'foo')
->once();
2016-05-30 05:50:59 +00:00
2018-08-24 15:27:19 +00:00
$this->postAsUser("/api/{$song->id}/scrobble/$ts", [], $user)
->assertResponseOk();
2016-05-30 05:50:59 +00:00
}
}