diff --git a/app/Livewire/Tokens.php b/app/Livewire/Tokens.php index 0b686f5..508e37d 100644 --- a/app/Livewire/Tokens.php +++ b/app/Livewire/Tokens.php @@ -32,7 +32,7 @@ public function reloadTokens() $this->tokens->shift(); $this->tokens->prepend( - collect($tokens)->sortBy(fn ($token) => $token->price * $token->balance) + collect($tokens)->sortBy(fn ($token) => $token->price * $token->balance)->values() ); $this->balances['prices'][] = $result->ethereumPrice->usd; diff --git a/tests/Feature/Livewire/TokensTest.php b/tests/Feature/Livewire/TokensTest.php index 6533248..029d742 100644 --- a/tests/Feature/Livewire/TokensTest.php +++ b/tests/Feature/Livewire/TokensTest.php @@ -42,7 +42,7 @@ $result = Http::get(config('tokens.api_url'))->object(); - $newTokens = $result->balances; + $newTokens = collect($result->balances)->sortBy(fn ($token) => $token->price * $token->balance)->values(); $supabaseService = new SupabaseService('fake-api-key', 'https://fake-url.supabase.co'); @@ -52,16 +52,14 @@ Livewire::test(Tokens::class) ->dispatch('tokens-loaded') ->assertSet('tokens', fn ($tokens) => - count($tokens) == count($oldTokens) - && $newTokens[0] == $tokens->first()->get(0) - && $oldTokens->get(0) != $tokens->get(0) - && $oldTokens->get(1) == $tokens->get(1) + $tokens->get(0) == $newTokens && + $tokens->get(1) == $oldTokens->get(1) )->assertSet('balances', fn ($balances) => end($oldBalances['prices']) == $balances['prices'][count($balances['prices']) - 2] && end($balances['prices']) == $result->ethereumPrice->usd && end($balances['prices_eur']) == $result->ethereumPrice->eur && end($balances['totals']) == collect($newTokens)->sum(fn ($token) => $token->price * $token->balance) - && end($balances['totals_eur']) == collect($newTokens)->sum(fn ($token) => $token->price_eur * $token->balance) + && round(end($balances['totals_eur']), 9) == round(collect($newTokens)->sum(fn ($token) => $token->price_eur * $token->balance), 9) && end($balances['ethereum']) == collect($newTokens)->sum(fn ($token) => $token->price * $token->balance / $result->ethereumPrice->usd) ); });