koel/tests/Feature/ScrobbleTest.php

35 lines
806 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;
2022-08-08 16:00:59 +00:00
use Mockery;
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();
/** @var User $user */
$user = User::factory()->create();
/** @var Song $song */
$song = Song::factory()->create();
2016-05-30 05:50:59 +00:00
2020-12-22 23:01:49 +00:00
self::mock(LastfmService::class)
2018-09-04 06:25:24 +00:00
->shouldReceive('scrobble')
2022-08-08 16:00:59 +00:00
->with(
Mockery::on(static fn (Song $s) => $s->is($song)),
Mockery::on(static fn (User $u) => $u->is($user)),
100
)
2018-08-24 15:27:19 +00:00
->once();
2016-05-30 05:50:59 +00:00
2022-08-08 16:00:59 +00:00
$this->postAs("/api/$song->id/scrobble", ['timestamp' => 100], $user)
->assertNoContent();
2016-05-30 05:50:59 +00:00
}
}