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.

83 lines
2.9 KiB

3 months ago
<?php
namespace Tests\Feature;
use App\Models\AdminUser;
use App\Models\Application;
use App\Models\Competition;
use App\Models\User;
use App\Services\AdminApplicationExportService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class AdminApplicationExportTest extends TestCase
{
use RefreshDatabase;
public function test_export_meta_supports_three_modes(): void
{
$admin = AdminUser::query()->create([
'username' => 'admin_export',
'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' => '13800138002'])->id,
'competition_id' => $competition->id,
'status' => 'submitted',
'project_name' => '项目A',
]);
Sanctum::actingAs($admin);
$this->getJson("/api/v1/admin/competitions/{$competition->id}/applications/export/meta?mode=xlsx")
->assertOk()
->assertJsonPath('mode', AdminApplicationExportService::MODE_XLSX)
->assertJsonPath('includes_attachments', false)
->assertJsonPath('part_count', 1);
$this->getJson("/api/v1/admin/competitions/{$competition->id}/applications/export/meta?mode=all")
->assertOk()
->assertJsonPath('mode', AdminApplicationExportService::MODE_ALL)
->assertJsonPath('includes_attachments', true);
$this->getJson("/api/v1/admin/competitions/{$competition->id}/applications/export/meta?mode=selected&application_ids[]={$application->id}")
->assertOk()
->assertJsonPath('mode', AdminApplicationExportService::MODE_SELECTED)
->assertJsonPath('includes_attachments', true);
}
public function test_selected_export_requires_application_ids(): void
{
$admin = AdminUser::query()->create([
'username' => 'admin_export2',
'password_hash' => 'unused',
'name' => '管理员2',
'status' => 'active',
]);
$competition = Competition::query()->create([
'slug' => 'xxf2',
'name' => '测试赛2',
'published' => true,
]);
Application::query()->create([
'user_id' => User::query()->create(['mobile' => '13800138004'])->id,
'competition_id' => $competition->id,
'status' => 'submitted',
]);
Sanctum::actingAs($admin);
$this->getJson("/api/v1/admin/competitions/{$competition->id}/applications/export/meta?mode=selected")
->assertStatus(422)
->assertJsonValidationErrors(['application_ids']);
}
}