forked from laravel/jetstream
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeleteTeamTest.php
107 lines (75 loc) · 2.47 KB
/
DeleteTeamTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Laravel\Jetstream\Tests;
use App\Actions\Jetstream\CreateTeam;
use App\Actions\Jetstream\DeleteTeam;
use App\Models\Team;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\ValidationException;
use Laravel\Jetstream\Actions\ValidateTeamDeletion;
use Laravel\Jetstream\Jetstream;
use Laravel\Jetstream\Tests\Fixtures\TeamPolicy;
use Laravel\Jetstream\Tests\Fixtures\User;
class DeleteTeamTest extends OrchestraTestCase
{
public function setUp(): void
{
parent::setUp();
Gate::policy(Team::class, TeamPolicy::class);
Jetstream::useUserModel(User::class);
}
public function test_team_can_be_deleted()
{
$this->migrate();
$team = $this->createTeam();
$action = new DeleteTeam;
$action->delete($team);
$this->assertNull($team->fresh());
}
public function test_team_deletion_can_be_validated()
{
Jetstream::useUserModel(User::class);
$this->migrate();
$team = $this->createTeam();
$action = new ValidateTeamDeletion;
$action->validate($team->owner, $team);
$this->assertTrue(true);
}
public function test_personal_team_cant_be_deleted()
{
$this->expectException(ValidationException::class);
Jetstream::useUserModel(User::class);
$this->migrate();
$team = $this->createTeam();
$team->forceFill(['personal_team' => true])->save();
$action = new ValidateTeamDeletion;
$action->validate($team->owner, $team);
}
public function test_non_owner_cant_delete_team()
{
$this->expectException(AuthorizationException::class);
Jetstream::useUserModel(User::class);
$this->migrate();
$team = $this->createTeam();
$action = new ValidateTeamDeletion;
$action->validate(User::forceCreate([
'name' => 'Adam Wathan',
'email' => 'adam@laravel.com',
'password' => 'secret',
]), $team);
}
protected function createTeam()
{
$action = new CreateTeam;
$user = User::forceCreate([
'name' => 'Taylor Otwell',
'email' => 'taylor@laravel.com',
'password' => 'secret',
]);
return $action->create($user, ['name' => 'Test Team']);
}
protected function migrate()
{
$this->artisan('migrate', ['--database' => 'testbench'])->run();
}
}