mirror of
https://github.com/pacnpal/thrillwiki_laravel.git
synced 2025-12-20 00:51:11 -05:00
Add testing environment configuration and create model factories for Operator and Park
This commit is contained in:
22
.env.testing
Normal file
22
.env.testing
Normal file
@@ -0,0 +1,22 @@
|
||||
APP_NAME="ThrillWiki"
|
||||
APP_ENV=testing
|
||||
APP_KEY=base64:UzB6YEBskhM4O43pu4z4F8pscMD3A6NPWPpwZ+lkaMU=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=pgsql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=5432
|
||||
DB_DATABASE=thrillwiki_test
|
||||
DB_USERNAME=talor
|
||||
DB_PASSWORD=
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=array
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=array
|
||||
28
database/factories/OperatorFactory.php
Normal file
28
database/factories/OperatorFactory.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Operator;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class OperatorFactory extends Factory
|
||||
{
|
||||
protected $model = Operator::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->unique()->company(),
|
||||
'slug' => fake()->unique()->slug(2),
|
||||
'description' => fake()->paragraph(),
|
||||
'website' => fake()->url(),
|
||||
'headquarters' => fake()->city() . ', ' . fake()->country(),
|
||||
'founded_year' => fake()->year(),
|
||||
'total_parks' => fake()->numberBetween(1, 10),
|
||||
'total_rides' => fake()->numberBetween(20, 200),
|
||||
'annual_visitors' => fake()->numberBetween(1000000, 50000000),
|
||||
'employee_count' => fake()->numberBetween(1000, 50000),
|
||||
'revenue' => fake()->numberBetween(100000000, 5000000000),
|
||||
];
|
||||
}
|
||||
}
|
||||
73
database/factories/ParkFactory.php
Normal file
73
database/factories/ParkFactory.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Park;
|
||||
use App\Models\Operator;
|
||||
use App\Enums\ParkStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class ParkFactory extends Factory
|
||||
{
|
||||
protected $model = Park::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->unique()->company() . ' Theme Park',
|
||||
'slug' => fake()->unique()->slug(3),
|
||||
'description' => fake()->paragraph(),
|
||||
'status' => fake()->randomElement(ParkStatus::cases()),
|
||||
'opening_date' => fake()->dateTimeBetween('-50 years', '-1 year'),
|
||||
'operating_season' => 'Year-round',
|
||||
'size_acres' => fake()->numberBetween(20, 500),
|
||||
'website' => fake()->url(),
|
||||
'operator_id' => Operator::factory(),
|
||||
'total_areas' => fake()->numberBetween(3, 8),
|
||||
'operating_areas' => fake()->numberBetween(2, 8),
|
||||
'closed_areas' => fake()->numberBetween(0, 2),
|
||||
'total_rides' => fake()->numberBetween(20, 60),
|
||||
'total_coasters' => fake()->numberBetween(2, 15),
|
||||
'total_flat_rides' => fake()->numberBetween(10, 30),
|
||||
'total_water_rides' => fake()->numberBetween(1, 5),
|
||||
'total_daily_capacity' => fake()->numberBetween(10000, 50000),
|
||||
'average_wait_time' => fake()->numberBetween(15, 90),
|
||||
'average_rating' => fake()->randomFloat(1, 3.0, 5.0),
|
||||
'total_rides_operated' => fake()->numberBetween(20, 100),
|
||||
'total_rides_retired' => fake()->numberBetween(0, 20),
|
||||
'last_expansion_date' => fake()->dateTimeBetween('-5 years', 'now'),
|
||||
'last_major_update' => fake()->dateTimeBetween('-1 year', 'now'),
|
||||
'utilization_rate' => fake()->randomFloat(2, 0.50, 0.95),
|
||||
'peak_daily_attendance' => fake()->numberBetween(15000, 100000),
|
||||
'guest_satisfaction' => fake()->randomFloat(1, 3.0, 5.0),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the model factory.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function operating()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'status' => ParkStatus::OPERATING,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the model factory.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function closed()
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'status' => ParkStatus::CLOSED_PERM,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
114
tests/Feature/ParkListTest.php
Normal file
114
tests/Feature/ParkListTest.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
use App\Livewire\ParkListComponent;
|
||||
use App\Models\Park;
|
||||
use App\Models\Operator;
|
||||
use App\Enums\ParkStatus;
|
||||
use Livewire\Livewire;
|
||||
use function Pest\Laravel\get;
|
||||
|
||||
test('parks page loads successfully', function () {
|
||||
get('/parks')->assertSuccessful();
|
||||
});
|
||||
|
||||
test('park list component shows parks', function () {
|
||||
$park = Park::factory()->create([
|
||||
'name' => 'Test Park',
|
||||
'status' => ParkStatus::OPERATING
|
||||
]);
|
||||
|
||||
Livewire::test(ParkListComponent::class)
|
||||
->assertSee('Test Park');
|
||||
});
|
||||
|
||||
test('search filters parks', function () {
|
||||
$matchingPark = Park::factory()->create(['name' => 'Magic Kingdom']);
|
||||
$nonMatchingPark = Park::factory()->create(['name' => 'Epcot']);
|
||||
|
||||
Livewire::test(ParkListComponent::class)
|
||||
->set('search', 'Magic')
|
||||
->assertSee('Magic Kingdom')
|
||||
->assertDontSee('Epcot');
|
||||
});
|
||||
|
||||
test('status filter shows only matching parks', function () {
|
||||
$operatingPark = Park::factory()->create([
|
||||
'name' => 'Operating Park',
|
||||
'status' => ParkStatus::OPERATING
|
||||
]);
|
||||
|
||||
$closedPark = Park::factory()->create([
|
||||
'name' => 'Closed Park',
|
||||
'status' => ParkStatus::CLOSED_PERM
|
||||
]);
|
||||
|
||||
Livewire::test(ParkListComponent::class)
|
||||
->set('status', ParkStatus::OPERATING->value)
|
||||
->assertSee('Operating Park')
|
||||
->assertDontSee('Closed Park');
|
||||
});
|
||||
|
||||
test('operator filter shows only matching parks', function () {
|
||||
$operator1 = Operator::factory()->create(['name' => 'Disney']);
|
||||
$operator2 = Operator::factory()->create(['name' => 'Universal']);
|
||||
|
||||
$disneyPark = Park::factory()->create([
|
||||
'name' => 'Disney Park',
|
||||
'operator_id' => $operator1->id
|
||||
]);
|
||||
|
||||
$universalPark = Park::factory()->create([
|
||||
'name' => 'Universal Park',
|
||||
'operator_id' => $operator2->id
|
||||
]);
|
||||
|
||||
Livewire::test(ParkListComponent::class)
|
||||
->set('operator', $operator1->id)
|
||||
->assertSee('Disney Park')
|
||||
->assertDontSee('Universal Park');
|
||||
});
|
||||
|
||||
test('sorting works correctly', function () {
|
||||
$laterPark = Park::factory()->create([
|
||||
'name' => 'Later Park',
|
||||
'opening_date' => '2020-01-01'
|
||||
]);
|
||||
|
||||
$earlierPark = Park::factory()->create([
|
||||
'name' => 'Earlier Park',
|
||||
'opening_date' => '2010-01-01'
|
||||
]);
|
||||
|
||||
// Test date sorting ascending
|
||||
Livewire::test(ParkListComponent::class)
|
||||
->set('sort', 'opening_date')
|
||||
->set('direction', 'asc')
|
||||
->assertSeeInOrder(['Earlier Park', 'Later Park']);
|
||||
|
||||
// Test date sorting descending
|
||||
Livewire::test(ParkListComponent::class)
|
||||
->set('sort', 'opening_date')
|
||||
->set('direction', 'desc')
|
||||
->assertSeeInOrder(['Later Park', 'Earlier Park']);
|
||||
});
|
||||
|
||||
test('pagination works', function () {
|
||||
// Create 15 parks (more than the per-page limit of 12)
|
||||
Park::factory()->count(15)->create();
|
||||
|
||||
Livewire::test(ParkListComponent::class)
|
||||
->assertViewHas('parks', function ($parks) {
|
||||
return $parks->count() == 12; // First page should have 12 items
|
||||
});
|
||||
});
|
||||
|
||||
test('query string parameters work', function () {
|
||||
$park = Park::factory()->create([
|
||||
'name' => 'Test Park',
|
||||
'status' => ParkStatus::OPERATING
|
||||
]);
|
||||
|
||||
get('/parks?search=Test&status=' . ParkStatus::OPERATING->value)
|
||||
->assertSuccessful()
|
||||
->assertSee('Test Park');
|
||||
});
|
||||
Reference in New Issue
Block a user