Skip to content

Commit 03bfda4

Browse files
author
Chri$
committed
test:LAR-8 write test for send telegram notification after user submit article
1 parent 6ad6805 commit 03bfda4

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

tests/Feature/Article/SendTelegramNotificationTest.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,42 @@
33
declare(strict_types=1);
44

55
use App\Livewire\Articles\Create;
6-
use App\Models\User;
6+
use App\Models\Article;
7+
use App\Notifications\PostArticleToTelegram;
8+
use Illuminate\Support\Facades\Notification;
79
use Livewire\Livewire;
810

9-
test('Send notification on telegram after submition on article', function (): void {
10-
// 1- se rassurer que le user est bien connecté
11-
$user = User::factory()->create();
11+
beforeEach(function (): void {
12+
$this->user = $this->login();
13+
});
14+
15+
test('Send notification on telegram after submition on article', function () {
16+
1217
// 2- soumission d'article par le user connecté
13-
Livewire::actingAs($user)->test(Create::class)
18+
$article = Livewire::actingAs($this->user)->test(Create::class)
1419
->set('title', 'Test Article')
1520
->set('slug', 'test-article')
1621
->set('body', 'This is a test article')
1722
->set('published_at', now())
18-
->set('submitted_at', null)
23+
->set('submitted_at', now())
1924
->set('approved_at', null)
2025
->set('show_toc', true)
2126
->set('canonical_url', 'https://laravel.cm')
2227
->set('associateTags', ['tag1', 'tag2'])
23-
->store();
28+
->call('store');
29+
30+
expect(Article::count())
31+
->toBe(1);
2432

2533
// 3- Envois de la notification au modérateur sur un channel telegram
34+
if ($article->submitted_at) {
35+
Notification::assertSentTo(
36+
notifiable: $this->user,
37+
notification: PostArticleToTelegram::class
38+
);
39+
}
40+
41+
42+
Notification::assertCount(1);
2643

2744
});

0 commit comments

Comments
 (0)