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.

81 lines
2.8 KiB

4 weeks ago
<?php
namespace Tests\Feature;
use App\Models\AdminUser;
use App\Models\Application;
use App\Models\Competition;
use App\Models\CompetitionTrack;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class ManageReportTest extends TestCase
{
use RefreshDatabase;
public function test_report_lists_all_tracks_zones_degrees_and_countries_in_chinese(): void
{
Sanctum::actingAs(AdminUser::query()->create([
'username' => 'admin_report',
'password_hash' => 'unused',
'name' => '管理员',
'status' => 'active',
]));
$competition = Competition::query()->create([
'slug' => 'hsxt-report',
'name' => '看板测试赛',
'published' => true,
]);
foreach (['材料与芯片', '器件与模块', '场景与应用', '设备与服务'] as $i => $title) {
CompetitionTrack::query()->create([
'competition_id' => $competition->id,
'track_code' => 't'.($i + 1),
'title' => $title,
'sort' => $i + 1,
'is_enabled' => true,
]);
}
Application::query()->create([
'user_id' => User::query()->create(['mobile' => '13800138801'])->id,
'competition_id' => $competition->id,
'status' => 'submitted',
'project_name' => '已报名项目',
'track' => 't1',
'degree' => 'bachelor',
'location_country' => 'cn',
'event_location' => 'shanghai',
]);
$response = $this->getJson("/api/v1/admin/competitions/{$competition->id}/manage/report")
->assertOk();
$this->assertSame(
['材料与芯片', '器件与模块', '场景与应用', '设备与服务'],
collect($response->json('track_counts'))->pluck('label')->all()
);
$this->assertSame(1, $response->json('track_counts.0.count'));
$this->assertSame(0, $response->json('track_counts.1.count'));
$this->assertSame(
['大专', '本科', '硕士', '博士', '其他'],
collect($response->json('degree_counts'))->pluck('label')->all()
);
$this->assertSame(
['中国', '海外'],
collect($response->json('country_counts'))->pluck('label')->all()
);
$this->assertSame(
['上海赛区', '苏州赛区', '深圳赛区'],
collect($response->json('event_location_counts'))->pluck('label')->all()
);
$this->assertSame(
['材料与芯片', '器件与模块', '场景与应用', '设备与服务'],
collect($response->json('track_score_rank'))->pluck('track')->all()
);
}
}