wip testing

This commit is contained in:
hackerESQ
2024-09-06 19:39:04 -05:00
parent 9a99686db1
commit 90262abffb
19 changed files with 193 additions and 92 deletions
+26
View File
@@ -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(),
];
}
}
+62
View File
@@ -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',
]);
}
}
-24
View File
@@ -2,12 +2,9 @@
namespace Database\Factories;
use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
@@ -47,25 +44,4 @@ class UserFactory extends Factory
'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
View File
@@ -5,11 +5,8 @@
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory>tests/Feature</directory>
<testsuite name="Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
@@ -1,6 +1,6 @@
<?php
namespace Tests\Feature;
namespace Tests;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -20,7 +20,7 @@ class ApiTokenPermissionsTest extends TestCase
// $this->markTestSkipped('API support is not enabled.');
// }
// $this->actingAs($user = User::factory()->withPersonalTeam()->create());
// $this->actingAs($user = User::factory()->create());
// $token = $user->tokens()->create([
// 'name' => 'Test Token',
@@ -41,7 +41,7 @@ class ApiTokenPermissionsTest extends TestCase
// $this->markTestSkipped('API support is not enabled.');
// }
// $this->actingAs($user = User::factory()->withPersonalTeam()->create());
// $this->actingAs($user = User::factory()->create());
// Livewire::test(ApiTokenManager::class)
// ->set(['createApiTokenForm' => [
@@ -65,7 +65,7 @@ class ApiTokenPermissionsTest extends TestCase
// $this->markTestSkipped('API support is not enabled.');
// }
// $this->actingAs($user = User::factory()->withPersonalTeam()->create());
// $this->actingAs($user = User::factory()->create());
// $token = $user->tokens()->create([
// 'name' => 'Test Token',
@@ -1,6 +1,6 @@
<?php
namespace Tests\Feature;
namespace Tests;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -1,6 +1,6 @@
<?php
namespace Tests\Feature;
namespace Tests;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -1,6 +1,6 @@
<?php
namespace Tests\Feature;
namespace Tests;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -1,6 +1,6 @@
<?php
namespace Tests\Feature;
namespace Tests;
use App\Models\User;
use Illuminate\Auth\Events\Verified;
@@ -20,7 +20,7 @@ class EmailVerificationTest extends TestCase
$this->markTestSkipped('Email verification not enabled.');
}
$user = User::factory()->withPersonalTeam()->unverified()->create();
$user = User::factory()->unverified()->create();
$response = $this->actingAs($user)->get('/email/verify');
-19
View File
@@ -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
namespace Tests\Feature;
namespace Tests;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -12,7 +12,7 @@ class PasswordConfirmationTest extends TestCase
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');
@@ -1,6 +1,6 @@
<?php
namespace Tests\Feature;
namespace Tests;
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
@@ -1,6 +1,6 @@
<?php
namespace Tests\Feature;
namespace Tests;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -1,6 +1,6 @@
<?php
namespace Tests\Feature;
namespace Tests;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
@@ -22,17 +22,6 @@ class RegistrationTest extends TestCase
$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
{
if (! Features::enabled(Features::registration())) {
+14 -1
View File
@@ -2,9 +2,22 @@
namespace Tests;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
protected function setUp(): void
{
parent::setUp();
Artisan::call('migrate');
}
protected function tearDown(): void
{
parent::tearDown();
//
}
}
+73
View File
@@ -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,6 +1,6 @@
<?php
namespace Tests\Feature;
namespace Tests;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
-16
View File
@@ -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
namespace Tests\Feature;
namespace Tests;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;