backend notifications implementation

This commit is contained in:
Čarodej
2022-03-10 11:49:02 +01:00
parent 70d7f2f5bd
commit 64e80d387b
20 changed files with 617 additions and 280 deletions

View 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);
}
}