-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathProcessLaunchpadTest.php
More file actions
192 lines (176 loc) · 6.4 KB
/
Copy pathProcessLaunchpadTest.php
File metadata and controls
192 lines (176 loc) · 6.4 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
namespace Tests\Feature\Api;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessLaunchpad;
use ProcessMaker\Models\ProcessRequest;
use Tests\Feature\Shared\RequestHelper;
use Tests\TestCase;
class ProcessLaunchpadTest extends TestCase
{
use RequestHelper, RefreshDatabase;
const API_TEST_URL = '/process_launchpad';
const STRUCTURE = [
'launchpad',
'media',
'embed',
];
/**
* Test get process launchpad
*/
public function testGetProcessLaunchpad()
{
// Create data
$process = Process::factory()->create();
// Call the api GET
$response = $this->apiCall('GET', self::API_TEST_URL . '/' . $process->id);
// Validate the header status code
$response->assertStatus(200);
$this->assertNotEmpty($response);
// Create data related with the auth user
$user = Auth::user();
$process = Process::factory()->create();
ProcessLaunchpad::factory()->create([
'process_id' => $process->id,
'user_id' => $user->id,
]);
// Call the api GET
$response = $this->apiCall('GET', self::API_TEST_URL . '/' . $process->id);
// Validate the header status code
$response->assertStatus(200);
$this->assertNotEmpty($response);
}
/**
* Test store process launchpad
*/
public function testStoreProcessLaunchpad()
{
// Create data
$process = Process::factory()->create();
ProcessLaunchpad::factory()->create([
'process_id' => $process->id,
]);
// Call the api PUT
$values = json_encode(['icon' => 'fa-user']);
$response = $this->apiCall('PUT', self::API_TEST_URL . '/' . $process->id, ['properties' => $values]);
// Validate the header status code
$response->assertStatus(200);
}
/**
* Test delete process launchpad
*/
public function testDeleteProcessLaunchpad()
{
// Create data
$launchpad = ProcessLaunchpad::factory()->create();
// Call the api DELETE
$response = $this->apiCall('DELETE', self::API_TEST_URL . '/' . $launchpad->id);
// Validate the header status code
$response->assertStatus(204);
}
/**
* Test get stages count per process when stages are null.
*/
public function testGetStagesCountPerProcessWhenStagesIsNull()
{
// Create data
$process = Process::factory()->create();
// Call the api GET
$response = $this->apiCall('GET', self::API_TEST_URL . '/' . $process->id);
// Validate the header status code
$response->assertStatus(200);
$this->assertNotEmpty($response);
// Create data related with the auth user
$user = Auth::user();
$process = Process::factory()->create([
'stages' => null,
]);
ProcessLaunchpad::factory()->create([
'process_id' => $process->id,
'user_id' => $user->id,
]);
ProcessRequest::factory()->create();
// Call the api GET
$response = $this->apiCall('GET', self::API_TEST_URL . '/' . $process->id);
// Validate the header status code
$response->assertStatus(200);
$this->assertNotEmpty($response);
$this->assertEquals(null, $response->json('stagesSummary'));
}
/**
* Test get stages count per process when there are stages but no ProcessRequests.
*/
public function testGetStagesCountPerProcessWithStagesAndNoRequests()
{
// Create stages for the process
$stages = [
['id' => 1, 'name' => 'Stage A', 'order' => 1],
['id' => 2, 'name' => 'Stage B', 'order' => 2],
];
// Create a process with stages
$process = Process::factory()->create([
'stages' => $stages,
]);
ProcessLaunchpad::factory()->create([
'process_id' => $process->id,
]);
// No ProcessRequest records are created for this test
$stageSummary = $process->getStagesSummary($stages);
$expectedStagesSummary = [
['id' => 1, 'name' => 'Stage A', 'count' => 0, 'percentage' => 0],
['id' => 2, 'name' => 'Stage B', 'count' => 0, 'percentage' => 0],
];
// Check if the stagesSummary matches the expected output
$this->assertEquals($expectedStagesSummary, $stageSummary);
}
/**
* Test get stages count per process.
*/
public function testGetStagesCountPerProcess()
{
// Create stages for the process
$stages = [
['id' => 1, 'name' => 'Stage 1', 'order' => 1],
['id' => 2, 'name' => 'Stage 2', 'order' => 3],
['id' => 3, 'name' => 'Stage 3', 'order' => 2],
];
// Create a process
$process = Process::factory()->create([
'stages' => $stages,
]);
ProcessLaunchpad::factory()->create([
'process_id' => $process->id,
]);
// Create requests associated with the process
ProcessRequest::factory(2)->create([
'process_id' => $process->id,
'last_stage_id' => 1,
'last_stage_name' => 'Stage 1',
]);
ProcessRequest::factory(3)->create([
'process_id' => $process->id,
'last_stage_id' => 2,
'last_stage_name' => 'Stage 2',
]);
ProcessRequest::factory(5)->create([
'process_id' => $process->id,
'last_stage_id' => 3,
'last_stage_name' => 'Stage 3',
]);
// Call the API GET
$response = $this->apiCall('GET', self::API_TEST_URL . '/' . $process->id);
$stageSummary = $process->getStagesSummary($stages);
// Validate the header status code
$response->assertStatus(200);
$this->assertNotEmpty($response);
// Validate the stagesSummary in the response
$expectedStagesSummary = [
['id' => 1, 'name' => 'Stage 1', 'count' => 2, 'percentage' => 20],
['id' => 2, 'name' => 'Stage 2', 'count' => 3, 'percentage' => 30],
['id' => 3, 'name' => 'Stage 3', 'count' => 5, 'percentage' => 50],
];
// Check if the stagesSummary matches the expected output
$this->assertEquals($expectedStagesSummary, $stageSummary);
}
}