-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathProcessRequestPolicyTest.php
More file actions
75 lines (59 loc) · 2.17 KB
/
Copy pathProcessRequestPolicyTest.php
File metadata and controls
75 lines (59 loc) · 2.17 KB
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
<?php
namespace Tests\Feature\Api;
use Database\Seeders\PermissionSeeder;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Models\User;
use ProcessMaker\Providers\AuthServiceProvider;
use Tests\Feature\Shared\RequestHelper;
use Tests\TestCase;
/**
* Additional tests in tests/Traits/ForUserScopeTest.php
*/
class ProcessRequestPolicyTest extends TestCase
{
use RequestHelper;
public $withPermissions = true;
public function withUserSetup()
{
// Make $this->user a regular user instead of an admin user
$this->user = User::factory()->create();
}
public function testUserStartedProcessRequest()
{
$request = ProcessRequest::factory()->create(['user_id' => $this->user->id]);
$anotherUser = User::factory()->create();
$anotherRequest = ProcessRequest::factory()->create(['user_id' => $anotherUser->id]);
$route = route('api.requests.show', [$anotherRequest]);
$response = $this->apiCall('GET', $route);
$response->assertStatus(403);
$route = route('api.requests.show', [$request]);
$response = $this->apiCall('GET', $route);
$response->assertStatus(200);
}
public function testUserHasParticipated()
{
$request = ProcessRequest::factory()->create();
$route = route('api.requests.show', [$request]);
$response = $this->apiCall('GET', $route);
$response->assertStatus(403);
// Make user a participant
ProcessRequestToken::factory()->create([
'user_id' => $this->user->id,
'process_request_id' => $request->id,
]);
$response = $this->apiCall('GET', $route);
$response->assertStatus(200);
}
public function testUserHasPermission()
{
$request = ProcessRequest::factory()->create();
$route = route('api.requests.show', [$request]);
$response = $this->apiCall('GET', $route);
$response->assertStatus(403);
$this->user->giveDirectPermission('view-all_requests');
$this->user->refresh();
$response = $this->apiCall('GET', $route);
$response->assertStatus(200);
}
}