get(route('dashboard'))->assertRedirect(route('login')); }); test('an unsubscribed user is sent to pricing', function () { $this->actingAs(User::factory()->unsubscribed()->create()) ->get(route('dashboard')) ->assertRedirect(route('pricing')); }); test('an unsubscribed user cannot reach the other subscribed pages', function () { $user = User::factory()->unsubscribed()->create(); foreach (['todos', 'folders', 'admin.notes-limits'] as $name) { $this->actingAs($user) ->get(route($name)) ->assertRedirect(route('pricing')); } }); test('a subscribed user reaches the app', function () { $this->actingAs(User::factory()->create()) ->get(route('dashboard')) ->assertOk(); }); test('a grandfathered user reaches the app without a subscription', function () { $user = User::factory()->unsubscribed()->create(); $user->currentOrganization()->first()->forceFill(['lifetime_access' => true])->save(); $this->actingAs($user) ->get(route('dashboard')) ->assertOk(); }); test('a trialing user reaches the app', function () { $user = User::factory()->unsubscribed()->create(); Subscription::factory()->trialing(now()->addDays(3))->create([ 'organization_id' => $user->current_organization_id, ]); $this->actingAs($user) ->get(route('dashboard')) ->assertOk(); }); test('a user whose subscription lapsed is sent back to pricing', function () { $user = User::factory()->unsubscribed()->create(); Subscription::factory()->create([ 'organization_id' => $user->current_organization_id, 'stripe_status' => 'canceled', 'ends_at' => now()->subDay(), ]); $this->actingAs($user) ->get(route('dashboard')) ->assertRedirect(route('pricing')); }); test('billing settings stay reachable so a lapsed subscriber can resubscribe', function () { $this->actingAs(User::factory()->unsubscribed()->create()) ->get(route('billing.edit')) ->assertOk(); }); test('the other settings pages are not gated', function () { $this->actingAs(User::factory()->unsubscribed()->create()) ->get(route('profile.edit')) ->assertOk(); }); test('losing a subscription closes off the app on the next request', function () { $user = User::factory()->create(); $this->actingAs($user)->get(route('dashboard'))->assertOk(); $organization = $user->currentOrganization()->first(); $organization->forceFill(['lifetime_access' => false])->save(); $organization->subscriptions()->delete(); $this->actingAs($user) ->get(route('dashboard')) ->assertRedirect(route('pricing')); }); test('an organization that is not the current one does not grant access', function () { $user = User::factory()->unsubscribed()->create(); Subscription::factory()->active()->create([ 'organization_id' => Organization::factory()->create()->id, ]); $this->actingAs($user) ->get(route('dashboard')) ->assertRedirect(route('pricing')); });