|
10 | 10 | use App\Notifications\ThreadCreated; |
11 | 11 | use Illuminate\Support\Arr; |
12 | 12 | use Illuminate\Support\Facades\Notification; |
| 13 | +use Illuminate\Support\Str; |
13 | 14 | use Illuminate\Testing\PendingCommand; |
14 | 15 | use Tests\TestCase; |
15 | 16 |
|
@@ -207,6 +208,62 @@ public function test_fails_without_users(): void |
207 | 208 | $this->assertNoPingMessagesExist(); |
208 | 209 | } |
209 | 210 |
|
| 211 | + public function test_fails_when_from_is_missing(): void |
| 212 | + { |
| 213 | + $sender = User::factory()->create(); |
| 214 | + $thread = $this->service->newThread('S', $sender, $this->envelope()); |
| 215 | + |
| 216 | + $this->runPing(['--thread' => $thread->id, '--user' => [$sender->id]]) |
| 217 | + ->assertFailed(); |
| 218 | + |
| 219 | + $this->assertNoPingMessagesExist(); |
| 220 | + } |
| 221 | + |
| 222 | + public function test_fails_when_sender_is_not_found(): void |
| 223 | + { |
| 224 | + $creator = User::factory()->create(); |
| 225 | + $participant = User::factory()->create(); |
| 226 | + $thread = $this->service->newThread('S', $creator, $this->envelope(), [$participant->id]); |
| 227 | + |
| 228 | + $this->runPing([ |
| 229 | + '--thread' => $thread->id, |
| 230 | + '--from' => (string) Str::uuid(), |
| 231 | + '--user' => [$participant->id], |
| 232 | + ])->assertFailed(); |
| 233 | + |
| 234 | + $this->assertNoPingMessagesExist(); |
| 235 | + } |
| 236 | + |
| 237 | + public function test_fails_when_a_pinged_user_does_not_exist(): void |
| 238 | + { |
| 239 | + $sender = User::factory()->create(); |
| 240 | + $thread = $this->service->newThread('S', $sender, $this->envelope()); |
| 241 | + |
| 242 | + $this->runPing([ |
| 243 | + '--thread' => $thread->id, |
| 244 | + '--from' => $sender->id, |
| 245 | + '--user' => [(string) Str::uuid()], |
| 246 | + ])->assertFailed(); |
| 247 | + |
| 248 | + $this->assertNoPingMessagesExist(); |
| 249 | + } |
| 250 | + |
| 251 | + public function test_create_mode_fails_gracefully_when_note_exceeds_max_length(): void |
| 252 | + { |
| 253 | + $sender = User::factory()->create(); |
| 254 | + $recipient = User::factory()->create(); |
| 255 | + |
| 256 | + $this->runPing([ |
| 257 | + '--from' => $sender->id, |
| 258 | + '--subject' => 'Heads up', |
| 259 | + '--user' => [$recipient->id], |
| 260 | + '--note' => str_repeat('a', 281), |
| 261 | + ])->assertFailed(); |
| 262 | + |
| 263 | + $this->assertNoPingMessagesExist(); |
| 264 | + $this->assertDatabaseMissing('threads', ['subject' => 'Heads up']); |
| 265 | + } |
| 266 | + |
210 | 267 | private function assertNoPingMessagesExist(): void |
211 | 268 | { |
212 | 269 | $this->assertFalse( |
|
0 commit comments