Files
InvoiceShelf/tests/Feature/PilotSpec/InstallationWizardTest.php
T
Darko Gjorgjijoski 605d700f75 test: add the behavioral spec suites (pilot + ten domains)
98 tests pinning observable behavior ahead of the authorship rewrite.
2026-08-20 17:19:26 +02:00

71 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// Pilot behavioural suite — installation state and wizard progress.
// Spec: platform-operations-spec.md §23.
use Illuminate\Support\Facades\DB;
use function Pest\Laravel\getJson;
use function Pest\Laravel\postJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
// DatabaseSeeder leaves profile_complete at 0: database created, NOT installed.
});
function pilotSetSetting(string $key, $value): void
{
DB::table('settings')->updateOrInsert(['option' => $key], ['option' => $key, 'value' => $value]);
}
it('caches the created-database probe for the lifetime of the process', function () {
// The first probe in this PHP process ran at boot, before the schema
// existed, and the answer is cached per process — so the wizard reports
// the pre-database defaults even though the tables exist by now. This is
// deliberate current behaviour; the stored-values branch and the
// redirect-once-completed behaviour are pinned by the sandbox scenarios
// (see the suite README).
pilotSetSetting('profile_complete', 'STEP_2');
pilotSetSetting('profile_language', 'de');
getJson('/api/v1/installation/wizard-step')
->assertOk()
->assertJson(['profile_complete' => 0, 'profile_language' => 'en']);
});
it('stores a wizard step and echoes the stored value', function () {
postJson('/api/v1/installation/wizard-step', ['profile_complete' => 'STEP_3'])
->assertOk()
->assertJson(['profile_complete' => 'STEP_3']);
expect(DB::table('settings')->where('option', 'profile_complete')->value('value'))
->toBe('STEP_3');
});
it('refuses to overwrite a completed wizard state', function () {
pilotSetSetting('profile_complete', 'COMPLETED');
postJson('/api/v1/installation/wizard-step', ['profile_complete' => 'STEP_1'])
->assertOk()
->assertJson(['profile_complete' => 'COMPLETED']);
expect(DB::table('settings')->where('option', 'profile_complete')->value('value'))
->toBe('COMPLETED');
});
it('stores the wizard language and echoes it', function () {
postJson('/api/v1/installation/wizard-language', ['profile_language' => 'fr'])
->assertOk()
->assertJson(['profile_language' => 'fr']);
expect(DB::table('settings')->where('option', 'profile_language')->value('value'))
->toBe('fr');
});
it('lists the supported languages as code and name pairs', function () {
$response = getJson('/api/v1/installation/languages')->assertOk()->json();
expect($response['languages'])->toBeArray()->not->toBeEmpty();
expect(collect($response['languages'])->firstWhere('code', 'en')['name'])->toBe('English');
});