mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
fix(test): settings test
This commit is contained in:
parent
a1f0309b0a
commit
f5608d0058
4 changed files with 17 additions and 16 deletions
|
@ -4,21 +4,21 @@ namespace App\Http\Controllers\API;
|
|||
|
||||
use App\Http\Requests\API\SettingRequest;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Services\MediaSyncService;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
private MediaSyncService $mediaSyncService;
|
||||
|
||||
public function __construct(MediaSyncService $mediaSyncService)
|
||||
public function __construct(private MediaSyncService $mediaSyncService)
|
||||
{
|
||||
$this->mediaSyncService = $mediaSyncService;
|
||||
}
|
||||
|
||||
public function update(SettingRequest $request)
|
||||
{
|
||||
$this->authorize('admin', User::class);
|
||||
|
||||
Setting::set('media_path', rtrim(trim($request->media_path), '/'));
|
||||
$this->mediaSyncService->sync(Setting::get('media_path'));
|
||||
$this->mediaSyncService->sync();
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
|
|
|
@ -3,15 +3,10 @@
|
|||
namespace App\Http\Requests\API;
|
||||
|
||||
/**
|
||||
* @property string $media_path
|
||||
* @property-read string $media_path
|
||||
*/
|
||||
class SettingRequest extends Request
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->user()->is_admin;
|
||||
}
|
||||
|
||||
/** @return array<mixed> */
|
||||
public function rules(): array
|
||||
{
|
||||
|
|
|
@ -5,11 +5,12 @@ namespace Tests\Feature;
|
|||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Services\MediaSyncService;
|
||||
use Mockery\LegacyMockInterface;
|
||||
use Mockery\MockInterface;
|
||||
|
||||
class SettingTest extends TestCase
|
||||
{
|
||||
private MockInterface $mediaSyncService;
|
||||
private MediaSyncService|MockInterface|LegacyMockInterface $mediaSyncService;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
|
@ -22,9 +23,15 @@ class SettingTest extends TestCase
|
|||
{
|
||||
$this->mediaSyncService->shouldReceive('sync')->once();
|
||||
|
||||
$user = User::factory()->admin()->create();
|
||||
$this->putAsUser('/api/settings', ['media_path' => __DIR__], $user);
|
||||
$this->putAsUser('/api/settings', ['media_path' => __DIR__], User::factory()->admin()->create())
|
||||
->assertSuccessful();
|
||||
|
||||
self::assertEquals(__DIR__, Setting::get('media_path'));
|
||||
}
|
||||
|
||||
public function testNonAdminCannotSaveSettings(): void
|
||||
{
|
||||
$this->putAsUser('/api/settings', ['media_path' => __DIR__], User::factory()->create())
|
||||
->assertForbidden();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace Tests\Integration\Repositories;
|
|||
|
||||
use App\Models\Song;
|
||||
use App\Repositories\SongRepository;
|
||||
use App\Services\Helper;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SongRepositoryTest extends TestCase
|
||||
|
@ -15,7 +14,7 @@ class SongRepositoryTest extends TestCase
|
|||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->songRepository = new SongRepository(new Helper());
|
||||
$this->songRepository = app(SongRepository::class);
|
||||
}
|
||||
|
||||
public function testGetOneByPath(): void
|
||||
|
|
Loading…
Reference in a new issue