Feat: Adds multi currency to imports and exports (#89)

* Also adds ability for user to export configurations
This commit is contained in:
hackerESQ
2025-04-10 20:47:35 -05:00
committed by GitHub
parent eae345f243
commit 1ef8dd9378
23 changed files with 445 additions and 77 deletions
+48
View File
@@ -198,4 +198,52 @@ class DailyChangeTest extends TestCase
$this->assertEqualsWithDelta($total_dividends, $last_dividend_change->total_dividends_earned, 0.01);
}
public function test_daily_changes_synced_into_past_for_older_transactions(): void
{
$this->actingAs($user = User::factory()->create());
$portfolio = Portfolio::factory()->create();
// 1. test daily change will fill to the date of first transaction
$first_transaction = Transaction::factory(5)->buy()->lastMonth()->portfolio($portfolio->id)->symbol('AAPL')->create();
$portfolio->syncDailyChanges();
$first_date = DailyChange::min('date');
$this->assertEquals($first_transaction->min('date')->toDateString(), $first_date);
// 2. test daily change will fill when new transaction pre-dates earliest daily change
config()->set('app.env', 'local');
$this->withoutDefer();
$second_transaction = Transaction::create([
'symbol' => 'AAPL',
'portfolio_id' => $portfolio->id,
'date' => now()->subYears(3),
'quantity' => 1,
'cost_basis' => 39.89,
'transaction_type' => 'BUY',
]);
$second_date = DailyChange::min('date');
$this->assertEquals($second_transaction->date->toDateString(), $second_date);
// 3. test daily change will fill when new transaction is between earliest daily change and earliest transaction
$third_transaction = Transaction::create([
'symbol' => 'AAPL',
'portfolio_id' => $portfolio->id,
'date' => now()->subYears(1),
'quantity' => 1,
'cost_basis' => 39.89,
'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();
$this->assertEquals(39.89, $daily_change_day_after->total_cost_basis - $daily_change_day_before->total_cost_basis);
}
}