diff --git a/app/Service/CurrencyService.php b/app/Service/CurrencyService.php index 92391ebe..2e353f42 100644 --- a/app/Service/CurrencyService.php +++ b/app/Service/CurrencyService.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Service; +use Brick\Money\ISOCurrencyProvider; use Brick\Money\Money; class CurrencyService @@ -374,4 +375,12 @@ class CurrencyService return $currencyCode; } + + public function getRandomCurrencyCode(): string + { + $currencies = ISOCurrencyProvider::getInstance()->getAvailableCurrencies(); + $currencyCodes = array_keys($currencies); + + return $currencyCodes[array_rand($currencyCodes)]; + } } diff --git a/database/factories/OrganizationFactory.php b/database/factories/OrganizationFactory.php index f24cc25d..bb870f3f 100644 --- a/database/factories/OrganizationFactory.php +++ b/database/factories/OrganizationFactory.php @@ -11,6 +11,7 @@ use App\Enums\NumberFormat; use App\Enums\TimeFormat; use App\Models\Organization; use App\Models\User; +use App\Service\CurrencyService; use Illuminate\Database\Eloquent\Factories\Factory; /** @@ -27,7 +28,7 @@ class OrganizationFactory extends Factory { return [ 'name' => $this->faker->unique()->company(), - 'currency' => $this->faker->currencyCode(), + 'currency' => app(CurrencyService::class)->getRandomCurrencyCode(), 'billable_rate' => null, 'user_id' => User::factory(), 'personal_team' => true, diff --git a/tests/Unit/Service/CurrencyServiceTest.php b/tests/Unit/Service/CurrencyServiceTest.php index d7bf0586..76997ce0 100644 --- a/tests/Unit/Service/CurrencyServiceTest.php +++ b/tests/Unit/Service/CurrencyServiceTest.php @@ -92,4 +92,15 @@ class CurrencyServiceTest extends TestCaseWithDatabase // Assert $this->assertSame('XXX', $symbol); } + + public function test_get_random_currency_code(): void + { + // Act + $currencyCode = $this->currencyService->getRandomCurrencyCode(); + + // Assert + $this->assertNotEmpty($currencyCode); + $this->assertIsString($currencyCode); + $this->assertNotNull(Currency::of($currencyCode)); + } }