From 8191985caa5efdde494cebb79f8165b6d7b06ccc Mon Sep 17 00:00:00 2001 From: manel Date: Thu, 9 May 2024 19:01:54 +0200 Subject: [PATCH] Add debt column --- app/Models/Total.php | 1 + app/Services/SupabaseService.php | 1 + database/migrations/2024_01_11_120158_create_totals_table.php | 1 + tests/Unit/SupabaseServiceTest.php | 1 + tests/responses/totals.json | 1 + 5 files changed, 5 insertions(+) diff --git a/app/Models/Total.php b/app/Models/Total.php index 6c158b3..80c9140 100644 --- a/app/Models/Total.php +++ b/app/Models/Total.php @@ -9,6 +9,7 @@ class Total extends Model protected $guarded = []; protected $casts = [ + 'debt' => 'float', 'price' => 'float', 'balance' => 'float', 'price_eur' => 'float', diff --git a/app/Services/SupabaseService.php b/app/Services/SupabaseService.php index 2c3c14e..5be804b 100644 --- a/app/Services/SupabaseService.php +++ b/app/Services/SupabaseService.php @@ -20,6 +20,7 @@ public function getHistoricalBalances() ->reverse()->values(); return [ + 'debt' => $balances->pluck('debt')->toArray(), 'prices' => $balances->pluck('price')->toArray(), // eth_price 'ethereum' => $balances->pluck('balance')->toArray(), // total_usd / eth_price 'btc_prices' => $balances->pluck('btc_price')->toArray(), // btc_price 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 e296c68..351b111 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('debt')->nullable(); $table->string('btc_price')->nullable(); $table->string('btc_price_eur')->nullable(); $table->timestamps(); diff --git a/tests/Unit/SupabaseServiceTest.php b/tests/Unit/SupabaseServiceTest.php index 007fbcf..eb3d42f 100644 --- a/tests/Unit/SupabaseServiceTest.php +++ b/tests/Unit/SupabaseServiceTest.php @@ -24,6 +24,7 @@ function createEntries($type) { $dates = $this->balances['dates']; expect(end($dates))->toBe('Nov 08 2024'); + expect(end($this->balances['debt']))->toBe(5000.0); expect(end($this->balances['prices']))->toBe(2000.0); expect(end($this->balances['bitcoin']))->toBe(200.0); expect(end($this->balances['ethereum']))->toBe(2000.0); diff --git a/tests/responses/totals.json b/tests/responses/totals.json index 63da718..b5488c3 100644 --- a/tests/responses/totals.json +++ b/tests/responses/totals.json @@ -1,5 +1,6 @@ [ { + "debt": 5000, "price": 2000, "price_eur": 1900, "balance": 2000,