b2in/tests/Feature/CreateNewUserOriginTest.php
2026-02-20 17:57:50 +01:00

95 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
use App\Actions\Fortify\CreateNewUser;
use App\Enums\UserOrigin;
use App\Models\Hub;
test('new user gets style2own origin when theme is style2own', function () {
config(['app.theme' => 'style2own']);
$action = new CreateNewUser;
$user = $action->create([
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'Password123!',
'password_confirmation' => 'Password123!',
]);
expect($user->origin)->toBe(UserOrigin::Style2Own);
expect($user->origin->value)->toBe('style2own');
});
test('new user gets stileigentum origin when theme is stileigentum', function () {
config(['app.theme' => 'stileigentum']);
$action = new CreateNewUser;
$user = $action->create([
'name' => 'Test User 2',
'email' => 'test2@example.com',
'password' => 'Password123!',
'password_confirmation' => 'Password123!',
]);
expect($user->origin)->toBe(UserOrigin::StilEigentum);
expect($user->origin->value)->toBe('stileigentum');
});
test('new user has null origin when theme is unknown', function () {
config(['app.theme' => 'portal']);
$action = new CreateNewUser;
$user = $action->create([
'name' => 'Test User 3',
'email' => 'test3@example.com',
'password' => 'Password123!',
'password_confirmation' => 'Password123!',
]);
expect($user->origin)->toBeNull();
});
test('new user has null origin when theme is empty', function () {
config(['app.theme' => '']);
$action = new CreateNewUser;
$user = $action->create([
'name' => 'Test User 4',
'email' => 'test4@example.com',
'password' => 'Password123!',
'password_confirmation' => 'Password123!',
]);
expect($user->origin)->toBeNull();
});
test('new user stores hub_id when provided', function () {
$hub = Hub::factory()->create();
config(['app.theme' => '']);
$action = new CreateNewUser;
$user = $action->create([
'name' => 'Hub User',
'email' => 'hubuser@example.com',
'password' => 'Password123!',
'password_confirmation' => 'Password123!',
'hub_id' => $hub->id,
]);
expect($user->hub_id)->toBe($hub->id);
});
test('new user has null hub_id when not provided', function () {
config(['app.theme' => '']);
$action = new CreateNewUser;
$user = $action->create([
'name' => 'No Hub User',
'email' => 'nohub@example.com',
'password' => 'Password123!',
'password_confirmation' => 'Password123!',
]);
expect($user->hub_id)->toBeNull();
});