Skip to content

Commit e1185af

Browse files
committed
Fixed failing tests because of legacy currency codes
1 parent f9c0d64 commit e1185af

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

app/Service/CurrencyService.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\Service;
66

7+
use Brick\Money\ISOCurrencyProvider;
78
use Brick\Money\Money;
89

910
class CurrencyService
@@ -374,4 +375,12 @@ public function getCurrencySymbol(string $currencyCode): string
374375

375376
return $currencyCode;
376377
}
378+
379+
public function getRandomCurrencyCode(): string
380+
{
381+
$currencies = ISOCurrencyProvider::getInstance()->getAvailableCurrencies();
382+
$currencyCodes = array_keys($currencies);
383+
384+
return $currencyCodes[array_rand($currencyCodes)];
385+
}
377386
}

database/factories/OrganizationFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use App\Enums\TimeFormat;
1212
use App\Models\Organization;
1313
use App\Models\User;
14+
use App\Service\CurrencyService;
1415
use Illuminate\Database\Eloquent\Factories\Factory;
1516

1617
/**
@@ -27,7 +28,7 @@ public function definition(): array
2728
{
2829
return [
2930
'name' => $this->faker->unique()->company(),
30-
'currency' => $this->faker->currencyCode(),
31+
'currency' => app(CurrencyService::class)->getRandomCurrencyCode(),
3132
'billable_rate' => null,
3233
'user_id' => User::factory(),
3334
'personal_team' => true,

tests/Unit/Service/CurrencyServiceTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,15 @@ public function test_get_currency_symbol_for_currency_without_known_symbol(): vo
9292
// Assert
9393
$this->assertSame('XXX', $symbol);
9494
}
95+
96+
public function test_get_random_currency_code(): void
97+
{
98+
// Act
99+
$currencyCode = $this->currencyService->getRandomCurrencyCode();
100+
101+
// Assert
102+
$this->assertNotEmpty($currencyCode);
103+
$this->assertIsString($currencyCode);
104+
$this->assertNotNull(Currency::of($currencyCode));
105+
}
95106
}

0 commit comments

Comments
 (0)