assertRedirect(route('login')); }); it('returns 403 when user has no permission to view settings', function () { actingAs(createUnauthorizedUser()) ->get(route('system.settings.index')) ->assertStatus(403); }); }); describe('General Setting Module - Authorized Actions', function () { beforeEach(function () { $user = createAuthorizedUser([ 'View:Setting', 'Edit:Setting', ]); actingAs($user); }); it('can access settings index page', function () { get(route('system.settings.index')) ->assertOk() ->assertInertia(fn ($page) => $page ->component('admin/system/settings/index') ->has('setting') ); }); it('can update general settings with logo and icon variants', function () { Storage::fake('public'); // Ensure a setting exists first for testing update logic in Controller $setting = GeneralSetting::create([ 'name' => 'Old Name', 'description' => 'Old Description', 'address' => 'Old Address', 'phone' => '000', ]); $data = [ 'name' => 'VNGrup Dress', 'description' => 'Toko baju premium', 'address' => 'Jakarta, Indonesia', 'phone' => '081234567890', 'logo_light' => UploadedFile::fake()->image('logo_light.png'), 'logo_dark' => UploadedFile::fake()->image('logo_dark.png'), 'icon_light' => UploadedFile::fake()->image('icon_light.png'), 'icon_dark' => UploadedFile::fake()->image('icon_dark.png'), ]; postJson(route('system.settings.update'), $data) ->assertRedirect() ->assertSessionHas('success'); assertDatabaseHas('general_settings', [ 'id' => $setting->id, 'name' => 'VNGrup Dress', 'phone' => '081234567890', ]); $setting->refresh(); expect($setting->getFirstMediaUrl('logo_light'))->not->toBeEmpty(); expect($setting->getFirstMediaUrl('logo_dark'))->not->toBeEmpty(); expect($setting->getFirstMediaUrl('icon_light'))->not->toBeEmpty(); expect($setting->getFirstMediaUrl('icon_dark'))->not->toBeEmpty(); }); it('validates settings update with new variants', function () { // If setting doesn't exist, logo_light and icon_light are required GeneralSetting::truncate(); postJson(route('system.settings.update'), []) ->assertStatus(422) ->assertJsonValidationErrors(['name', 'description', 'address', 'phone', 'logo_light', 'icon_light']); }); }); describe('General Setting Module - Unauthorized Actions', function () { beforeEach(function () { actingAs(createUnauthorizedUser()); }); it('cannot update settings without permission', function () { postJson(route('system.settings.update'), ['name' => 'Unauthorized']) ->assertStatus(403); }); });