|
6 | 6 | use App\Models\Thread; |
7 | 7 | use App\Models\User; |
8 | 8 | use App\Notifications\MentionNotification; |
| 9 | +use App\Rules\InvalidMentionRule; |
9 | 10 | use Illuminate\Foundation\Testing\DatabaseMigrations; |
10 | 11 | use Illuminate\Notifications\DatabaseNotification; |
11 | 12 | use Illuminate\Support\Facades\Notification; |
|
217 | 218 |
|
218 | 219 | Notification::assertNothingSent(); |
219 | 220 | }); |
| 221 | + |
| 222 | +test('cannot fake a mention when creating a reply', function () { |
| 223 | + $thread = Thread::factory()->create(['subject' => 'The first thread', 'slug' => 'the-first-thread']); |
| 224 | + |
| 225 | + $this->login(); |
| 226 | + |
| 227 | + $response = $this->post('/replies', [ |
| 228 | + 'body' => 'Hey [@joedixon](https://somethingnasty.com)', |
| 229 | + 'replyable_id' => $thread->id, |
| 230 | + 'replyable_type' => Thread::TABLE, |
| 231 | + ]); |
| 232 | + |
| 233 | + $response->assertSessionHas('error', 'Something went wrong. Please review the fields below.'); |
| 234 | + $response->assertSessionHasErrors(['body' => 'The body field contains an invalid mention.']); |
| 235 | +}); |
| 236 | + |
| 237 | +test('users cannot edit a reply with a fake mention', function () { |
| 238 | + $user = $this->createUser(); |
| 239 | + $thread = Thread::factory()->create(['slug' => 'the-first-thread']); |
| 240 | + $reply = Reply::factory()->create(['author_id' => $user->id(), 'replyable_id' => $thread->id()]); |
| 241 | + |
| 242 | + $this->actingAs($user); |
| 243 | + |
| 244 | + Livewire::test(EditReply::class, ['reply' => $reply]) |
| 245 | + ->call('updateReply', 'Hey [@joedixon](https://somethingnasty.com)') |
| 246 | + ->assertHasErrors(['body' => InvalidMentionRule::class]); |
| 247 | +}); |
0 commit comments