108 lines
3.7 KiB
PHP
108 lines
3.7 KiB
PHP
<?php
|
|
|
|
use App\Settings\GeneralSettings;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use function Pest\Laravel\actingAs;
|
|
use function Pest\Laravel\assertDatabaseHas;
|
|
use function Pest\Laravel\get;
|
|
use function Pest\Laravel\postJson;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| General Setting Module Tests
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
describe('General Setting Module - Authorization', function () {
|
|
it('redirects to login when accessing settings unauthenticated', function () {
|
|
get(route('system.settings.index'))
|
|
->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');
|
|
|
|
$data = [
|
|
'site_name' => 'VNGrup Dress',
|
|
'site_description' => 'Toko baju premium',
|
|
'site_address' => 'Jakarta, Indonesia',
|
|
'site_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('settings', [
|
|
'group' => 'general',
|
|
'name' => 'site_name',
|
|
'payload' => json_encode('VNGrup Dress'),
|
|
]);
|
|
|
|
assertDatabaseHas('settings', [
|
|
'group' => 'general',
|
|
'name' => 'site_phone',
|
|
'payload' => json_encode('081234567890'),
|
|
]);
|
|
|
|
$settings = app(GeneralSettings::class);
|
|
expect($settings->logo_light)->not->toBeNull();
|
|
expect($settings->logo_dark)->not->toBeNull();
|
|
expect($settings->icon_light)->not->toBeNull();
|
|
expect($settings->icon_dark)->not->toBeNull();
|
|
|
|
Storage::disk('public')->assertExists($settings->logo_light);
|
|
Storage::disk('public')->assertExists($settings->logo_dark);
|
|
Storage::disk('public')->assertExists($settings->icon_light);
|
|
Storage::disk('public')->assertExists($settings->icon_dark);
|
|
});
|
|
|
|
it('validates settings update with new variants', function () {
|
|
postJson(route('system.settings.update'), [])
|
|
->assertStatus(422)
|
|
->assertJsonValidationErrors(['site_name', 'site_description', 'site_address', 'site_phone']);
|
|
});
|
|
});
|
|
|
|
describe('General Setting Module - Unauthorized Actions', function () {
|
|
beforeEach(function () {
|
|
actingAs(createUnauthorizedUser());
|
|
});
|
|
|
|
it('cannot update settings without permission', function () {
|
|
postJson(route('system.settings.update'), ['site_name' => 'Unauthorized'])
|
|
->assertStatus(403);
|
|
});
|
|
});
|