|
3 | 3 | declare(strict_types=1);
|
4 | 4 |
|
5 | 5 | 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; |
7 | 9 | use Livewire\Livewire;
|
8 | 10 |
|
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 | + |
12 | 17 | // 2- soumission d'article par le user connecté
|
13 |
| - Livewire::actingAs($user)->test(Create::class) |
| 18 | + $article = Livewire::actingAs($this->user)->test(Create::class) |
14 | 19 | ->set('title', 'Test Article')
|
15 | 20 | ->set('slug', 'test-article')
|
16 | 21 | ->set('body', 'This is a test article')
|
17 | 22 | ->set('published_at', now())
|
18 |
| - ->set('submitted_at', null) |
| 23 | + ->set('submitted_at', now()) |
19 | 24 | ->set('approved_at', null)
|
20 | 25 | ->set('show_toc', true)
|
21 | 26 | ->set('canonical_url', 'https://laravel.cm')
|
22 | 27 | ->set('associateTags', ['tag1', 'tag2'])
|
23 |
| - ->store(); |
| 28 | + ->call('store'); |
| 29 | + |
| 30 | + expect(Article::count()) |
| 31 | + ->toBe(1); |
24 | 32 |
|
25 | 33 | // 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); |
26 | 43 |
|
27 | 44 | });
|
0 commit comments