|
11 | 11 | use App\Models\Team; |
12 | 12 | use App\Models\User; |
13 | 13 | use Illuminate\Foundation\Testing\RefreshDatabase; |
| 14 | +use Illuminate\Support\Facades\Gate; |
14 | 15 |
|
15 | 16 | uses(RefreshDatabase::class); |
16 | 17 |
|
|
123 | 124 | $response->assertStatus(404); |
124 | 125 | }); |
125 | 126 |
|
| 127 | + test('returns 403 when target environment update is denied', function () { |
| 128 | + $application = Application::factory()->create([ |
| 129 | + 'environment_id' => $this->environment->id, |
| 130 | + 'destination_id' => $this->destination->id, |
| 131 | + 'destination_type' => $this->destination->getMorphClass(), |
| 132 | + ]); |
| 133 | + |
| 134 | + Gate::before(function (User $user, string $ability, array $arguments) { |
| 135 | + $target = $arguments[0] ?? null; |
| 136 | + |
| 137 | + if ($ability === 'update' && $target instanceof Environment && $target->is($this->targetEnvironment)) { |
| 138 | + return false; |
| 139 | + } |
| 140 | + |
| 141 | + return null; |
| 142 | + }); |
| 143 | + |
| 144 | + $response = $this->withHeaders([ |
| 145 | + 'Authorization' => 'Bearer '.$this->bearerToken, |
| 146 | + 'Content-Type' => 'application/json', |
| 147 | + ])->postJson("/api/v1/applications/{$application->uuid}/move", [ |
| 148 | + 'environment_uuid' => $this->targetEnvironment->uuid, |
| 149 | + ]); |
| 150 | + |
| 151 | + $response->assertForbidden(); |
| 152 | + |
| 153 | + $application->refresh(); |
| 154 | + expect($application->environment_id)->toBe($this->environment->id); |
| 155 | + }); |
| 156 | + |
126 | 157 | test('returns 400 when application is already in the target environment', function () { |
127 | 158 | $application = Application::factory()->create([ |
128 | 159 | 'environment_id' => $this->environment->id, |
|
0 commit comments