feat/reverb (#20)
Co-authored-by: jon brookes <marshyon@gmail.com> Reviewed-on: https://codeberg.org/headshed/share-lt/pulls/20
This commit is contained in:
parent
74bc17d019
commit
21147af908
30 changed files with 1948 additions and 29 deletions
77
tests/Feature/NotificationControllerTest.php
Normal file
77
tests/Feature/NotificationControllerTest.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
use App\Events\PreviewSiteBuilt;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
use function Pest\Laravel\actingAs;
|
||||
use function Pest\Laravel\postJson;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
test('send preview site built notification requires authentication', function () {
|
||||
postJson('/api/notifications/preview-site-built', [
|
||||
'message' => 'Test notification',
|
||||
])->assertUnauthorized();
|
||||
});
|
||||
|
||||
test('send preview site built notification requires admin permissions', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
actingAs($user)
|
||||
->postJson('/api/notifications/preview-site-built', [
|
||||
'message' => 'Test notification',
|
||||
])
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('send preview site built notification validates message requirement', function () {
|
||||
$adminEmail = config('app.admin_email');
|
||||
$admin = User::factory()->create(['email' => $adminEmail]);
|
||||
|
||||
actingAs($admin)
|
||||
->postJson('/api/notifications/preview-site-built', [])
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['message']);
|
||||
});
|
||||
|
||||
test('send preview site built notification validates message length', function () {
|
||||
$adminEmail = config('app.admin_email');
|
||||
$admin = User::factory()->create(['email' => $adminEmail]);
|
||||
|
||||
actingAs($admin)
|
||||
->postJson('/api/notifications/preview-site-built', [
|
||||
'message' => str_repeat('a', 256), // 256 characters, over the 255 limit
|
||||
])
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['message']);
|
||||
});
|
||||
|
||||
test('send preview site built notification dispatches event successfully', function () {
|
||||
Event::fake();
|
||||
|
||||
$adminEmail = config('app.admin_email');
|
||||
$admin = User::factory()->create(['email' => $adminEmail]);
|
||||
$message = 'Test preview site notification';
|
||||
|
||||
actingAs($admin)
|
||||
->postJson('/api/notifications/preview-site-built', [
|
||||
'message' => $message,
|
||||
])
|
||||
->assertSuccessful()
|
||||
->assertJsonStructure([
|
||||
'success',
|
||||
'message',
|
||||
'data' => [
|
||||
'notification_message',
|
||||
],
|
||||
])
|
||||
->assertJsonPath('success', true)
|
||||
->assertJsonPath('data.notification_message', $message);
|
||||
|
||||
Event::assertDispatched(PreviewSiteBuilt::class, function ($event) use ($message) {
|
||||
return $event->message === $message
|
||||
&& $event->type === 'success';
|
||||
});
|
||||
});
|
||||
23
tests/Feature/PreviewSiteBuiltEventTest.php
Normal file
23
tests/Feature/PreviewSiteBuiltEventTest.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
use App\Events\PreviewSiteBuilt;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
it('can broadcast preview site built event', function () {
|
||||
Event::fake();
|
||||
|
||||
PreviewSiteBuilt::dispatch('Test preview site is built', 'success');
|
||||
|
||||
Event::assertDispatched(PreviewSiteBuilt::class, function ($event) {
|
||||
return $event->message === 'Test preview site is built'
|
||||
&& $event->type === 'success';
|
||||
});
|
||||
});
|
||||
|
||||
it('has correct broadcast channel and event name', function () {
|
||||
$event = new PreviewSiteBuilt('Test message', 'success');
|
||||
|
||||
expect($event->broadcastOn())->toHaveCount(1)
|
||||
->and($event->broadcastOn()[0]->name)->toBe('filament-notifications')
|
||||
->and($event->broadcastAs())->toBe('preview-site.built');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue