mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +00:00
added it_get_recent_files test
This commit is contained in:
@@ -93,15 +93,13 @@ class BrowseController extends Controller
|
||||
*/
|
||||
public function latest()
|
||||
{
|
||||
|
||||
// Get User
|
||||
$user = User::with(['latest_uploads' => function ($query) {
|
||||
$query->sortable(['created_at' => 'desc']);
|
||||
}])
|
||||
->where('id', Auth::id())
|
||||
->first();
|
||||
|
||||
return $user->latest_uploads->makeHidden(['user_id', 'basename']);
|
||||
return $user->latest_uploads;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -254,7 +254,7 @@ class User extends Authenticatable
|
||||
*/
|
||||
public function latest_uploads()
|
||||
{
|
||||
return $this->hasMany(File::class)->with(['parent'])->take(40);
|
||||
return $this->hasMany(File::class)->with(['parent:id,name'])->take(40);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Feature;
|
||||
use App\Models\File;
|
||||
use App\Models\Folder;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
@@ -200,6 +201,102 @@ class BrowseTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_recent_files()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$root = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'name' => 'root',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$file_1 = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $root->id,
|
||||
'name' => 'Document 1',
|
||||
'basename' => 'document-1.pdf',
|
||||
"mimetype" => "application/pdf",
|
||||
"user_scope" => "master",
|
||||
"type" => "file",
|
||||
'user_id' => $user->id,
|
||||
'created_at' => Carbon::now(),
|
||||
]);
|
||||
|
||||
$this->travel(5)->minutes();
|
||||
|
||||
$file_2 = File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $root->id,
|
||||
'name' => 'Document 2',
|
||||
'basename' => 'document-2.pdf',
|
||||
"mimetype" => "application/pdf",
|
||||
"user_scope" => "master",
|
||||
"type" => "file",
|
||||
'user_id' => $user->id,
|
||||
'created_at' => Carbon::now(),
|
||||
]);
|
||||
|
||||
$this->getJson("/api/browse/latest")
|
||||
->assertStatus(200)
|
||||
->assertJson([
|
||||
[
|
||||
"id" => $file_2->id,
|
||||
"user_id" => $user->id,
|
||||
"folder_id" => $root->id,
|
||||
"thumbnail" => null,
|
||||
"name" => "Document 2",
|
||||
"basename" => "document-2.pdf",
|
||||
"mimetype" => "application/pdf",
|
||||
"filesize" => $file_2->filesize,
|
||||
"type" => "file",
|
||||
"metadata" => null,
|
||||
"user_scope" => "master",
|
||||
"deleted_at" => null,
|
||||
"created_at" => $file_2->created_at,
|
||||
"updated_at" => $file_2->updated_at->toJson(),
|
||||
"file_url" => "http://localhost/file/document-2.pdf",
|
||||
"parent" => [
|
||||
"id" => $root->id,
|
||||
"name" => "root",
|
||||
"items" => 2,
|
||||
"trashed_items" => 2,
|
||||
"type" => "folder",
|
||||
],
|
||||
],
|
||||
[
|
||||
"id" => $file_1->id,
|
||||
"user_id" => $user->id,
|
||||
"folder_id" => $root->id,
|
||||
"thumbnail" => null,
|
||||
"name" => "Document 1",
|
||||
"basename" => "document-1.pdf",
|
||||
"mimetype" => "application/pdf",
|
||||
"filesize" => $file_1->filesize,
|
||||
"type" => "file",
|
||||
"metadata" => null,
|
||||
"user_scope" => "master",
|
||||
"deleted_at" => null,
|
||||
"created_at" => $file_1->created_at,
|
||||
"updated_at" => $file_1->updated_at->toJson(),
|
||||
"file_url" => "http://localhost/file/document-1.pdf",
|
||||
"parent" => [
|
||||
"id" => $root->id,
|
||||
"name" => "root",
|
||||
"items" => 2,
|
||||
"trashed_items" => 2,
|
||||
"type" => "folder",
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function it_get_searched_file()
|
||||
{
|
||||
|
||||
@@ -210,11 +307,6 @@ class BrowseTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function it_get_recent_files()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function it_get_trash()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user