|
12 | 12 | use ProcessMaker\Models\InboxRule; |
13 | 13 | use ProcessMaker\Models\InboxRuleLog; |
14 | 14 | use ProcessMaker\Models\Media; |
| 15 | +use ProcessMaker\Models\Notification; |
15 | 16 | use ProcessMaker\Models\ProcessAbeRequestToken; |
16 | 17 | use ProcessMaker\Models\ProcessRequest; |
17 | 18 | use ProcessMaker\Models\ProcessRequestLock; |
@@ -152,6 +153,70 @@ public function testDeleteCaseRemovesDependentRecords(): void |
152 | 153 | } |
153 | 154 | } |
154 | 155 |
|
| 156 | + public function testDeleteCaseRemovesCaseNotifications(): void |
| 157 | + { |
| 158 | + $caseNumber = 13579; |
| 159 | + $request = ProcessRequest::factory() |
| 160 | + ->withCaseNumber($caseNumber) |
| 161 | + ->create(); |
| 162 | + $otherRequest = ProcessRequest::factory() |
| 163 | + ->withCaseNumber($caseNumber + 1) |
| 164 | + ->create(); |
| 165 | + |
| 166 | + $notificationTypes = [ |
| 167 | + 'COMMENT', |
| 168 | + 'FILE_SHARED', |
| 169 | + 'TASK_CREATED', |
| 170 | + 'TASK_COMPLETED', |
| 171 | + 'TASK_REASSIGNED', |
| 172 | + ]; |
| 173 | + |
| 174 | + $deletedNotificationIds = []; |
| 175 | + foreach ($notificationTypes as $type) { |
| 176 | + $deletedNotificationIds[] = Notification::factory()->create([ |
| 177 | + 'notifiable_type' => get_class($this->user), |
| 178 | + 'notifiable_id' => $this->user->getKey(), |
| 179 | + 'data' => json_encode([ |
| 180 | + 'type' => $type, |
| 181 | + 'request_id' => $request->id, |
| 182 | + 'url' => "/requests/{$request->id}", |
| 183 | + ]), |
| 184 | + 'url' => "/requests/{$request->id}", |
| 185 | + ])->id; |
| 186 | + } |
| 187 | + |
| 188 | + $keptDifferentRequest = Notification::factory()->create([ |
| 189 | + 'notifiable_type' => get_class($this->user), |
| 190 | + 'notifiable_id' => $this->user->getKey(), |
| 191 | + 'data' => json_encode([ |
| 192 | + 'type' => 'TASK_CREATED', |
| 193 | + 'request_id' => $otherRequest->id, |
| 194 | + 'url' => "/requests/{$otherRequest->id}", |
| 195 | + ]), |
| 196 | + 'url' => "/requests/{$otherRequest->id}", |
| 197 | + ]); |
| 198 | + |
| 199 | + $keptDifferentType = Notification::factory()->create([ |
| 200 | + 'notifiable_type' => get_class($this->user), |
| 201 | + 'notifiable_id' => $this->user->getKey(), |
| 202 | + 'data' => json_encode([ |
| 203 | + 'type' => 'MESSAGE', |
| 204 | + 'request_id' => $request->id, |
| 205 | + 'url' => "/requests/{$request->id}", |
| 206 | + ]), |
| 207 | + 'url' => "/requests/{$request->id}", |
| 208 | + ]); |
| 209 | + |
| 210 | + $response = $this->apiCall('DELETE', route('api.cases.destroy', ['case_number' => $caseNumber])); |
| 211 | + |
| 212 | + $response->assertStatus(204); |
| 213 | + foreach ($deletedNotificationIds as $notificationId) { |
| 214 | + $this->assertDatabaseMissing('notifications', ['id' => $notificationId]); |
| 215 | + } |
| 216 | + $this->assertDatabaseHas('notifications', ['id' => $keptDifferentRequest->id]); |
| 217 | + $this->assertDatabaseHas('notifications', ['id' => $keptDifferentType->id]); |
| 218 | + } |
| 219 | + |
155 | 220 | public function testDeleteCaseReturnsNotFoundWhenMissing(): void |
156 | 221 | { |
157 | 222 | $caseNumber = 99999; |
|
0 commit comments