- 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)
81 lines
2.8 KiB
PHP
81 lines
2.8 KiB
PHP
<?php
|
|
|
|
use App\Enums\User\Setup;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
|
|
test('user with completed setup can access protected routes', function () {
|
|
config(['trypost.self_hosted' => true]);
|
|
|
|
$user = User::factory()->create(['setup' => Setup::Completed]);
|
|
$workspace = Workspace::factory()->create(['user_id' => $user->id]);
|
|
$workspace->members()->attach($user->id, ['role' => 'owner']);
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('app.calendar'))
|
|
->assertOk();
|
|
});
|
|
|
|
test('user on role step is redirected to onboarding step 1', function () {
|
|
config(['trypost.self_hosted' => true]);
|
|
|
|
$user = User::factory()->create(['setup' => Setup::Role]);
|
|
$workspace = Workspace::factory()->create(['user_id' => $user->id]);
|
|
$workspace->members()->attach($user->id, ['role' => 'owner']);
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('app.calendar'))
|
|
->assertRedirect(route('app.onboarding.step1'));
|
|
});
|
|
|
|
test('user on connections step is redirected to onboarding step 2', function () {
|
|
config(['trypost.self_hosted' => true]);
|
|
|
|
$user = User::factory()->create(['setup' => Setup::Connections]);
|
|
$workspace = Workspace::factory()->create(['user_id' => $user->id]);
|
|
$workspace->members()->attach($user->id, ['role' => 'owner']);
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('app.calendar'))
|
|
->assertRedirect(route('app.onboarding.step2'));
|
|
});
|
|
|
|
test('user on subscription step is redirected to onboarding step 2', function () {
|
|
config(['trypost.self_hosted' => true]);
|
|
|
|
$user = User::factory()->create(['setup' => Setup::Subscription]);
|
|
$workspace = Workspace::factory()->create(['user_id' => $user->id]);
|
|
$workspace->members()->attach($user->id, ['role' => 'owner']);
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('app.calendar'))
|
|
->assertRedirect(route('app.onboarding.step2'));
|
|
});
|
|
|
|
test('user on role step can access onboarding step 1', function () {
|
|
$user = User::factory()->create(['setup' => Setup::Role]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('app.onboarding.step1'))
|
|
->assertOk();
|
|
});
|
|
|
|
test('user on connections step can access onboarding step 2', function () {
|
|
$user = User::factory()->create(['setup' => Setup::Connections]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('app.onboarding.step2'))
|
|
->assertOk();
|
|
});
|
|
|
|
test('user on connections step can access social connect routes', function () {
|
|
$user = User::factory()->create(['setup' => Setup::Connections]);
|
|
|
|
$this->actingAs($user)
|
|
->get(route('app.social.linkedin.connect'))
|
|
->assertRedirect();
|
|
});
|