2016-06-13 09:04:42 +00:00
|
|
|
<?php
|
|
|
|
|
2017-02-14 06:53:02 +00:00
|
|
|
namespace Tests\Feature\ObjectStorage;
|
|
|
|
|
2016-06-13 09:04:42 +00:00
|
|
|
use App\Events\LibraryChanged;
|
2018-08-24 15:27:19 +00:00
|
|
|
use App\Models\Song;
|
2016-06-13 09:04:42 +00:00
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
2017-08-05 16:56:11 +00:00
|
|
|
use Tests\Feature\TestCase;
|
2016-06-13 09:04:42 +00:00
|
|
|
|
2017-08-05 16:56:11 +00:00
|
|
|
class S3Test extends TestCase
|
2016-06-13 09:04:42 +00:00
|
|
|
{
|
2017-08-05 16:56:11 +00:00
|
|
|
use WithoutMiddleware;
|
2016-06-13 09:04:42 +00:00
|
|
|
|
2019-07-22 07:03:23 +00:00
|
|
|
public function setUp(): void
|
2017-02-14 06:53:02 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-11-14 16:57:25 +00:00
|
|
|
|
2017-06-11 00:15:28 +00:00
|
|
|
$this->disableMiddlewareForAllTests();
|
2017-02-14 06:53:02 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 07:03:23 +00:00
|
|
|
public function testStoringASong(): void
|
2016-06-13 09:04:42 +00:00
|
|
|
{
|
|
|
|
$this->post('api/os/s3/song', [
|
|
|
|
'bucket' => 'koel',
|
|
|
|
'key' => 'sample.mp3',
|
|
|
|
'tags' => [
|
|
|
|
'title' => 'A Koel Song',
|
|
|
|
'album' => 'Koel Testing Vol. 1',
|
|
|
|
'artist' => 'Koel',
|
|
|
|
'lyrics' => "When you wake up, turn your radio on, and you'll hear this simple song",
|
|
|
|
'duration' => 10,
|
|
|
|
'track' => 5,
|
|
|
|
],
|
2020-09-06 18:21:39 +00:00
|
|
|
]);
|
|
|
|
|
2021-12-06 16:12:47 +00:00
|
|
|
/** @var Song $song */
|
2022-08-09 18:45:11 +00:00
|
|
|
$song = Song::query()->where('path', 's3://koel/sample.mp3')->firstOrFail();
|
2021-12-06 16:12:47 +00:00
|
|
|
|
|
|
|
self::assertSame('A Koel Song', $song->title);
|
|
|
|
self::assertSame('Koel Testing Vol. 1', $song->album->name);
|
|
|
|
self::assertSame('Koel', $song->artist->name);
|
|
|
|
self::assertSame('When you wake up, turn your radio on, and you\'ll hear this simple song', $song->lyrics);
|
|
|
|
self::assertEquals(10, $song->length);
|
|
|
|
self::assertSame(5, $song->track);
|
2016-06-13 09:04:42 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 07:03:23 +00:00
|
|
|
public function testRemovingASong(): void
|
2016-06-13 09:04:42 +00:00
|
|
|
{
|
|
|
|
$this->expectsEvents(LibraryChanged::class);
|
2018-08-24 15:27:19 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
Song::factory()->create([
|
2018-08-24 15:27:19 +00:00
|
|
|
'path' => 's3://koel/sample.mp3',
|
|
|
|
]);
|
2016-06-13 09:04:42 +00:00
|
|
|
|
|
|
|
$this->delete('api/os/s3/song', [
|
|
|
|
'bucket' => 'koel',
|
|
|
|
'key' => 'sample.mp3',
|
2020-09-06 18:21:39 +00:00
|
|
|
]);
|
|
|
|
|
2021-12-06 16:12:47 +00:00
|
|
|
self::assertDatabaseMissing(Song::class, ['path' => 's3://koel/sample.mp3']);
|
2016-06-13 09:04:42 +00:00
|
|
|
}
|
|
|
|
}
|