mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-06 02:33:48 +00:00
added it_get_shared_items test
This commit is contained in:
@@ -43,7 +43,7 @@ class BrowseController extends Controller
|
||||
->with(['parent'])
|
||||
->where('user_id', $user_id)
|
||||
->whereNull('folder_id')
|
||||
->whereNotIn('folder_id', array_values(array_unique(recursiveFind($folders_trashed->toArray(), 'unique_id'))))
|
||||
->orWhereNotIn('folder_id', array_values(array_unique(recursiveFind($folders_trashed->toArray(), 'id'))))
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
@@ -73,13 +73,13 @@ class BrowseController extends Controller
|
||||
// Get folders and files
|
||||
$folders = Folder::with(['parent', 'shared:token,id,item_id,permission,is_protected,expire_in'])
|
||||
->where('user_id', $user_id)
|
||||
->whereIn('unique_id', $folder_ids)
|
||||
->whereIn('id', $folder_ids)
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
$files = File::with(['parent', 'shared:token,id,item_id,permission,is_protected,expire_in'])
|
||||
->where('user_id', $user_id)
|
||||
->whereIn('unique_id', $file_ids)
|
||||
->whereIn('id', $file_ids)
|
||||
->sortable()
|
||||
->get();
|
||||
|
||||
|
||||
37
database/factories/ShareFactory.php
Normal file
37
database/factories/ShareFactory.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Share;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ShareFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Share::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'id' => $this->faker->uuid,
|
||||
'user_id' => $this->faker->uuid,
|
||||
'item_id' => $this->faker->uuid,
|
||||
'token' => Str::random(16),
|
||||
'type' => $this->faker->randomElement(['file', 'folder']),
|
||||
'permission' => $this->faker->randomElement(['visitor', 'editor']),
|
||||
'is_protected' => $this->faker->boolean(20),
|
||||
'password' => \Hash::make('secret'),
|
||||
'expire_in' => $this->faker->randomElement([1, 6, 12, 24]),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ Route::group(['middleware' => ['auth:sanctum']], function () {
|
||||
Route::get('/participants', [BrowseController::class, 'participant_uploads']);
|
||||
Route::get('/navigation', [BrowseController::class, 'navigation_tree']);
|
||||
Route::get('/folders/{id}', [BrowseController::class, 'folder']);
|
||||
Route::get('/sharing', [BrowseController::class, 'shared']);
|
||||
Route::get('/shared', [BrowseController::class, 'shared']);
|
||||
Route::get('/latest', [BrowseController::class, 'latest']);
|
||||
Route::get('/search', [BrowseController::class, 'search']);
|
||||
Route::get('/trash', [BrowseController::class, 'trash']);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Models\Folder;
|
||||
use App\Models\Share;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
@@ -355,11 +356,6 @@ class BrowseTest extends TestCase
|
||||
File::factory(File::class)
|
||||
->create([
|
||||
'folder_id' => $folder->id,
|
||||
'name' => 'Document 1',
|
||||
'basename' => 'document-1.pdf',
|
||||
"mimetype" => "application/pdf",
|
||||
"user_scope" => "master",
|
||||
"type" => "file",
|
||||
'user_id' => $user->id,
|
||||
'deleted_at' => Carbon::now(),
|
||||
]);
|
||||
@@ -404,6 +400,46 @@ class BrowseTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function it_get_shared_items()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$folder = Folder::factory(Folder::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$file = File::factory(File::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
collect([$folder, $file])
|
||||
->each(function ($item) use ($user) {
|
||||
Share::factory(Share::class)
|
||||
->create([
|
||||
"type" => $item->type === 'folder' ? 'folder' : 'file',
|
||||
"item_id" => $item->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
});
|
||||
|
||||
collect([$folder, $file])
|
||||
->each(function ($item) use ($user) {
|
||||
$this->getJson("/api/browse/shared")
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment([
|
||||
'id' => $item->id
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function it_get_searched_file()
|
||||
{
|
||||
@@ -414,9 +450,4 @@ class BrowseTest extends TestCase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function it_get_shared_files()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user