create(); Sanctum::actingAs($user); $response = $this->putJson(self::UPDATE_URL, ['currency' => 'USD']); $response->assertOk(); $this->assertSame( 'USD', app(EcommerceUserProfileRepositoryInterface::class)->getPreferredCurrency($user->id) ); } public function test_unregistered_currency_is_rejected_422(): void { $user = User::factory()->create(); Sanctum::actingAs($user); // XYZ 는 등록 통화 목록에 없음 → 422 $response = $this->putJson(self::UPDATE_URL, ['currency' => 'XYZ']); $response->assertStatus(422); $response->assertJsonValidationErrors('currency'); $this->assertNull( app(EcommerceUserProfileRepositoryInterface::class)->getPreferredCurrency($user->id) ); } public function test_currency_without_exchange_rate_is_rejected(): void { $user = User::factory()->create(); Sanctum::actingAs($user); // KRW 는 기본통화(is_default) → 허용. 환율 미설정 비-기본 통화는 거부되어야 하나 // 기본 통화는 항상 허용됨을 확인(golden). $response = $this->putJson(self::UPDATE_URL, ['currency' => 'KRW']); $response->assertOk(); } public function test_guest_cannot_update_currency(): void { $response = $this->putJson(self::UPDATE_URL, ['currency' => 'USD']); $response->assertStatus(401); } public function test_show_returns_current_currency(): void { $user = User::factory()->create(); Sanctum::actingAs($user); app(EcommerceUserProfileRepositoryInterface::class)->setPreferredCurrency($user->id, 'JPY'); $response = $this->getJson(self::UPDATE_URL); $response->assertOk(); $response->assertJsonPath('data.preferred_currency', 'JPY'); } }