mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +00:00
134 lines
4.4 KiB
PHP
134 lines
4.4 KiB
PHP
<?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);
|
|
}
|
|
} |