tests:import and exporting
This commit is contained in:
@@ -85,7 +85,7 @@ class DailyChangesSheet implements ToCollection, WithHeadingRow, WithValidation,
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'portfolio_id' => ['required'],
|
'portfolio_id' => ['required', 'uuid'],
|
||||||
'date' => ['required', 'date'],
|
'date' => ['required', 'date'],
|
||||||
'total_market_value' => ['sometimes', 'nullable', 'numeric'],
|
'total_market_value' => ['sometimes', 'nullable', 'numeric'],
|
||||||
'total_cost_basis' => ['sometimes', 'nullable', 'min:0', 'numeric'],
|
'total_cost_basis' => ['sometimes', 'nullable', 'min:0', 'numeric'],
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class PortfoliosSheet implements ToCollection, WithValidation, WithHeadingRow, S
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'portfolio_id' => ['sometimes', 'nullable'],
|
'portfolio_id' => ['sometimes', 'nullable', 'uuid'],
|
||||||
'title' => ['required', 'string'],
|
'title' => ['required', 'string'],
|
||||||
'wishlist' => ['sometimes', 'nullable', 'boolean'],
|
'wishlist' => ['sometimes', 'nullable', 'boolean'],
|
||||||
'notes' => ['sometimes', 'nullable', 'string'],
|
'notes' => ['sometimes', 'nullable', 'string'],
|
||||||
|
|||||||
@@ -106,9 +106,9 @@ class TransactionsSheet implements ToCollection, WithHeadingRow, WithValidation,
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'transaction_id' => ['sometimes', 'nullable'],
|
'transaction_id' => ['sometimes', 'nullable', 'uuid'],
|
||||||
'symbol' => ['required', 'string'],
|
'symbol' => ['required', 'string'],
|
||||||
'portfolio_id' => ['required'],
|
'portfolio_id' => ['required', 'uuid'],
|
||||||
'quantity' => ['required', 'min:0', 'numeric'],
|
'quantity' => ['required', 'min:0', 'numeric'],
|
||||||
'transaction_type' => ['required', 'in:BUY,SELL'],
|
'transaction_type' => ['required', 'in:BUY,SELL'],
|
||||||
'date' => ['required', 'date'],
|
'date' => ['required', 'date'],
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Transaction;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use App\Exports\BackupExport;
|
||||||
|
use App\Models\BackupImport as BackupImportModel;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
|
class ImportExportTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public function test_can_create_exports(): void
|
||||||
|
{
|
||||||
|
Excel::fake();
|
||||||
|
|
||||||
|
$this->actingAs($user = User::factory()->create());
|
||||||
|
|
||||||
|
Transaction::factory(5)->buy()->lastYear()->symbol('AAPL')->create();
|
||||||
|
|
||||||
|
Excel::download(new BackupExport, now()->format('Y_m_d') . '_investbrain_backup.xlsx');
|
||||||
|
|
||||||
|
Excel::assertDownloaded(now()->format('Y_m_d') . '_investbrain_backup.xlsx', function(BackupExport $export) {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public function test_backup_job_completes(): void
|
||||||
|
{
|
||||||
|
$this->actingAs($user = User::factory()->create());
|
||||||
|
|
||||||
|
$backup_job = BackupImportModel::create([
|
||||||
|
'user_id' => auth()->user()->id,
|
||||||
|
'path' => __DIR__.'/0000_00_00_import_test.xlsx'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$backup_job->refresh();
|
||||||
|
|
||||||
|
$this->assertEquals('success', $backup_job->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public function test_backup_job_inserts_rows(): void
|
||||||
|
{
|
||||||
|
$this->actingAs($user = User::factory()->create());
|
||||||
|
|
||||||
|
BackupImportModel::create([
|
||||||
|
'user_id' => auth()->user()->id,
|
||||||
|
'path' => __DIR__.'/0000_00_00_import_test.xlsx'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(3, $user->transactions->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public function test_backup_job_calculates_correct_holding_data(): void
|
||||||
|
{
|
||||||
|
$this->actingAs($user = User::factory()->create());
|
||||||
|
|
||||||
|
BackupImportModel::create([
|
||||||
|
'user_id' => auth()->user()->id,
|
||||||
|
'path' => __DIR__.'/0000_00_00_import_test.xlsx'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$holding = $user->holdings->first();
|
||||||
|
|
||||||
|
$this->assertEquals('AAPL', $holding->symbol);
|
||||||
|
$this->assertEquals(6, $holding->quantity);
|
||||||
|
$this->assertEqualsWithDelta(233.33, $holding->average_cost_basis, 0.01);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user