trypost/tests/Feature/Auth/RegistrationTest.php
Paulo Castellano 8689e54e55 refactor: restructure to Actions, subdomain routes (app/api), API tokens
- Extract business logic from controllers into Action classes:
  Post/, Workspace/, Hashtag/, Label/, Invite/, ApiKey/
- Create subdomain routing: app.trypost.test (Inertia dashboard),
  api.trypost.test (REST API with token auth)
- Add ApiToken model with tp_ prefix, token_lookup/hash auth
- Add AuthenticateApiToken middleware for API authentication
- Create Api controllers with JSON Resources for all entities
- Create App controllers that use Actions + Inertia responses
- Organize Form Requests into Api/ and App/ directories
- Add api_tokens migration
- Update all route names with app. prefix
- Update all tests to use new route names (684 passing)
2026-03-29 19:24:28 -03:00

115 lines
3.5 KiB
PHP

<?php
use App\Models\User;
test('registration screen can be rendered', function () {
$response = $this->get(route('register'));
$response->assertOk();
});
test('new users can register', function () {
$response = $this->post(route('register.store'), [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'Password123!',
]);
$response->assertSessionHasNoErrors();
$this->assertAuthenticated();
$response->assertRedirect(route('app.onboarding.step1', absolute: false));
});
test('new users get a default workspace on registration', function () {
$this->post(route('register.store'), [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'Password123!',
]);
$user = User::where('email', 'test@example.com')->first();
expect($user)->not->toBeNull();
expect($user->workspaces)->toHaveCount(1);
expect($user->workspaces->first()->name)->toBe("Test User's Workspace");
expect($user->workspaces->first()->timezone)->toBe('UTC');
});
test('new users workspace uses provided timezone', function () {
$this->post(route('register.store'), [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'Password123!',
'timezone' => 'America/Sao_Paulo',
]);
$user = User::where('email', 'test@example.com')->first();
expect($user)->not->toBeNull();
expect($user->workspaces->first()->timezone)->toBe('America/Sao_Paulo');
});
test('new users do not have verified email by default', function () {
$this->post(route('register.store'), [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'Password123!',
]);
$user = User::where('email', 'test@example.com')->first();
expect($user->email_verified_at)->toBeNull();
});
test('new users can register with deprecated timezone Asia/Calcutta', function () {
$this->post(route('register.store'), [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'Password123!',
'timezone' => 'Asia/Calcutta',
]);
$user = User::where('email', 'test@example.com')->first();
expect($user)->not->toBeNull();
expect($user->workspaces->first()->timezone)->toBe('Asia/Calcutta');
});
test('new users can register with deprecated timezone US/Eastern', function () {
$this->post(route('register.store'), [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'Password123!',
'timezone' => 'US/Eastern',
]);
$user = User::where('email', 'test@example.com')->first();
expect($user)->not->toBeNull();
expect($user->workspaces->first()->timezone)->toBe('US/Eastern');
});
test('new users cannot register with invalid timezone', function () {
$response = $this->post(route('register.store'), [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'Password123!',
'timezone' => 'Invalid/Timezone',
]);
$response->assertSessionHasErrors('timezone');
expect(User::where('email', 'test@example.com')->exists())->toBeFalse();
});
test('new users registering via invite have verified email automatically', function () {
$this->post(route('register.store'), [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'Password123!',
'redirect' => '/invites/some-invite-id',
]);
$user = User::where('email', 'test@example.com')->first();
expect($user->email_verified_at)->not->toBeNull();
});