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'
);
}
}