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',
|
|
|
|
]);
|
|
|
|
|
|
|
|
self::assertEquals(1, Interaction::whereSongIdAndUserId($song->id, $user->id)->first()->play_count);
|
|
|
|
}
|
2022-07-26 21:05:43 +00:00
|
|
|
}
|