forked from laravel/jetstream
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCurrentTeamControllerTest.php
81 lines (60 loc) · 2.13 KB
/
CurrentTeamControllerTest.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
<?php
namespace Laravel\Jetstream\Tests;
use App\Actions\Jetstream\CreateTeam;
use App\Models\Team;
use Illuminate\Support\Facades\Gate;
use Laravel\Jetstream\Jetstream;
use Laravel\Jetstream\Tests\Fixtures\TeamPolicy;
use Laravel\Jetstream\Tests\Fixtures\User;
class CurrentTeamControllerTest extends OrchestraTestCase
{
public function setUp(): void
{
parent::setUp();
Gate::policy(Team::class, TeamPolicy::class);
Jetstream::useUserModel(User::class);
}
public function test_can_switch_to_team_the_user_belongs_to()
{
$this->migrate();
$action = new CreateTeam;
$user = User::forceCreate([
'name' => 'Taylor Otwell',
'email' => 'taylor@laravel.com',
'password' => 'secret',
]);
$team = $action->create($user, ['name' => 'Test Team']);
$response = $this->actingAs($user)->put('/current-team', ['team_id' => $team->id]);
$response->assertRedirect('/home');
$this->assertEquals($team->id, $user->fresh()->currentTeam->id);
$this->assertTrue($user->isCurrentTeam($team));
}
public function test_cant_switch_to_team_the_user_does_not_belong_to()
{
$this->migrate();
$action = new CreateTeam;
$user = User::forceCreate([
'name' => 'Taylor Otwell',
'email' => 'taylor@laravel.com',
'password' => 'secret',
]);
$team = $action->create($user, ['name' => 'Test Team']);
$otherUser = User::forceCreate([
'name' => 'Adam Wathan',
'email' => 'adam@laravel.com',
'password' => 'secret',
]);
$response = $this->actingAs($otherUser)->put('/current-team', ['team_id' => $team->id]);
$response->assertStatus(403);
}
protected function migrate()
{
$this->artisan('migrate', ['--database' => 'testbench'])->run();
}
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('jetstream.stack', 'livewire');
$app['config']->set('jetstream.features', ['teams']);
}
}