Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manelgavalda committed Nov 10, 2023
1 parent 1aa44b2 commit a27a3bd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/Livewire/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions tests/Feature/Livewire/TokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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)
);
});

0 comments on commit a27a3bd

Please sign in to comment.