|
8 | 8 | use App\Jobs\RevokeTeamUserAccessJob; |
9 | 9 | use App\Jobs\SuspendTeamJob; |
10 | 10 | use App\Jobs\UnsuspendTeamJob; |
| 11 | +use App\Livewire\TeamManager; |
11 | 12 | use App\Models\License; |
12 | 13 | use App\Models\Plugin; |
13 | 14 | use App\Models\PluginLicense; |
|
25 | 26 | use Laravel\Cashier\Events\WebhookReceived; |
26 | 27 | use Laravel\Cashier\Subscription; |
27 | 28 | use Laravel\Pennant\Feature; |
| 29 | +use Livewire\Livewire; |
28 | 30 | use Tests\TestCase; |
29 | 31 |
|
30 | 32 | class TeamManagementTest extends TestCase |
@@ -202,14 +204,31 @@ public function test_cannot_invite_when_team_suspended(): void |
202 | 204 | Notification::assertNothingSent(); |
203 | 205 | } |
204 | 206 |
|
| 207 | + public function test_owner_cannot_invite_themselves(): void |
| 208 | + { |
| 209 | + Notification::fake(); |
| 210 | + |
| 211 | + [$owner, $team] = $this->createTeamWithOwner(); |
| 212 | + |
| 213 | + $response = $this->actingAs($owner) |
| 214 | + ->post(route('customer.team.invite'), ['email' => $owner->email]); |
| 215 | + |
| 216 | + $response->assertSessionHas('error', 'You cannot invite yourself to your own team.'); |
| 217 | + Notification::assertNothingSent(); |
| 218 | + $this->assertDatabaseMissing('team_users', [ |
| 219 | + 'team_id' => $team->id, |
| 220 | + 'email' => $owner->email, |
| 221 | + ]); |
| 222 | + } |
| 223 | + |
205 | 224 | public function test_cannot_invite_beyond_seat_limit(): void |
206 | 225 | { |
207 | 226 | Notification::fake(); |
208 | 227 |
|
209 | 228 | [$owner, $team] = $this->createTeamWithOwner(); |
210 | 229 |
|
211 | | - // Create 10 active members to fill all seats |
212 | | - TeamUser::factory()->count(10)->active()->create(['team_id' => $team->id]); |
| 230 | + // Create 9 active members to fill all seats (owner occupies 1 of 10 included seats) |
| 231 | + TeamUser::factory()->count(9)->active()->create(['team_id' => $team->id]); |
213 | 232 |
|
214 | 233 | $response = $this->actingAs($owner) |
215 | 234 | ->post(route('customer.team.invite'), ['email' => 'extra@example.com']); |
@@ -873,4 +892,77 @@ public function test_team_detail_page_shows_owner_purchased_plugins(): void |
873 | 892 | $response->assertSee('acme/shared-plugin'); |
874 | 893 | $response->assertSee('Accessible Plugins'); |
875 | 894 | } |
| 895 | + |
| 896 | + // ======================================== |
| 897 | + // Seat Validation Tests |
| 898 | + // ======================================== |
| 899 | + |
| 900 | + public function test_cannot_add_zero_seats(): void |
| 901 | + { |
| 902 | + [$owner, $team] = $this->createTeamWithOwner(); |
| 903 | + |
| 904 | + Livewire::actingAs($owner) |
| 905 | + ->test(TeamManager::class, ['team' => $team]) |
| 906 | + ->call('addSeats', 0); |
| 907 | + |
| 908 | + $this->assertEquals(0, $team->fresh()->extra_seats); |
| 909 | + } |
| 910 | + |
| 911 | + public function test_cannot_add_negative_seats(): void |
| 912 | + { |
| 913 | + [$owner, $team] = $this->createTeamWithOwner(); |
| 914 | + |
| 915 | + Livewire::actingAs($owner) |
| 916 | + ->test(TeamManager::class, ['team' => $team]) |
| 917 | + ->call('addSeats', -1); |
| 918 | + |
| 919 | + $this->assertEquals(0, $team->fresh()->extra_seats); |
| 920 | + } |
| 921 | + |
| 922 | + public function test_cannot_add_more_than_fifty_seats(): void |
| 923 | + { |
| 924 | + [$owner, $team] = $this->createTeamWithOwner(); |
| 925 | + |
| 926 | + Livewire::actingAs($owner) |
| 927 | + ->test(TeamManager::class, ['team' => $team]) |
| 928 | + ->call('addSeats', 51); |
| 929 | + |
| 930 | + $this->assertEquals(0, $team->fresh()->extra_seats); |
| 931 | + } |
| 932 | + |
| 933 | + public function test_cannot_remove_zero_seats(): void |
| 934 | + { |
| 935 | + [$owner, $team] = $this->createTeamWithOwner(); |
| 936 | + $team->update(['extra_seats' => 5]); |
| 937 | + |
| 938 | + Livewire::actingAs($owner) |
| 939 | + ->test(TeamManager::class, ['team' => $team]) |
| 940 | + ->call('removeSeats', 0); |
| 941 | + |
| 942 | + $this->assertEquals(5, $team->fresh()->extra_seats); |
| 943 | + } |
| 944 | + |
| 945 | + public function test_cannot_remove_negative_seats(): void |
| 946 | + { |
| 947 | + [$owner, $team] = $this->createTeamWithOwner(); |
| 948 | + $team->update(['extra_seats' => 5]); |
| 949 | + |
| 950 | + Livewire::actingAs($owner) |
| 951 | + ->test(TeamManager::class, ['team' => $team]) |
| 952 | + ->call('removeSeats', -1); |
| 953 | + |
| 954 | + $this->assertEquals(5, $team->fresh()->extra_seats); |
| 955 | + } |
| 956 | + |
| 957 | + public function test_cannot_remove_more_than_fifty_seats(): void |
| 958 | + { |
| 959 | + [$owner, $team] = $this->createTeamWithOwner(); |
| 960 | + $team->update(['extra_seats' => 60]); |
| 961 | + |
| 962 | + Livewire::actingAs($owner) |
| 963 | + ->test(TeamManager::class, ['team' => $team]) |
| 964 | + ->call('removeSeats', 51); |
| 965 | + |
| 966 | + $this->assertEquals(60, $team->fresh()->extra_seats); |
| 967 | + } |
876 | 968 | } |
0 commit comments