您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InviteCompanyEmployeeTest.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Models\User;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Illuminate\Support\Facades\Mail;
  6. use Livewire\Livewire;
  7. use Tests\TestCase;
  8. use Wallo\FilamentCompanies\Features;
  9. use Wallo\FilamentCompanies\Http\Livewire\CompanyEmployeeManager;
  10. use Wallo\FilamentCompanies\Mail\CompanyInvitation;
  11. class InviteCompanyEmployeeTest extends TestCase
  12. {
  13. use RefreshDatabase;
  14. public function test_company_employees_can_be_invited_to_company(): void
  15. {
  16. if (! Features::sendsCompanyInvitations()) {
  17. $this->markTestSkipped('Company invitations not enabled.');
  18. return;
  19. }
  20. Mail::fake();
  21. $this->actingAs($user = User::factory()->withPersonalCompany()->create());
  22. $component = Livewire::test(CompanyEmployeeManager::class, ['company' => $user->currentCompany])
  23. ->set('addCompanyEmployeeForm', [
  24. 'email' => 'test@example.com',
  25. 'role' => 'admin',
  26. ])->call('addCompanyEmployee');
  27. Mail::assertSent(CompanyInvitation::class);
  28. $this->assertCount(1, $user->currentCompany->fresh()->companyInvitations);
  29. }
  30. public function test_company_employee_invitations_can_be_cancelled(): void
  31. {
  32. if (! Features::sendsCompanyInvitations()) {
  33. $this->markTestSkipped('Company invitations not enabled.');
  34. return;
  35. }
  36. Mail::fake();
  37. $this->actingAs($user = User::factory()->withPersonalCompany()->create());
  38. // Add the company employee...
  39. $component = Livewire::test(CompanyEmployeeManager::class, ['company' => $user->currentCompany])
  40. ->set('addCompanyEmployeeForm', [
  41. 'email' => 'test@example.com',
  42. 'role' => 'admin',
  43. ])->call('addCompanyEmployee');
  44. $invitationId = $user->currentCompany->fresh()->companyInvitations->first()->id;
  45. // Cancel the company invitation...
  46. $component->call('cancelCompanyInvitation', $invitationId);
  47. $this->assertCount(0, $user->currentCompany->fresh()->companyInvitations);
  48. }
  49. }