fixes multi currency tests

This commit is contained in:
hackerESQ
2025-04-11 20:57:21 -05:00
parent 26e54fb357
commit 38a65f99c9
6 changed files with 71 additions and 44 deletions
+8
View File
@@ -7,7 +7,9 @@ namespace Tests\Api;
use App\Models\Portfolio;
use App\Models\Transaction;
use App\Models\User;
use Database\Seeders\CurrencySeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;
class TransactionsTest extends TestCase
@@ -69,6 +71,11 @@ class TransactionsTest extends TestCase
public function test_can_create_transaction()
{
Artisan::call('db:seed', [
'--class' => CurrencySeeder::class,
'--force' => true,
]);
$this->actingAs($this->user);
$data = [
@@ -76,6 +83,7 @@ class TransactionsTest extends TestCase
'portfolio_id' => $this->portfolio->id,
'transaction_type' => 'BUY',
'quantity' => 10,
'currency' => 'USD',
'date' => now()->toDateString(),
'cost_basis' => 150,
];
+4 -2
View File
@@ -241,9 +241,11 @@ class DailyChangeTest extends TestCase
'transaction_type' => 'BUY',
]);
$daily_change_day_after = DailyChange::withDailyPerformance()->whereDate('daily_change.date', $third_transaction->date->addDay())->first();
$daily_change_day_before = DailyChange::withDailyPerformance()->whereDate('daily_change.date', $third_transaction->date->subDay())->first();
$daily_change_day_after = DailyChange::withDailyPerformance()->whereDate('daily_change.date', $third_transaction->date->nextWeekday())->first();
$daily_change_day_before = DailyChange::withDailyPerformance()->whereDate('daily_change.date', $third_transaction->date->previousWeekday())->first();
$this->assertNotNull($daily_change_day_after);
$this->assertNotNull($daily_change_day_before);
$this->assertEquals(39.89, $daily_change_day_after->total_cost_basis - $daily_change_day_before->total_cost_basis);
}
}
+5 -5
View File
@@ -17,6 +17,7 @@ use App\Models\User;
use Carbon\CarbonPeriod;
use Database\Seeders\CurrencySeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Artisan;
use Investbrain\Frankfurter\Frankfurter;
use Mockery;
@@ -210,10 +211,10 @@ class MultiCurrencyTest extends TestCase
$start = now()->subWeeks(2);
$end = now();
$results = [];
$period = CarbonPeriod::create($start, $end);
// mock response from Frankfurter
$results = [];
collect($period->copy()->filter('isWeekday'))->each(function ($date) use (&$results) {
$date = $date->toDateString();
@@ -299,7 +300,6 @@ class MultiCurrencyTest extends TestCase
public function test_can_handle_aliases_for_time_series_rates()
{
$start = now()->subWeeks(2);
$end = now();
$adjustment = 100;
@@ -333,8 +333,8 @@ class MultiCurrencyTest extends TestCase
$result = CurrencyRate::timeSeriesRates('ZZZ', $start, $end);
$this->assertEquals(
$results[$end->toDateString()]['YYY'] * $adjustment,
$result[$end->toDateString()]
Arr::last($results)['YYY'] * $adjustment,
Arr::last($result)
);
}