Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manelgavalda committed Jan 13, 2024
1 parent a1a98dc commit 4d4820f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/Models/Total.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Total extends Model
protected $casts = [
'price' => 'float',
'balance' => 'float',
'btc_price' => 'float',
'price_eur' => 'float'
];
}
1 change: 1 addition & 0 deletions app/Services/SupabaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function getHistoricalBalances()
return [
'prices' => $balances->pluck('price')->toArray(),
'ethereum' => $balances->pluck('balance')->toArray(),
'bitcoin' => $balances->pluck('btc_price')->toArray(),
'prices_eur' => $balances->pluck('price_eur')->toArray(),
'totals' => $balances->map(fn ($balance) => $balance->price * $balance->balance)->toArray(),
'totals_eur' => $balances->map(fn ($balance) => $balance->price_eur * $balance->balance)->toArray(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function up(): void
$table->string('price');
$table->string('balance');
$table->string('price_eur');
$table->string('btc_price')->nullable();
$table->timestamps();
});
}
Expand Down
23 changes: 8 additions & 15 deletions tests/Unit/SupabaseServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
use App\Services\SupabaseService;
use Illuminate\Support\Facades\File;

expect()->extend('toBeParsed', function () {
expect(reset($this->value))->toBe($this->value[0]);

$this->toHaveCount(31);
});

function createEntries($type) {
$file = str()->plural($type);
$class = app()->make('App\Models\\' . str()->ucfirst($type));
Expand All @@ -27,17 +21,16 @@ function createEntries($type) {
});

it('retrieves_the_historical_balances', function () {
expect($dates = $this->balances['dates'])->toBeParsed();
expect($totals = $this->balances['totals'])->toBeParsed();
expect($prices = $this->balances['prices'])->toBeParsed();
expect($ethereum = $this->balances['ethereum'])->toBeParsed();
expect($pricesEur = $this->balances['prices_eur'])->toBeParsed();
expect($totalsEur = $this->balances['totals_eur'])->toBeParsed();

expect(end($totals))->toBe(end($ethereum) * end($prices));
expect(end($totalsEur))->toBe(end($ethereum) * end($pricesEur));
$dates = $this->balances['dates'];

expect(end($dates))->toBe('Nov 08 2024');
expect(end($this->balances['prices']))->toBe(2000.0);
expect(end($this->balances['bitcoin']))->toBe(20000.0);
expect(end($this->balances['ethereum']))->toBe(2000.0);
expect(end($this->balances['totals']))->toBe(4000000.0);
expect(end($this->balances['prices_eur']))->toBe(1900.0);
expect(end($this->balances['totals_eur']))->toBe(3800000.0);

expect(Carbon::parse($dates[0])->lt(Carbon::createFromFormat('M d Y', end($dates))))->toBetrue();
});

Expand Down
1 change: 1 addition & 0 deletions tests/responses/totals.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"price": 2000,
"price_eur": 1900,
"balance": 2000,
"btc_price": 20000,
"created_at": "2024-11-08T00:00:00.000000+00:00"
},
{
Expand Down

0 comments on commit 4d4820f

Please sign in to comment.