Refactor: Enforce type safety, fix close deadlock, implement assignee restrictions and notify admin fallbacks
This commit is contained in:
72
tests/Feature/EditFeedbackTest.php
Normal file
72
tests/Feature/EditFeedbackTest.php
Normal 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();
|
||||
});
|
||||
Reference in New Issue
Block a user