You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.1 KiB
96 lines
3.1 KiB
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\AdminUser;
|
|
use App\Models\Application;
|
|
use App\Models\ApplicationFile;
|
|
use App\Models\Competition;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class AdminApplicationFileDownloadTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_admin_download_returns_clear_message_when_file_missing(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
Sanctum::actingAs(AdminUser::query()->create([
|
|
'username' => 'admin_dl',
|
|
'password_hash' => 'unused',
|
|
'name' => '管理员',
|
|
'status' => 'active',
|
|
]));
|
|
|
|
$competition = Competition::query()->create([
|
|
'slug' => 'xxf',
|
|
'name' => '测试赛',
|
|
'published' => true,
|
|
]);
|
|
$application = Application::query()->create([
|
|
'user_id' => User::query()->create(['mobile' => '13800138055'])->id,
|
|
'competition_id' => $competition->id,
|
|
'status' => 'submitted',
|
|
'project_name' => '测试项目',
|
|
]);
|
|
$file = ApplicationFile::query()->create([
|
|
'application_id' => $application->id,
|
|
'kind' => 'plan',
|
|
'disk' => 'public',
|
|
'path' => '0',
|
|
'original_name' => '商业计划书.pdf',
|
|
'size' => 8,
|
|
'mime' => 'application/pdf',
|
|
]);
|
|
|
|
$this->getJson(
|
|
"/api/v1/admin/competitions/{$competition->id}/applications/{$application->id}/files/{$file->id}/download"
|
|
)
|
|
->assertNotFound()
|
|
->assertJsonPath('message', '附件文件不存在或已丢失');
|
|
}
|
|
|
|
public function test_admin_download_streams_existing_file(): void
|
|
{
|
|
Storage::fake('public');
|
|
Storage::disk('public')->put('applications/1/plan.pdf', 'pdf-bytes');
|
|
|
|
Sanctum::actingAs(AdminUser::query()->create([
|
|
'username' => 'admin_dl_ok',
|
|
'password_hash' => 'unused',
|
|
'name' => '管理员',
|
|
'status' => 'active',
|
|
]));
|
|
|
|
$competition = Competition::query()->create([
|
|
'slug' => 'xxf-ok',
|
|
'name' => '测试赛',
|
|
'published' => true,
|
|
]);
|
|
$application = Application::query()->create([
|
|
'user_id' => User::query()->create(['mobile' => '13800138056'])->id,
|
|
'competition_id' => $competition->id,
|
|
'status' => 'submitted',
|
|
'project_name' => '测试项目',
|
|
]);
|
|
$file = ApplicationFile::query()->create([
|
|
'application_id' => $application->id,
|
|
'kind' => 'plan',
|
|
'disk' => 'public',
|
|
'path' => 'applications/1/plan.pdf',
|
|
'original_name' => '商业计划书.pdf',
|
|
'size' => 9,
|
|
'mime' => 'application/pdf',
|
|
]);
|
|
|
|
$this->get(
|
|
"/api/v1/admin/competitions/{$competition->id}/applications/{$application->id}/files/{$file->id}/download"
|
|
)->assertOk();
|
|
}
|
|
}
|