mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-24 13:44:42 +00:00
deleted pro files
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
<?php
|
||||
namespace Tests\Domain\Notifications;
|
||||
|
||||
use DB;
|
||||
use Str;
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
|
||||
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([
|
||||
'category' => '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([
|
||||
'category' => '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);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
namespace Tests\Domain\Pages;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Domain\Pages\Actions\SeedDefaultPagesAction;
|
||||
|
||||
class AdminPagesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_all_pages()
|
||||
{
|
||||
resolve(SeedDefaultPagesAction::class)();
|
||||
|
||||
$admin = User::factory()
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
collect(['terms-of-service', 'privacy-policy', 'cookie-policy'])
|
||||
->each(function ($slug) {
|
||||
$this->getJson('/api/admin/pages')
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'slug' => $slug,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_page()
|
||||
{
|
||||
resolve(SeedDefaultPagesAction::class)();
|
||||
|
||||
$admin = User::factory()
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
$this
|
||||
->actingAs($admin)
|
||||
->getJson('/api/admin/pages/terms-of-service')
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'slug' => 'terms-of-service',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_update_page()
|
||||
{
|
||||
resolve(SeedDefaultPagesAction::class)();
|
||||
|
||||
$admin = User::factory()
|
||||
->create(['role' => 'admin']);
|
||||
|
||||
$this
|
||||
->actingAs($admin)
|
||||
->patchJson('/api/admin/pages/terms-of-service', [
|
||||
'name' => 'title',
|
||||
'value' => 'New Title',
|
||||
])->assertStatus(204);
|
||||
|
||||
$this->assertDatabaseHas('pages', [
|
||||
'title' => 'New Title',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
namespace Tests\Domain\Pages;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Domain\Pages\Actions\SeedDefaultPagesAction;
|
||||
|
||||
class PagesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_legal_page()
|
||||
{
|
||||
resolve(SeedDefaultPagesAction::class)();
|
||||
|
||||
$this->getJson('/api/page/terms-of-service')
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'title' => 'Terms of Service',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
<?php
|
||||
namespace Tests\Domain\Teams;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Domain\Teams\Models\TeamFolderMember;
|
||||
|
||||
class TeamFileAccessTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function team_member_download_folder_as_zip()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
collect([0, 1])
|
||||
->each(function ($index) use ($folder, $user) {
|
||||
$file = UploadedFile::fake()
|
||||
->create("fake-file-$index.pdf", 1200, 'application/pdf');
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson('/api/upload', [
|
||||
'name' => $file->name,
|
||||
'extension' => 'pdf',
|
||||
'file' => $file,
|
||||
'parent_id' => $folder->id,
|
||||
'path' => "/$file->name",
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
});
|
||||
|
||||
$member = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
// Attach user into members
|
||||
TeamFolderMember::create([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->getJson("/api/zip?items=$folder->id|folder")
|
||||
->assertStatus(200)
|
||||
->assertHeader('content-type', 'application/x-zip');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function team_member_download_files_as_zip()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
collect([0, 1])
|
||||
->each(function ($index) use ($folder, $user) {
|
||||
$file = UploadedFile::fake()
|
||||
->create("fake-file-$index.pdf", 1200, 'application/pdf');
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson('/api/upload', [
|
||||
'name' => $file->name,
|
||||
'extension' => 'pdf',
|
||||
'file' => $file,
|
||||
'parent_id' => $folder->id,
|
||||
'path' => "/$file->name",
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
});
|
||||
|
||||
$member = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
// Attach user into members
|
||||
TeamFolderMember::create([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
$files = File::all();
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->getJson("/api/zip?items={$files->first()->id}|file,{$files->last()->id}|file")
|
||||
->assertStatus(200)
|
||||
->assertHeader('content-type', 'application/x-zip');
|
||||
}
|
||||
}
|
||||
@@ -1,758 +0,0 @@
|
||||
<?php
|
||||
namespace Tests\Domain\Teams;
|
||||
|
||||
use Str;
|
||||
use Notification;
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Domain\Teams\Models\TeamFolderInvitation;
|
||||
use Domain\Teams\Notifications\InvitationIntoTeamFolder;
|
||||
|
||||
class TeamManagementTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_team_folder_invite()
|
||||
{
|
||||
[$inviter, $member] = User::factory()
|
||||
->hasSettings()
|
||||
->count(2)
|
||||
->create();
|
||||
|
||||
$invitation = TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'inviter_id' => $inviter->id,
|
||||
'parent_id' => Str::uuid(),
|
||||
'email' => $member->email,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
$this->getJson("/api/teams/invitations/{$invitation->id}")
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'name' => $inviter->settings->name,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_accept_team_folder_invite_as_registered_user()
|
||||
{
|
||||
$member = User::factory()
|
||||
->create([
|
||||
'email' => 'john@internal.com',
|
||||
]);
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create();
|
||||
|
||||
$invitation = TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'email' => $member->email,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-view',
|
||||
]);
|
||||
|
||||
DB::table('notifications')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'type' => 'Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification',
|
||||
'notifiable_type' => 'App\Users\Models\User',
|
||||
'notifiable_id' => $member->id,
|
||||
'data' => json_encode([
|
||||
'type' => 'team-invitation',
|
||||
'title' => 'New Team Invitation',
|
||||
'description' => 'Jane Doe invite you to join into Team Folder..',
|
||||
'action' => [
|
||||
'type' => 'invitation',
|
||||
'params' => [
|
||||
'type' => 'invitation',
|
||||
'params' => [
|
||||
'id' => $invitation->id,
|
||||
],
|
||||
],
|
||||
],
|
||||
]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->putJson("/api/teams/invitations/{$invitation->id}")
|
||||
->assertNoContent();
|
||||
|
||||
// Get notification
|
||||
$notification = json_decode(DB::table('notifications')->first()->data);
|
||||
|
||||
// Check if action is null
|
||||
$this->assertEquals(null, $notification->action);
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'accepted',
|
||||
])
|
||||
->assertDatabaseHas('team_folder_members', [
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-view',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_accept_team_folder_invite_as_guest_user()
|
||||
{
|
||||
$folder = Folder::factory()
|
||||
->create();
|
||||
|
||||
$invitation = TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
$this
|
||||
->putJson("/api/teams/invitations/{$invitation->id}")
|
||||
->assertNoContent();
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'waiting-for-registration',
|
||||
])
|
||||
->assertDatabaseMissing('team_folder_members', [
|
||||
'parent_id' => $folder->id,
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_apply_accepted_invitation_after_user_registration()
|
||||
{
|
||||
$invitation = TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'email' => 'john@doe.com',
|
||||
'status' => 'waiting-for-registration',
|
||||
]);
|
||||
|
||||
$this->postJson('api/register', [
|
||||
'email' => 'john@doe.com',
|
||||
'password' => 'SecretPassword',
|
||||
'password_confirmation' => 'SecretPassword',
|
||||
'name' => 'John Doe',
|
||||
])->assertStatus(201);
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'parent_id' => $invitation->parent_id,
|
||||
'status' => 'accepted',
|
||||
])
|
||||
->assertDatabaseHas('team_folder_members', [
|
||||
'parent_id' => $invitation->parent_id,
|
||||
'user_id' => User::first()->id,
|
||||
'permission' => $invitation->permission,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_used_team_folder_invite()
|
||||
{
|
||||
$invitation = TeamFolderInvitation::factory()
|
||||
->create(['status' => 'accepted']);
|
||||
|
||||
$this
|
||||
->getJson("/api/teams/invitations/{$invitation->id}")
|
||||
->assertStatus(410);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_reject_team_folder_invite()
|
||||
{
|
||||
$member = User::factory()
|
||||
->create([
|
||||
'email' => 'john@internal.com',
|
||||
]);
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create();
|
||||
|
||||
$invitation = TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'email' => $member->email,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
DB::table('notifications')
|
||||
->insert([
|
||||
'id' => Str::uuid(),
|
||||
'type' => 'Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification',
|
||||
'notifiable_type' => 'App\Users\Models\User',
|
||||
'notifiable_id' => $member->id,
|
||||
'data' => json_encode([
|
||||
'type' => 'team-invitation',
|
||||
'title' => 'New Team Invitation',
|
||||
'description' => 'Jane Doe invite you to join into Team Folder..',
|
||||
'action' => [
|
||||
'type' => 'invitation',
|
||||
'params' => [
|
||||
'type' => 'invitation',
|
||||
'params' => [
|
||||
'id' => $invitation->id,
|
||||
],
|
||||
],
|
||||
],
|
||||
]),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->deleteJson("/api/teams/invitations/{$invitation->id}")
|
||||
->assertNoContent();
|
||||
|
||||
// Get notification
|
||||
$notification = json_decode(DB::table('notifications')->first()->data);
|
||||
|
||||
// Check if action is null
|
||||
$this->assertEquals(null, $notification->action);
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'rejected',
|
||||
])
|
||||
->assertDatabaseMissing('team_folder_members', [
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_invite_member_into_team_folder()
|
||||
{
|
||||
[$user, $member_1, $member_2] = User::factory()
|
||||
->hasSettings()
|
||||
->count(3)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
'email' => 'existing@member.com',
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_1->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_2->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/teams/folders/{$folder->id}", [
|
||||
'members' => [
|
||||
[
|
||||
'id' => $member_1->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'id' => $member_2->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
],
|
||||
'invitations' => [
|
||||
[
|
||||
'id' => null,
|
||||
'email' => 'existing@member.com',
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'id' => null,
|
||||
'email' => 'added@member.com',
|
||||
'permission' => 'can-view',
|
||||
],
|
||||
],
|
||||
])
|
||||
->assertCreated();
|
||||
|
||||
$this
|
||||
->assertDatabaseCount('team_folder_members', 2)
|
||||
->assertDatabaseCount('team_folder_invitations', 2)
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'email' => 'added@member.com',
|
||||
'permission' => 'can-view',
|
||||
]);
|
||||
|
||||
Notification::assertTimesSent(1, InvitationIntoTeamFolder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_delete_invited_member_from_team_folder()
|
||||
{
|
||||
[$user, $member_1, $member_2] = User::factory()
|
||||
->hasSettings()
|
||||
->count(3)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
'email' => 'deleted@member.com',
|
||||
]);
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
'email' => 'existing@member.com',
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_1->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_2->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/teams/folders/{$folder->id}", [
|
||||
'members' => [
|
||||
[
|
||||
'id' => $member_1->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'id' => $member_2->id,
|
||||
'permission' => 'can-view',
|
||||
],
|
||||
],
|
||||
'invitations' => [
|
||||
[
|
||||
'id' => null,
|
||||
'email' => 'existing@member.com',
|
||||
'permission' => 'can-view',
|
||||
],
|
||||
],
|
||||
])
|
||||
->assertCreated();
|
||||
|
||||
$this
|
||||
->assertDatabaseCount('team_folder_members', 2)
|
||||
->assertDatabaseCount('team_folder_invitations', 1)
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'email' => 'existing@member.com',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_remove_member_from_team_folder()
|
||||
{
|
||||
[$user, $member, $deletedMember] = User::factory()
|
||||
->hasSettings()
|
||||
->count(3)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
// Attach members to the team folder
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $deletedMember->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
// Update team folder members
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/teams/folders/{$folder->id}", [
|
||||
'members' => [
|
||||
[
|
||||
'id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
],
|
||||
'invitations' => [],
|
||||
])
|
||||
->assertCreated();
|
||||
|
||||
$this
|
||||
->assertDatabaseCount('team_folder_members', 1)
|
||||
->assertDatabaseMissing('team_folder_members', [
|
||||
'user_id' => $deletedMember->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_update_invited_member_permission_in_team_folder()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-view',
|
||||
'email' => 'existing@member.com',
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/teams/folders/{$folder->id}", [
|
||||
'members' => [],
|
||||
'invitations' => [
|
||||
[
|
||||
'id' => null,
|
||||
'email' => 'existing@member.com',
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
],
|
||||
])
|
||||
->assertCreated();
|
||||
|
||||
$this
|
||||
->assertDatabaseCount('team_folder_members', 0)
|
||||
->assertDatabaseCount('team_folder_invitations', 1)
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'email' => 'existing@member.com',
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
Notification::assertTimesSent(0, InvitationIntoTeamFolder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_update_member_permission_in_team_folder()
|
||||
{
|
||||
[$user, $member_1, $member_2] = User::factory()
|
||||
->hasSettings()
|
||||
->count(3)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_1->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_2->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/teams/folders/{$folder->id}", [
|
||||
'members' => [
|
||||
[
|
||||
'id' => $member_1->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'id' => $member_2->id,
|
||||
'permission' => 'can-view',
|
||||
],
|
||||
],
|
||||
'invitations' => [],
|
||||
])
|
||||
->assertCreated();
|
||||
|
||||
$this->assertDatabaseHas('team_folder_members', [
|
||||
'user_id' => $member_2->id,
|
||||
'permission' => 'can-view',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function member_try_update_permission_in_team_folder()
|
||||
{
|
||||
[$user, $member_1, $member_2] = User::factory()
|
||||
->count(3)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_1->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_2->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs(
|
||||
User::find($member_1->id)
|
||||
)
|
||||
->patchJson("/api/teams/folders/{$folder->id}", [
|
||||
'members' => [
|
||||
[
|
||||
'id' => $member_1->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'id' => $member_2->id,
|
||||
'permission' => 'can-view',
|
||||
],
|
||||
],
|
||||
'invitations' => [],
|
||||
])
|
||||
->assertForbidden();
|
||||
|
||||
$this->assertDatabaseHas('team_folder_members', [
|
||||
'user_id' => $member_2->id,
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_dissolve_team_folder()
|
||||
{
|
||||
[$user, $member_1, $member_2] = User::factory()
|
||||
->count(3)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
$folderWithin = Folder::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_1->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_2->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->deleteJson("/api/teams/folders/{$folder->id}")
|
||||
->assertNoContent();
|
||||
|
||||
$this
|
||||
->assertDatabaseCount('team_folder_members', 0)
|
||||
->assertDatabaseCount('team_folder_invitations', 0)
|
||||
->assertDatabaseHas('folders', [
|
||||
'id' => $folder->id,
|
||||
'team_folder' => 0,
|
||||
])
|
||||
->assertDatabaseHas('folders', [
|
||||
'id' => $folderWithin->id,
|
||||
'team_folder' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_leave_team_folder()
|
||||
{
|
||||
[$user, $member] = User::factory()
|
||||
->count(2)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'name' => 'Team Folder',
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
// add member to the team folder
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->deleteJson("/api/teams/folders/{$folder->id}/leave")
|
||||
->assertNoContent();
|
||||
|
||||
$this
|
||||
->assertDatabaseMissing('team_folder_members', [
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function member_try_dissolve_team_folder()
|
||||
{
|
||||
[$user, $member_1, $member_2] = User::factory()
|
||||
->count(3)
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
TeamFolderInvitation::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'status' => 'pending',
|
||||
'permission' => 'can-edit',
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_1->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $member_2->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs(
|
||||
User::find($member_1->id)
|
||||
)
|
||||
->deleteJson("/api/teams/folders/{$folder->id}")
|
||||
->assertForbidden();
|
||||
|
||||
$this
|
||||
->assertDatabaseCount('team_folder_members', 2)
|
||||
->assertDatabaseCount('team_folder_invitations', 1);
|
||||
}
|
||||
}
|
||||
@@ -1,299 +0,0 @@
|
||||
<?php
|
||||
namespace Tests\Domain\Teams;
|
||||
|
||||
use Notification;
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Domain\Teams\Notifications\InvitationIntoTeamFolder;
|
||||
|
||||
class TeamsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_find_team_parent_id_from_children()
|
||||
{
|
||||
$teamFolder = Folder::factory()
|
||||
->create([
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
$level_1 = Folder::factory()
|
||||
->create([
|
||||
'parent_id' => $teamFolder->id,
|
||||
]);
|
||||
|
||||
$level_2 = Folder::factory()
|
||||
->create([
|
||||
'parent_id' => $level_1->id,
|
||||
]);
|
||||
|
||||
$this->assertEquals($teamFolder->id, $level_2->getLatestParent()->id);
|
||||
$this->assertEquals($teamFolder->id, $teamFolder->getLatestParent()->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_create_team_folder()
|
||||
{
|
||||
User::factory()
|
||||
->create([
|
||||
'email' => 'john@internal.com',
|
||||
]);
|
||||
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->post('/api/teams/folders', [
|
||||
'name' => 'Company Project',
|
||||
'invitations' => [
|
||||
[
|
||||
'email' => 'john@internal.com',
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'email' => 'jane@external.com',
|
||||
'permission' => 'can-view',
|
||||
],
|
||||
],
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonFragment([
|
||||
'name' => 'Company Project',
|
||||
]);
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('folders', [
|
||||
'user_id' => $user->id,
|
||||
'name' => 'Company Project',
|
||||
'team_folder' => 1,
|
||||
])
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'email' => 'john@internal.com',
|
||||
])
|
||||
->assertDatabaseHas('team_folder_invitations', [
|
||||
'email' => 'jane@external.com',
|
||||
]);
|
||||
|
||||
Notification::assertTimesSent(2, InvitationIntoTeamFolder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_mark_newly_created_folder_as_team_folder()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$teamFolder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson('/api/create-folder', [
|
||||
'name' => 'Inner Folder',
|
||||
'parent_id' => $teamFolder->id,
|
||||
])
|
||||
->assertStatus(201)
|
||||
->assertJsonFragment([
|
||||
'isTeamFolder' => true,
|
||||
'id' => $user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_convert_folder_into_team_folder()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$folderWithin = Folder::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->post("/api/teams/folders/{$folder->id}/convert", [
|
||||
'invitations' => [
|
||||
[
|
||||
'email' => 'john@internal.com',
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'email' => 'jane@external.com',
|
||||
'permission' => 'can-view',
|
||||
],
|
||||
],
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonFragment([
|
||||
'name' => $folder->name,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('folders', [
|
||||
'id' => $folderWithin->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
Notification::assertTimesSent(2, InvitationIntoTeamFolder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_all_team_folders()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->getJson('/api/teams/folders/undefined')
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'id' => $folder->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_content_of_team_folder()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
$file = File::factory()
|
||||
->create([
|
||||
'parent_id' => $folder->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->getJson("/api/teams/folders/{$folder->id}")
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'id' => $file->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_team_folders_shared_with_another_user()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$member = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$folders = Folder::factory()
|
||||
->count(2)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
DB::table('team_folder_members')
|
||||
->insert([
|
||||
[
|
||||
'parent_id' => $folders[0]->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
[
|
||||
'parent_id' => $folders[1]->id,
|
||||
'user_id' => $member->id,
|
||||
'permission' => 'can-edit',
|
||||
],
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->getJson('/api/teams/shared-with-me/undefined')
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'id' => $folders[0]->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function team_member_upload_new_file()
|
||||
{
|
||||
$file = UploadedFile::fake()
|
||||
->create('fake-file.pdf', 12000000, 'application/pdf');
|
||||
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$member = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'team_folder' => 1,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($member)
|
||||
->postJson('/api/upload', [
|
||||
'name' => $file->name,
|
||||
'extension' => 'pdf',
|
||||
'file' => $file,
|
||||
'parent_id' => $folder->id,
|
||||
'path' => "/$file->name",
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('files', [
|
||||
'user_id' => $user->id,
|
||||
'creator_id' => $member->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
<?php
|
||||
namespace Tests\Domain\UploadRequest;
|
||||
|
||||
use Storage;
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Domain\Files\Models\File;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Domain\UploadRequest\Models\UploadRequest;
|
||||
|
||||
class UploadRequestAccessTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_file_from_upload_request_folder()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$file = UploadedFile::fake()
|
||||
->create(Str::random() . '-fake-file.pdf', 1200, 'application/pdf');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $file, $file->name);
|
||||
|
||||
File::factory()
|
||||
->create([
|
||||
'parent_id' => $uploadRequest->id,
|
||||
'basename' => $file->name,
|
||||
'user_id' => $user->id,
|
||||
'name' => $file->name,
|
||||
]);
|
||||
|
||||
$this
|
||||
->get("/file/$file->name/upload-request/$uploadRequest->id")
|
||||
->assertDownload($file->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_thumbnail_from_upload_request_folder()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$thumbnail = UploadedFile::fake()
|
||||
->image('fake-thumbnail.jpg');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $thumbnail, $thumbnail->name);
|
||||
|
||||
File::factory()
|
||||
->create([
|
||||
'parent_id' => $uploadRequest->id,
|
||||
'basename' => 'fake-thumbnail.jpg',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->get("/thumbnail/xs-$thumbnail->name/upload-request/$uploadRequest->id")
|
||||
->assertDownload("xs-$thumbnail->name");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_try_get_file_from_expired_upload_request_folder()
|
||||
{
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'expired',
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$this
|
||||
->get("/file/fake-file.pdf/upload-request/$uploadRequest->id")
|
||||
->assertStatus(410);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_try_get_thumbnail_from_expired_upload_request_folder()
|
||||
{
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'filled',
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$this
|
||||
->get("/thumbnail/xs-fake-thumbnail.jpeg/upload-request/$uploadRequest->id")
|
||||
->assertStatus(410);
|
||||
}
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
<?php
|
||||
namespace Tests\Domain\UploadRequest;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Domain\UploadRequest\Models\UploadRequest;
|
||||
|
||||
class UploadRequestBrowsingTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_navigator_tree_for_upload_request_folder()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
Folder::factory()
|
||||
->create([
|
||||
'id' => $uploadRequest->id,
|
||||
'name' => 'Upload request',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$folder_level_1 = Folder::factory()
|
||||
->create([
|
||||
'parent_id' => $uploadRequest->id,
|
||||
'name' => 'level 1',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$folder_level_2 = Folder::factory()
|
||||
->create([
|
||||
'name' => 'level 2',
|
||||
'parent_id' => $folder_level_1->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->getJson("/api/upload-request/$uploadRequest->id/navigation")
|
||||
->assertStatus(200)
|
||||
->assertExactJson([
|
||||
[
|
||||
'location' => 'upload-request',
|
||||
'name' => 'Upload Request',
|
||||
'folders' => [
|
||||
[
|
||||
'id' => $folder_level_1->id,
|
||||
'parent_id' => $uploadRequest->id,
|
||||
'name' => 'level 1',
|
||||
'items' => 1,
|
||||
'trashed_items' => 1,
|
||||
'folders' => [
|
||||
[
|
||||
'id' => $folder_level_2->id,
|
||||
'parent_id' => $folder_level_1->id,
|
||||
'name' => 'level 2',
|
||||
'items' => 0,
|
||||
'trashed_items' => 0,
|
||||
'folders' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'isMovable' => true,
|
||||
'isOpen' => true,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_folder_content_for_upload_request_folder()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$root = Folder::factory()
|
||||
->create([
|
||||
'id' => $uploadRequest->id,
|
||||
'name' => 'root',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'parent_id' => $root->id,
|
||||
'author' => 'user',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$file = File::factory()
|
||||
->create([
|
||||
'parent_id' => $root->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->getJson("/api/upload-request/$uploadRequest->id/browse/$root->id")
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'id' => $root->id,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'id' => $file->id,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'id' => $folder->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_folder_content_from_not_existed_upload_request_folder()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$root = Folder::factory()
|
||||
->create([
|
||||
'id' => $uploadRequest->id,
|
||||
'name' => 'root',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'parent_id' => $root->id,
|
||||
'author' => 'user',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$file = File::factory()
|
||||
->create([
|
||||
'parent_id' => $root->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->getJson("/api/upload-request/$uploadRequest->id/browse/$root->id")
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'id' => $root->id,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'id' => $file->id,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'id' => $folder->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,335 +0,0 @@
|
||||
<?php
|
||||
namespace Tests\Domain\UploadRequest;
|
||||
|
||||
use Storage;
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Files\Models\File;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Domain\UploadRequest\Models\UploadRequest;
|
||||
|
||||
class UploadRequestEditingTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_rename_folder_item()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'parent_id' => $uploadRequest->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/upload-request/$uploadRequest->id/rename/$folder->id", [
|
||||
'name' => 'Renamed Folder',
|
||||
'type' => 'folder',
|
||||
])
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'name' => 'Renamed Folder',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('folders', [
|
||||
'name' => 'Renamed Folder',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_rename_file_item()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$file = File::factory()
|
||||
->create([
|
||||
'parent_id' => $uploadRequest->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->patchJson("/api/upload-request/$uploadRequest->id/rename/$file->id", [
|
||||
'name' => 'Renamed File',
|
||||
'type' => 'file',
|
||||
])
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'name' => 'Renamed File',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('files', [
|
||||
'name' => 'Renamed File',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_create_new_folder_in_upload_request()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson("/api/upload-request/$uploadRequest->id/create-folder", [
|
||||
'name' => 'New Folder',
|
||||
'parent_id' => $uploadRequest->id,
|
||||
])
|
||||
->assertStatus(201)
|
||||
->assertJsonFragment([
|
||||
'name' => 'New Folder',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('folders', [
|
||||
'name' => 'New Folder',
|
||||
'parent_id' => $uploadRequest->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_delete_image_with_their_thumbnails()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$image = File::factory()
|
||||
->create([
|
||||
'mimetype' => 'jpeg',
|
||||
'type' => 'image',
|
||||
'basename' => 'fake-image.jpeg',
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $uploadRequest->id,
|
||||
]);
|
||||
|
||||
// Mock files
|
||||
$thumbnail_sizes = collect([
|
||||
config('vuefilemanager.image_sizes.later'),
|
||||
config('vuefilemanager.image_sizes.immediately'),
|
||||
])->collapse();
|
||||
|
||||
$fakeFile = UploadedFile::fake()
|
||||
->create('fake-image.jpeg', 2000, 'image/jpeg');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $fakeFile, $fakeFile->name);
|
||||
|
||||
// Create fake image thumbnails
|
||||
$thumbnail_sizes
|
||||
->each(function ($item) use ($user) {
|
||||
$fakeFile = UploadedFile::fake()
|
||||
->create("{$item['name']}-fake-image.jpeg", 2000, 'image/jpeg');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $fakeFile, $fakeFile->name);
|
||||
});
|
||||
|
||||
$this
|
||||
->postJson("/api/upload-request/$uploadRequest->id/remove", [
|
||||
'items' => [
|
||||
[
|
||||
'id' => $image->id,
|
||||
'type' => 'file',
|
||||
'force_delete' => true,
|
||||
],
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
// Assert primary file was deleted
|
||||
Storage::assertMissing("files/$user->id/fake-image.jpeg");
|
||||
|
||||
// Assert thumbnail was deleted
|
||||
getThumbnailFileList('fake-image.jpeg')
|
||||
->each(fn ($thumbnail) => Storage::assertMissing("files/$user->id/$thumbnail"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_delete_file()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$file = File::factory()
|
||||
->create([
|
||||
'type' => 'file',
|
||||
'basename' => 'fake-file.pdf',
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $uploadRequest->id,
|
||||
]);
|
||||
|
||||
$fakeFile = UploadedFile::fake()
|
||||
->create('fake-file.pdf', 1200, 'application/pdf');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $fakeFile, $fakeFile->name);
|
||||
|
||||
$this
|
||||
->postJson("/api/upload-request/$uploadRequest->id/remove", [
|
||||
'items' => [
|
||||
[
|
||||
'id' => $file->id,
|
||||
'type' => 'file',
|
||||
'force_delete' => true,
|
||||
],
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
// Assert primary file was deleted
|
||||
Storage::assertMissing("files/$user->id/fake-file.pdf");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_delete_folder_with_file_within()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $uploadRequest->id,
|
||||
]);
|
||||
|
||||
$folderWithin = Folder::factory()
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $folder->id,
|
||||
]);
|
||||
|
||||
$file = File::factory()
|
||||
->create([
|
||||
'type' => 'file',
|
||||
'basename' => 'fake-file.pdf',
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $folder->id,
|
||||
]);
|
||||
|
||||
$fakeFile = UploadedFile::fake()
|
||||
->create('fake-file.pdf', 1200, 'application/pdf');
|
||||
|
||||
Storage::putFileAs("files/$user->id", $fakeFile, $fakeFile->name);
|
||||
|
||||
$this
|
||||
->postJson("/api/upload-request/$uploadRequest->id/remove", [
|
||||
'items' => [
|
||||
[
|
||||
'id' => $folder->id,
|
||||
'type' => 'folder',
|
||||
'force_delete' => true,
|
||||
],
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
$this
|
||||
->assertDatabaseMissing('folders', [
|
||||
'id' => $folder->id,
|
||||
])
|
||||
->assertDatabaseMissing('folders', [
|
||||
'id' => $folderWithin->id,
|
||||
])
|
||||
->assertDatabaseMissing('files', [
|
||||
'id' => $file->id,
|
||||
]);
|
||||
|
||||
// Assert primary file was deleted
|
||||
Storage::assertMissing("files/$user->id/fake-file.pdf");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_move_file_to_another_folder_in_upload_request()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$folder = Folder::factory()
|
||||
->create([
|
||||
'id' => $uploadRequest->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$file = File::factory()
|
||||
->create([
|
||||
'parent_id' => $uploadRequest->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->postJson("/api/upload-request/$uploadRequest->id/move", [
|
||||
'to_id' => $folder->id,
|
||||
'items' => [
|
||||
[
|
||||
'type' => 'file',
|
||||
'id' => $file->id,
|
||||
],
|
||||
],
|
||||
])->assertStatus(204);
|
||||
|
||||
$this->assertDatabaseHas('files', [
|
||||
'id' => $file->id,
|
||||
'parent_id' => $folder->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,333 +0,0 @@
|
||||
<?php
|
||||
namespace Tests\Domain\UploadRequest;
|
||||
|
||||
use Storage;
|
||||
use Notification;
|
||||
use Tests\TestCase;
|
||||
use App\Users\Models\User;
|
||||
use Domain\Files\Models\File;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Domain\UploadRequest\Models\UploadRequest;
|
||||
use Support\Scheduler\Actions\ExpireUnfilledUploadRequestAction;
|
||||
use Domain\UploadRequest\Notifications\UploadRequestNotification;
|
||||
use Domain\UploadRequest\Notifications\UploadRequestFulfilledNotification;
|
||||
|
||||
class UploadRequestTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_test_upload_request_factory()
|
||||
{
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create();
|
||||
|
||||
$this->assertModelExists($uploadRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_upload_request_with_email()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson('/api/upload-request', [
|
||||
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
'notes' => 'Please send me your files...',
|
||||
])
|
||||
->assertCreated();
|
||||
|
||||
$this->assertDatabasehas('upload_requests', [
|
||||
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
|
||||
'email' => 'howdy@hi5ve.digital',
|
||||
'notes' => 'Please send me your files...',
|
||||
]);
|
||||
|
||||
Notification::assertTimesSent(1, UploadRequestNotification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_upload_request_without_email()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson('/api/upload-request', [
|
||||
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
|
||||
'notes' => 'Please send me your files...',
|
||||
])
|
||||
->assertCreated();
|
||||
|
||||
$this->assertDatabasehas('upload_requests', [
|
||||
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
|
||||
'notes' => 'Please send me your files...',
|
||||
'email' => null,
|
||||
]);
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_create_upload_request_with_name()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$this
|
||||
->actingAs($user)
|
||||
->postJson('/api/upload-request', [
|
||||
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
|
||||
'notes' => 'Please send me your files...',
|
||||
'name' => 'My name',
|
||||
])
|
||||
->assertCreated();
|
||||
|
||||
$this->assertDatabasehas('upload_requests', [
|
||||
'folder_id' => '00cacdb9-1d09-4a32-8ad7-c0d45d66b758',
|
||||
'notes' => 'Please send me your files...',
|
||||
'email' => null,
|
||||
'name' => 'My name',
|
||||
]);
|
||||
|
||||
Notification::assertNothingSent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_upload_request_detail()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this->getJson("/api/upload-request/$uploadRequest->id")
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'id' => $uploadRequest->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_upload_file_and_create_upload_request_folder_without_custom_folder_name()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
'created_at' => now(),
|
||||
'name' => null,
|
||||
]);
|
||||
|
||||
$file = UploadedFile::fake()
|
||||
->create('fake-file.pdf', 12000000, 'application/pdf');
|
||||
|
||||
$this
|
||||
->postJson("/api/upload-request/$uploadRequest->id/upload", [
|
||||
'name' => $file->name,
|
||||
'extension' => 'pdf',
|
||||
'file' => $file,
|
||||
'parent_id' => null,
|
||||
'path' => "/$file->name",
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('upload_requests', [
|
||||
'status' => 'filling',
|
||||
])
|
||||
->assertDatabaseHas('folders', [
|
||||
'id' => $uploadRequest->id,
|
||||
'name' => 'Upload Request from 01. Jan. 2021',
|
||||
])->assertDatabaseHas('files', [
|
||||
'parent_id' => $uploadRequest->id,
|
||||
]);
|
||||
|
||||
$file = File::first();
|
||||
|
||||
Storage::assertExists("files/$user->id/$file->basename");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_upload_file_and_create_upload_request_folder_with_custom_folder_name()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
'created_at' => now(),
|
||||
'name' => 'My Documents',
|
||||
]);
|
||||
|
||||
$file = UploadedFile::fake()
|
||||
->create('fake-file.pdf', 12000000, 'application/pdf');
|
||||
|
||||
$this
|
||||
->postJson("/api/upload-request/$uploadRequest->id/upload", [
|
||||
'name' => $file->name,
|
||||
'extension' => 'pdf',
|
||||
'file' => $file,
|
||||
'parent_id' => null,
|
||||
'path' => "/$file->name",
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(201);
|
||||
|
||||
$this
|
||||
->assertDatabaseHas('upload_requests', [
|
||||
'status' => 'filling',
|
||||
])
|
||||
->assertDatabaseHas('folders', [
|
||||
'id' => $uploadRequest->id,
|
||||
'name' => 'My Documents',
|
||||
])->assertDatabaseHas('files', [
|
||||
'parent_id' => $uploadRequest->id,
|
||||
]);
|
||||
|
||||
$file = File::first();
|
||||
|
||||
Storage::assertExists("files/$user->id/$file->basename");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_try_upload_file_into_non_active_upload_request()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'expired',
|
||||
'user_id' => $user->id,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$file = UploadedFile::fake()
|
||||
->create('fake-file.pdf', 12000000, 'application/pdf');
|
||||
|
||||
$this
|
||||
->postJson("/api/upload-request/$uploadRequest->id/upload", [
|
||||
'name' => $file->name,
|
||||
'file' => $file,
|
||||
'parent_id' => null,
|
||||
'path' => "/$file->name",
|
||||
'is_last' => 'true',
|
||||
])->assertStatus(410);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_mark_upload_request_as_filled()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this
|
||||
->deleteJson("/api/upload-request/$uploadRequest->id")
|
||||
->assertStatus(201)
|
||||
->assertJsonFragment([
|
||||
'id' => $uploadRequest->id,
|
||||
'status' => 'filled',
|
||||
]);
|
||||
|
||||
Notification::assertSentTo($user, UploadRequestFulfilledNotification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_mark_upload_request_as_expired_after_72_hours()
|
||||
{
|
||||
UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'created_at' => now()->subHours(72),
|
||||
]);
|
||||
|
||||
resolve(ExpireUnfilledUploadRequestAction::class)();
|
||||
|
||||
$this->assertDatabaseHas('upload_requests', [
|
||||
'status' => 'expired',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_mark_upload_request_as_filled_3_hours_after_last_upload()
|
||||
{
|
||||
$user = User::factory()
|
||||
->hasSettings()
|
||||
->create();
|
||||
|
||||
$uploadRequest = UploadRequest::factory()
|
||||
->create([
|
||||
'status' => 'active',
|
||||
'user_id' => $user->id,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$file = UploadedFile::fake()
|
||||
->create('fake-file.pdf', 12000000, 'application/pdf');
|
||||
|
||||
$this
|
||||
->postJson("/api/upload-request/$uploadRequest->id/upload", [
|
||||
'name' => $file->name,
|
||||
'extension' => 'pdf',
|
||||
'file' => $file,
|
||||
'parent_id' => null,
|
||||
'path' => "/$file->name",
|
||||
'is_last' => 'true',
|
||||
])->assertCreated();
|
||||
|
||||
$this->travel(3)->hours();
|
||||
|
||||
resolve(ExpireUnfilledUploadRequestAction::class)();
|
||||
|
||||
$this->assertDatabaseHas('upload_requests', [
|
||||
'status' => 'filled',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user