mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
backend notifications implementation
This commit is contained in:
134
tests/Domain/Notifications/NotificationsTest.php
Normal file
134
tests/Domain/Notifications/NotificationsTest.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Domain\Notifications;
|
||||
|
||||
use App\Users\Models\User;
|
||||
use Tests\TestCase;
|
||||
use Str;
|
||||
use DB;
|
||||
|
||||
class NotificationsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_all_notifications()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
DB::table('notifications')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'type' => 'Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification',
|
||||
'notifiable_type' => 'App\Users\Models\User',
|
||||
'notifiable_id' => $user->id,
|
||||
'data' => json_encode([
|
||||
'type' => 'file-request',
|
||||
'title' => 'File Request Filled',
|
||||
'description' => "Your file request for 'Documents' folder was filled successfully.",
|
||||
'action' => [
|
||||
'type' => 'route',
|
||||
'params' => [
|
||||
'route' => 'Files',
|
||||
'button' => 'Show Files',
|
||||
'id' => Str::uuid(),
|
||||
],
|
||||
],
|
||||
]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->getJson('/api/user/notifications')
|
||||
->assertJsonFragment([
|
||||
'type' => 'file-request',
|
||||
])
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_mark_as_read_notifications()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
DB::table('notifications')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'type' => 'Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification',
|
||||
'notifiable_type' => 'App\Users\Models\User',
|
||||
'notifiable_id' => $user->id,
|
||||
'data' => json_encode([
|
||||
'type' => 'file-request',
|
||||
'title' => 'File Request Filled',
|
||||
'description' => "Your file request for 'Documents' folder was filled successfully.",
|
||||
'action' => [
|
||||
'type' => 'route',
|
||||
'params' => [
|
||||
'route' => 'Files',
|
||||
'button' => 'Show Files',
|
||||
'id' => Str::uuid(),
|
||||
],
|
||||
],
|
||||
]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson('/api/user/notifications/read')
|
||||
->assertStatus(204);
|
||||
|
||||
$this->assertDatabaseHas('notifications', [
|
||||
'read_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_delete_all_notifications()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
DB::table('notifications')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'type' => 'Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification',
|
||||
'notifiable_type' => 'App\Users\Models\User',
|
||||
'notifiable_id' => $user->id,
|
||||
'data' => json_encode([
|
||||
'type' => 'file-request',
|
||||
'title' => 'File Request Filled',
|
||||
'description' => "Your file request for 'Documents' folder was filled successfully.",
|
||||
'action' => [
|
||||
'type' => 'route',
|
||||
'params' => [
|
||||
'route' => 'Files',
|
||||
'button' => 'Show Files',
|
||||
'id' => Str::uuid(),
|
||||
],
|
||||
],
|
||||
]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->deleteJson('/api/user/notifications')
|
||||
->assertStatus(204);
|
||||
|
||||
$this->assertDatabaseCount('notifications', 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user