mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-14 08:18:08 +00:00
test: add Pest browser testing with SQLite :memory: schema
Set up end-to-end browser testing using Pest Browser Plugin + Playwright. New v4 test suite uses SQLite :memory: database with pre-generated schema dump (database/schema/testing-schema.sql) instead of running migrations, enabling faster test startup. - Add pestphp/pest-plugin-browser dependency - Create GenerateTestingSchema command to export PostgreSQL schema to SQLite - Add .env.testing configuration for isolated test environment - Implement v4 test directory structure (Feature, Browser, Unit tests) - Update Pest skill documentation with browser testing patterns, API reference, debugging techniques, and common pitfalls - Configure phpunit.xml and tests/Pest.php for v4 suite - Update package.json and docker-compose.dev.yml for testing dependencies
This commit is contained in:
1 parent
0c19464db1
commit
47a3f2e2cd
20 files changed
+3887
-130
No files matched your search
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
InstanceSettings::create(['id' => 0]);
|
||||
});
|
||||
|
||||
it('shows registration page when no users exist', function () {
|
||||
$page = visit('/login');
|
||||
|
||||
$page->assertSee('Root User Setup')
|
||||
->assertSee('Create Account');
|
||||
});
|
||||
|
||||
it('can login with valid credentials', function () {
|
||||
User::factory()->create([
|
||||
'id' => 0,
|
||||
'email' => 'test@example.com',
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
|
||||
$page = visit('/login');
|
||||
|
||||
$page->assertSee('Login');
|
||||
});
|
||||
|
||||
it('fails login with invalid credentials', function () {
|
||||
User::factory()->create([
|
||||
'id' => 0,
|
||||
'email' => 'test@example.com',
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
|
||||
$page = visit('/login');
|
||||
|
||||
$page->fill('email', 'random@email.com')
|
||||
->fill('password', 'wrongpassword123')
|
||||
->click('Login')
|
||||
->assertSee('These credentials do not match our records');
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
InstanceSettings::create(['id' => 0]);
|
||||
});
|
||||
|
||||
it('shows registration page when no users exist', function () {
|
||||
$page = visit('/register');
|
||||
|
||||
$page->assertSee('Root User Setup')
|
||||
->assertSee('Create Account');
|
||||
});
|
||||
|
||||
it('can register a new root user', function () {
|
||||
$page = visit('/register');
|
||||
|
||||
$page->fill('name', 'Test User')
|
||||
->fill('email', 'root@example.com')
|
||||
->fill('password', 'Password1!@')
|
||||
->fill('password_confirmation', 'Password1!@')
|
||||
->click('Create Account')
|
||||
->assertPathIs('/onboarding');
|
||||
|
||||
expect(User::where('email', 'root@example.com')->exists())->toBeTrue();
|
||||
});
|
||||
|
||||
it('fails registration with mismatched passwords', function () {
|
||||
$page = visit('/register');
|
||||
|
||||
$page->fill('name', 'Test User')
|
||||
->fill('email', 'root@example.com')
|
||||
->fill('password', 'Password1!@')
|
||||
->fill('password_confirmation', 'DifferentPass1!@')
|
||||
->click('Create Account')
|
||||
->assertSee('password');
|
||||
});
|
||||
|
||||
it('fails registration with weak password', function () {
|
||||
$page = visit('/register');
|
||||
|
||||
$page->fill('name', 'Test User')
|
||||
->fill('email', 'root@example.com')
|
||||
->fill('password', 'short')
|
||||
->fill('password_confirmation', 'short')
|
||||
->click('Create Account')
|
||||
->assertSee('password');
|
||||
});
|
||||
|
||||
it('shows login link when a user already exists', function () {
|
||||
User::factory()->create(['id' => 0]);
|
||||
|
||||
$page = visit('/register');
|
||||
|
||||
$page->assertSee('Already registered?')
|
||||
->assertDontSee('Root User Setup');
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('uses sqlite for testing', function () {
|
||||
expect(DB::connection()->getDriverName())->toBe('sqlite');
|
||||
});
|
||||
|
||||
it('runs migrations successfully', function () {
|
||||
expect(Schema::hasTable('users'))->toBeTrue();
|
||||
expect(Schema::hasTable('teams'))->toBeTrue();
|
||||
expect(Schema::hasTable('servers'))->toBeTrue();
|
||||
expect(Schema::hasTable('applications'))->toBeTrue();
|
||||
});
|
||||
Reference in new issue
Block a user