Refactor: Enforce type safety, fix close deadlock, implement assignee restrictions and notify admin fallbacks
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled

This commit is contained in:
2026-05-20 10:42:30 +00:00
parent 44a7f53deb
commit fc9158b928
16 changed files with 409 additions and 10 deletions

View File

@@ -0,0 +1,72 @@
<?php
use App\Models\Customer;
use App\Models\Department;
use App\Models\Feedback;
use App\Models\FeedbackChannel;
use App\Models\User;
use App\Filament\Resources\Feedback\Pages\EditFeedback;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use Livewire\Livewire;
use Illuminate\Support\Facades\Storage;
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
beforeEach(function () {
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
Permission::firstOrCreate(['name' => 'close-ticket']);
Permission::firstOrCreate(['name' => 'view-feedback']);
Permission::firstOrCreate(['name' => 'update-feedback']);
Permission::firstOrCreate(['name' => 'transfer-department']);
Permission::firstOrCreate(['name' => 'delete-feedback']);
Permission::firstOrCreate(['name' => 'create-feedback']);
});
test('can upload proof and close ticket in one save operation', function () {
Storage::fake('public');
// Create manager who has close permission
$managerRole = Role::create(['name' => 'manager']);
$managerRole->givePermissionTo(['close-ticket', 'view-feedback', 'update-feedback']);
$manager = User::factory()->create();
$manager->assignRole('manager');
$dept = Department::create(['name' => 'CSKH', 'manager_id' => $manager->id]);
$channel = FeedbackChannel::create(['name' => 'Email', 'slug' => 'email']);
$customer = Customer::create(['name' => 'Test Customer', 'email' => 'test@test.com']);
$feedback = Feedback::create([
'customer_id' => $customer->id,
'feedback_channel_id' => $channel->id,
'title' => 'Test Feedback',
'content' => 'Test content',
'status' => 'resolved',
'current_department_id' => $dept->id,
]);
// Mock an uploaded file on disk
$path = 'feedback-attachments/mock-proof.pdf';
Storage::disk('public')->put($path, 'dummy content');
$this->actingAs($manager);
// Run Filament form test
Livewire::test(EditFeedback::class, ['record' => $feedback->id])
->fillForm([
'status' => 'closed',
'attachment_collection' => 'proof_of_resolution',
'attachments' => [$path],
])
->call('save')
->assertHasNoFormErrors();
// Verify feedback is closed
expect($feedback->fresh()->status)->toBe('closed');
// Verify attachment exists in database
expect($feedback->attachments()->where('collection', 'proof_of_resolution')->exists())->toBeTrue();
});