koel/tests/Feature/V6/PlayCountTest.php

56 lines
1.4 KiB
PHP
Raw Normal View History

2022-07-26 21:05:43 +00:00
<?php
namespace Tests\Feature\V6;
use App\Models\Interaction;
2022-07-27 09:30:04 +00:00
use App\Models\Song;
use App\Models\User;
2022-07-26 21:05:43 +00:00
class PlayCountTest extends TestCase
{
2022-07-27 09:30:04 +00:00
public function testStoreExistingEntry(): void
2022-07-26 21:05:43 +00:00
{
/** @var Interaction $interaction */
$interaction = Interaction::factory()->create([
'play_count' => 10,
]);
2022-07-27 09:30:04 +00:00
$this->postAs('/api/interaction/play', ['song' => $interaction->song->id], $interaction->user)
->assertJsonStructure([
'type',
'id',
'song_id',
'liked',
'play_count',
]);
2022-07-26 21:05:43 +00:00
self::assertEquals(11, $interaction->refresh()->play_count);
}
2022-07-27 09:30:04 +00:00
public function testStoreNewEntry(): void
{
/** @var Song $song */
$song = Song::factory()->create();
/** @var User $user */
$user = User::factory()->create();
$this->postAs('/api/interaction/play', ['song' => $song->id], $user)
->assertJsonStructure([
'type',
'id',
'song_id',
'liked',
'play_count',
]);
/** @var Interaction $interaction */
$interaction = Interaction::query()
->where('song_id', $song->id)
->where('user_id', $user->id)
->first();
self::assertEquals(1, $interaction->play_count);
2022-07-27 09:30:04 +00:00
}
2022-07-26 21:05:43 +00:00
}