|
6 | 6 | use Laravel\Jetstream\Jetstream;
|
7 | 7 | use Laravel\Jetstream\Team;
|
8 | 8 | use Laravel\Jetstream\Tests\Fixtures\User;
|
| 9 | +use Laravel\Sanctum\Sanctum; |
9 | 10 | use Laravel\Sanctum\TransientToken;
|
10 | 11 |
|
11 | 12 | class TeamBehaviorTest extends OrchestraTestCase
|
@@ -54,6 +55,15 @@ public function test_team_relationship_methods()
|
54 | 55 | $otherUser->teams()->attach($team, ['role' => 'editor']);
|
55 | 56 | $otherUser = $otherUser->fresh();
|
56 | 57 |
|
| 58 | + $this->assertTrue($otherUser->belongsToTeam($team)); |
| 59 | + $this->assertFalse($otherUser->ownsTeam($team)); |
| 60 | + |
| 61 | + $this->assertTrue($otherUser->hasTeamPermission($team, 'foo')); |
| 62 | + $this->assertFalse($otherUser->hasTeamPermission($team, 'bar')); |
| 63 | + |
| 64 | + $this->assertTrue($team->userHasPermission($otherUser, 'foo')); |
| 65 | + $this->assertFalse($team->userHasPermission($otherUser, 'bar')); |
| 66 | + |
57 | 67 | $otherUser->withAccessToken(new TransientToken);
|
58 | 68 |
|
59 | 69 | $this->assertTrue($otherUser->belongsToTeam($team));
|
@@ -88,9 +98,25 @@ public function test_has_team_permission_checks_token_permissions()
|
88 | 98 | 'password' => 'secret',
|
89 | 99 | ]);
|
90 | 100 |
|
| 101 | + $authToken = new Sanctum; |
| 102 | + $adam = $authToken->actingAs($adam, ['bar'], []); |
| 103 | + |
91 | 104 | $team->users()->attach($adam, ['role' => 'admin']);
|
92 | 105 |
|
93 | 106 | $this->assertFalse($adam->hasTeamPermission($team, 'foo'));
|
| 107 | + |
| 108 | + $john = User::forceCreate([ |
| 109 | + 'name' => 'John Doe', |
| 110 | + |
| 111 | + 'password' => 'secret', |
| 112 | + ]); |
| 113 | + |
| 114 | + $authToken = new Sanctum; |
| 115 | + $john = $authToken->actingAs($john, ['foo'], []); |
| 116 | + |
| 117 | + $team->users()->attach($john, ['role' => 'admin']); |
| 118 | + |
| 119 | + $this->assertTrue($john->hasTeamPermission($team, 'foo')); |
94 | 120 | }
|
95 | 121 |
|
96 | 122 | protected function migrate()
|
|
0 commit comments