From 723e7c6676ead5f7f2f3688fbbc645df13976a35 Mon Sep 17 00:00:00 2001 From: weizong song Date: Mon, 8 Jun 2026 14:02:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8D=89=E7=A8=BF=E4=BF=9D=E5=AD=98=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/ApplicationController.php | 12 +--------- .../Feature/ChannelSignupIntegrationTest.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Api/ApplicationController.php b/app/Http/Controllers/Api/ApplicationController.php index 0184f40..5ec436c 100644 --- a/app/Http/Controllers/Api/ApplicationController.php +++ b/app/Http/Controllers/Api/ApplicationController.php @@ -212,16 +212,6 @@ class ApplicationController extends Controller $countries = config('contest.location_countries', []); $companyRules = ['nullable', 'string', 'max:255']; - if ($this->signupSchemaHasKey($competition, 'entry_group')) { - $reqVals = $this->companyNameRequiredWhenEntryGroupValues($competition); - if (count($reqVals) > 0) { - $companyRules[] = Rule::requiredIf(function () use ($request, $reqVals): bool { - $eg = (string) $request->input('entry_group', ''); - - return in_array($eg, $reqVals, true); - }); - } - } $trackRules = count($trackCodes) ? ['nullable', 'string', Rule::in($trackCodes)] @@ -243,7 +233,7 @@ class ApplicationController extends Controller 'intro' => ['nullable', 'string', 'max:5000'], ]; if ($this->signupSchemaHasKey($competition, 'entry_group')) { - $rules['entry_group'] = ['required', 'string', Rule::in($this->allowedEntryGroupValues($competition))]; + $rules['entry_group'] = ['nullable', 'string', Rule::in($this->allowedEntryGroupValues($competition))]; } if ($this->signupSchemaRequiresCommitment($competition)) { $rules['commitment_accepted'] = ['sometimes', 'boolean']; diff --git a/tests/Feature/ChannelSignupIntegrationTest.php b/tests/Feature/ChannelSignupIntegrationTest.php index 1e21d0c..b909837 100644 --- a/tests/Feature/ChannelSignupIntegrationTest.php +++ b/tests/Feature/ChannelSignupIntegrationTest.php @@ -134,6 +134,30 @@ class ChannelSignupIntegrationTest extends TestCase ])->assertUnprocessable(); } + public function test_draft_save_allows_required_fields_missing_but_validates_filled_formats(): void + { + $this->competition('main-event'); + Sanctum::actingAs(User::query()->create([ + 'mobile' => '13800138000', + ])); + + $this->putJson('/api/applications/current?competition_slug=main-event', [ + 'player_name' => '张三', + 'contact_email' => 'bad-email', + ])->assertUnprocessable() + ->assertJsonValidationErrors(['contact_email']); + + $this->putJson('/api/applications/current?competition_slug=main-event', [ + 'player_name' => '张三', + 'contact_email' => 'draft@example.com', + ])->assertOk() + ->assertJsonPath('status', 'draft') + ->assertJsonPath('player_name', '张三') + ->assertJsonPath('contact_email', 'draft@example.com') + ->assertJsonPath('entry_group', null) + ->assertJsonPath('company_name', null); + } + public function test_channel_entry_success_errors_context_and_safe_logs(): void { $competition = $this->competition('main-event');