diff --git a/app/Models/Total.php b/app/Models/Total.php index 73b04a7..3165a7e 100644 --- a/app/Models/Total.php +++ b/app/Models/Total.php @@ -11,6 +11,7 @@ class Total extends Model protected $casts = [ 'price' => 'float', 'balance' => 'float', + 'btc_price' => 'float', 'price_eur' => 'float' ]; } diff --git a/app/Services/SupabaseService.php b/app/Services/SupabaseService.php index aec412d..1ebbd10 100644 --- a/app/Services/SupabaseService.php +++ b/app/Services/SupabaseService.php @@ -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(), diff --git a/database/migrations/2024_01_11_120158_create_totals_table.php b/database/migrations/2024_01_11_120158_create_totals_table.php index d2e3d0c..12096aa 100644 --- a/database/migrations/2024_01_11_120158_create_totals_table.php +++ b/database/migrations/2024_01_11_120158_create_totals_table.php @@ -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(); }); } diff --git a/tests/Unit/SupabaseServiceTest.php b/tests/Unit/SupabaseServiceTest.php index 561eb93..f0c8080 100644 --- a/tests/Unit/SupabaseServiceTest.php +++ b/tests/Unit/SupabaseServiceTest.php @@ -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)); @@ -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(); }); diff --git a/tests/responses/totals.json b/tests/responses/totals.json index a562b1f..1e7c59c 100644 --- a/tests/responses/totals.json +++ b/tests/responses/totals.json @@ -3,6 +3,7 @@ "price": 2000, "price_eur": 1900, "balance": 2000, + "btc_price": 20000, "created_at": "2024-11-08T00:00:00.000000+00:00" }, {