Skip to content

Commit

Permalink
Merge pull request #375 from karlomikus/develop
Browse files Browse the repository at this point in the history
Fix menu cocktail currency null check
  • Loading branch information
karlomikus authored Dec 8, 2024
2 parents 0bbd43c + 1a7dfa1 commit 715a2ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/Models/MenuCocktail.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ public function menu(): BelongsTo

public function getMoney(): Money
{
try {
$currency = Currency::of($this->currency);
} catch (UnknownCurrencyException) {
// Prior to inclusion of Money object, currency could be any string
// To handle migration cases, we'll fallback to EUR
if ($this->currency === null) {
$currency = 'EUR';
} else {
try {
$currency = Currency::of($this->currency);
} catch (UnknownCurrencyException) {
// Prior to inclusion of Money object, currency could be any string
// To handle migration cases, we'll fallback to EUR
$currency = 'EUR';
}
}

return Money::ofMinor($this->price, $currency);
Expand Down
1 change: 1 addition & 0 deletions resources/docker/dist/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fi
# Enable WAL mode
echo "[BAR-ASSISTANT] Enabling database WAL mode..."
sqlite3 "$db_file" 'pragma journal_mode=wal;'
sqlite3 "$db_file" 'pragma synchronous=NORMAL;'

# Start running artisan commands
cd "$APP_BASE_DIR"
Expand Down
12 changes: 12 additions & 0 deletions tests/Feature/Http/MenuControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,16 @@ public function test_export_menu(): void

$response->assertSuccessful();
}

public function test_menu_has_null_currency(): void
{
$menu = Menu::factory()->for($this->barMembership->bar)->create(['is_enabled' => true]);
MenuCocktail::factory()->recycle($menu)->create([
'currency' => null,
]);

$response = $this->getJson('/api/menu', ['Bar-Assistant-Bar-Id' => $this->barMembership->bar_id]);

$response->assertSuccessful();
}
}

0 comments on commit 715a2ad

Please sign in to comment.