Skip to content

Commit a2abed5

Browse files
committed
test: cover thread:ping input-validation and create-mode envelope failure paths
1 parent 4c83b2a commit a2abed5

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/Feature/PingThreadUsersCommandTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Notifications\ThreadCreated;
1111
use Illuminate\Support\Arr;
1212
use Illuminate\Support\Facades\Notification;
13+
use Illuminate\Support\Str;
1314
use Illuminate\Testing\PendingCommand;
1415
use Tests\TestCase;
1516

@@ -207,6 +208,62 @@ public function test_fails_without_users(): void
207208
$this->assertNoPingMessagesExist();
208209
}
209210

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+
210267
private function assertNoPingMessagesExist(): void
211268
{
212269
$this->assertFalse(

0 commit comments

Comments
 (0)