wip testing
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Portfolio>
|
||||||
|
*/
|
||||||
|
class PortfolioFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => $this->faker->word,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Portfolio;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Transaction>
|
||||||
|
*/
|
||||||
|
class TransactionFactory extends Factory
|
||||||
|
{
|
||||||
|
protected static ?string $transaction_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'symbol' => $this->faker->randomElement(['AAPL', 'GOOGL', 'AMZN']),
|
||||||
|
'transaction_type' => static::$transaction_type = $this->faker->randomElement(['BUY', 'SELL']),
|
||||||
|
'portfolio_id' => Portfolio::factory()->create(),
|
||||||
|
'date' => $this->faker->date('Y-m-d'),
|
||||||
|
'quantity' => $this->faker->randomFloat(2, 1, 100),
|
||||||
|
'cost_basis' => $this->faker->randomFloat(2, 10, 500),
|
||||||
|
'sale_price' => static::$transaction_type == 'SELL'
|
||||||
|
? $this->faker->randomFloat(2, 10, 500)
|
||||||
|
: null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function symbol($symbol): static
|
||||||
|
{
|
||||||
|
return $this->state(fn (array $attributes) => [
|
||||||
|
'symbol' => $symbol,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function portfolios($portfolio_id): static
|
||||||
|
{
|
||||||
|
return $this->state(fn (array $attributes) => [
|
||||||
|
'portfolio_id' => $portfolio_id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buy(): static
|
||||||
|
{
|
||||||
|
return $this->state(fn (array $attributes) => [
|
||||||
|
'transaction_type' => 'BUY',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sell(): static
|
||||||
|
{
|
||||||
|
return $this->state(fn (array $attributes) => [
|
||||||
|
'transaction_type' => 'SELL',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,9 @@
|
|||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Team;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Laravel\Jetstream\Features;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||||
@@ -47,25 +44,4 @@ class UserFactory extends Factory
|
|||||||
'email_verified_at' => null,
|
'email_verified_at' => null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicate that the user should have a personal team.
|
|
||||||
*/
|
|
||||||
public function withPersonalTeam(?callable $callback = null): static
|
|
||||||
{
|
|
||||||
if (! Features::hasTeamFeatures()) {
|
|
||||||
return $this->state([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->has(
|
|
||||||
Team::factory()
|
|
||||||
->state(fn (array $attributes, User $user) => [
|
|
||||||
'name' => $user->name.'\'s Team',
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'personal_team' => true,
|
|
||||||
])
|
|
||||||
->when(is_callable($callback), $callback),
|
|
||||||
'ownedTeams'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -5,11 +5,8 @@
|
|||||||
colors="true"
|
colors="true"
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Unit">
|
<testsuite name="Tests">
|
||||||
<directory>tests/Unit</directory>
|
<directory>tests</directory>
|
||||||
</testsuite>
|
|
||||||
<testsuite name="Feature">
|
|
||||||
<directory>tests/Feature</directory>
|
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<source>
|
<source>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
@@ -20,7 +20,7 @@ class ApiTokenPermissionsTest extends TestCase
|
|||||||
// $this->markTestSkipped('API support is not enabled.');
|
// $this->markTestSkipped('API support is not enabled.');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// $this->actingAs($user = User::factory()->withPersonalTeam()->create());
|
// $this->actingAs($user = User::factory()->create());
|
||||||
|
|
||||||
// $token = $user->tokens()->create([
|
// $token = $user->tokens()->create([
|
||||||
// 'name' => 'Test Token',
|
// 'name' => 'Test Token',
|
||||||
@@ -41,7 +41,7 @@ class ApiTokenPermissionsTest extends TestCase
|
|||||||
// $this->markTestSkipped('API support is not enabled.');
|
// $this->markTestSkipped('API support is not enabled.');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// $this->actingAs($user = User::factory()->withPersonalTeam()->create());
|
// $this->actingAs($user = User::factory()->create());
|
||||||
|
|
||||||
// Livewire::test(ApiTokenManager::class)
|
// Livewire::test(ApiTokenManager::class)
|
||||||
// ->set(['createApiTokenForm' => [
|
// ->set(['createApiTokenForm' => [
|
||||||
@@ -65,7 +65,7 @@ class ApiTokenPermissionsTest extends TestCase
|
|||||||
// $this->markTestSkipped('API support is not enabled.');
|
// $this->markTestSkipped('API support is not enabled.');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// $this->actingAs($user = User::factory()->withPersonalTeam()->create());
|
// $this->actingAs($user = User::factory()->create());
|
||||||
|
|
||||||
// $token = $user->tokens()->create([
|
// $token = $user->tokens()->create([
|
||||||
// 'name' => 'Test Token',
|
// 'name' => 'Test Token',
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Auth\Events\Verified;
|
use Illuminate\Auth\Events\Verified;
|
||||||
@@ -20,7 +20,7 @@ class EmailVerificationTest extends TestCase
|
|||||||
$this->markTestSkipped('Email verification not enabled.');
|
$this->markTestSkipped('Email verification not enabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = User::factory()->withPersonalTeam()->unverified()->create();
|
$user = User::factory()->unverified()->create();
|
||||||
|
|
||||||
$response = $this->actingAs($user)->get('/email/verify');
|
$response = $this->actingAs($user)->get('/email/verify');
|
||||||
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature;
|
|
||||||
|
|
||||||
// use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A basic test example.
|
|
||||||
*/
|
|
||||||
public function test_the_application_returns_a_successful_response(): void
|
|
||||||
{
|
|
||||||
$response = $this->get('/');
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
@@ -12,7 +12,7 @@ class PasswordConfirmationTest extends TestCase
|
|||||||
|
|
||||||
public function test_confirm_password_screen_can_be_rendered(): void
|
public function test_confirm_password_screen_can_be_rendered(): void
|
||||||
{
|
{
|
||||||
$user = User::factory()->withPersonalTeam()->create();
|
$user = User::factory()->create();
|
||||||
|
|
||||||
$response = $this->actingAs($user)->get('/user/confirm-password');
|
$response = $this->actingAs($user)->get('/user/confirm-password');
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Auth\Notifications\ResetPassword;
|
use Illuminate\Auth\Notifications\ResetPassword;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Laravel\Fortify\Features;
|
use Laravel\Fortify\Features;
|
||||||
@@ -22,17 +22,6 @@ class RegistrationTest extends TestCase
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function test_registration_screen_cannot_be_rendered_if_support_is_disabled(): void
|
|
||||||
// {
|
|
||||||
// if (Features::enabled(Features::registration())) {
|
|
||||||
// $this->markTestSkipped('Registration support is enabled.');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $response = $this->get('/register');
|
|
||||||
|
|
||||||
// $response->assertStatus(404);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public function test_new_users_can_register(): void
|
public function test_new_users_can_register(): void
|
||||||
{
|
{
|
||||||
if (! Features::enabled(Features::registration())) {
|
if (! Features::enabled(Features::registration())) {
|
||||||
+14
-1
@@ -2,9 +2,22 @@
|
|||||||
|
|
||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
//
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Artisan::call('migrate');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\Portfolio;
|
||||||
|
use App\Models\Transaction;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
|
class TransactionsTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
/**
|
||||||
|
* A basic test example.
|
||||||
|
*/
|
||||||
|
public function test_can_create_a_transaction(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$transactions = Transaction::factory()->create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// static::saving(function ($transaction) {
|
||||||
|
|
||||||
|
// if ($transaction->transaction_type == 'SELL') {
|
||||||
|
|
||||||
|
// $transaction->ensureCostBasisIsAddedToSale();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// static::saved(function ($transaction) {
|
||||||
|
|
||||||
|
// $transaction->syncToHolding();
|
||||||
|
|
||||||
|
// $transaction->refreshMarketData();
|
||||||
|
|
||||||
|
// cache()->tags(['metrics', $transaction->portfolio_id])->flush();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// public function update()
|
||||||
|
// {
|
||||||
|
|
||||||
|
// $this->transaction->update($this->validate());
|
||||||
|
// // $this->transaction->owner_id = auth()->user()->id;
|
||||||
|
// $this->transaction->save();
|
||||||
|
|
||||||
|
// $this->success(__('Transaction updated'));
|
||||||
|
|
||||||
|
// $this->dispatch('toggle-manage-transaction');
|
||||||
|
// $this->dispatch('transaction-updated');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function save()
|
||||||
|
// {
|
||||||
|
// $validated = $this->validate();
|
||||||
|
|
||||||
|
// if (!isset($this->portfolio)) {
|
||||||
|
// $this->portfolio = Portfolio::find($this->portfolio_id);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $transaction = $this->portfolio->transactions()->create($validated);
|
||||||
|
// $transaction->save();
|
||||||
|
|
||||||
|
// $this->dispatch('transaction-saved');
|
||||||
|
|
||||||
|
// $this->success(__('Transaction created'), redirectTo: route('holding.show', ['portfolio' => $this->portfolio->id, 'symbol' => $this->symbol]));
|
||||||
|
// }
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A basic test example.
|
|
||||||
*/
|
|
||||||
public function test_that_true_is_true(): void
|
|
||||||
{
|
|
||||||
$this->assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
Reference in New Issue
Block a user