Skip to content

Commit

Permalink
test:LAR-8 write test for send telegram notification after user submi…
Browse files Browse the repository at this point in the history
…t article
  • Loading branch information
Chri$ committed Oct 8, 2024
1 parent 6ad6805 commit 03bfda4
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions tests/Feature/Article/SendTelegramNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,42 @@
declare(strict_types=1);

use App\Livewire\Articles\Create;
use App\Models\User;
use App\Models\Article;
use App\Notifications\PostArticleToTelegram;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;

test('Send notification on telegram after submition on article', function (): void {
// 1- se rassurer que le user est bien connecté
$user = User::factory()->create();
beforeEach(function (): void {
$this->user = $this->login();
});

test('Send notification on telegram after submition on article', function () {

// 2- soumission d'article par le user connecté
Livewire::actingAs($user)->test(Create::class)
$article = Livewire::actingAs($this->user)->test(Create::class)
->set('title', 'Test Article')
->set('slug', 'test-article')
->set('body', 'This is a test article')
->set('published_at', now())
->set('submitted_at', null)
->set('submitted_at', now())
->set('approved_at', null)
->set('show_toc', true)
->set('canonical_url', 'https://laravel.cm')
->set('associateTags', ['tag1', 'tag2'])
->store();
->call('store');

expect(Article::count())
->toBe(1);

// 3- Envois de la notification au modérateur sur un channel telegram
if ($article->submitted_at) {
Notification::assertSentTo(
notifiable: $this->user,
notification: PostArticleToTelegram::class
);
}


Notification::assertCount(1);

});

0 comments on commit 03bfda4

Please sign in to comment.