actingAs(User::factory()->unsubscribed()->create()); Livewire::test('pages::settings.billing') ->assertSee('Free') ->assertSee('No subscription') ->assertSee('Subscribe') ->assertOk(); }); test('a subscribed user sees their plan and status', function () { $user = User::factory()->create(); $user->currentOrganization()->first()->subscriptions()->delete(); Subscription::factory() ->active() ->withPrice('price_test_placeholder') ->create(['organization_id' => $user->current_organization_id]); $this->actingAs($user); Livewire::test('pages::settings.billing') ->assertSee('Pro') ->assertSee('Active') ->assertDontSee('Subscribe'); }); test('a trialing user is told when the trial ends', function () { $user = User::factory()->unsubscribed()->create(); Subscription::factory() ->trialing(now()->addDays(5)) ->create(['organization_id' => $user->current_organization_id]); $this->actingAs($user); Livewire::test('pages::settings.billing') ->assertSee('Free trial') ->assertSee('Your free trial ends on'); }); test('a subscription that is set to cancel explains the access window', function () { $user = User::factory()->unsubscribed()->create(); Subscription::factory()->create([ 'organization_id' => $user->current_organization_id, 'stripe_status' => 'canceled', 'ends_at' => now()->addDays(10), ]); $this->actingAs($user); Livewire::test('pages::settings.billing') ->assertSee('Canceled') ->assertSee('Your plan stays active until'); }); test('a grandfathered user is told they never need to subscribe', function () { $user = User::factory()->unsubscribed()->create(); $user->currentOrganization()->first()->forceFill(['lifetime_access' => true])->save(); $this->actingAs($user); Livewire::test('pages::settings.billing') ->assertSee('Lifetime access') ->assertDontSee('Subscribe'); }); test('the payment method button appears once the organization is a Stripe customer', function () { $user = User::factory()->create(); $this->actingAs($user); Livewire::test('pages::settings.billing')->assertDontSee('Manage payment method'); $user->currentOrganization()->first()->forceFill(['stripe_id' => 'cus_123'])->save(); Livewire::test('pages::settings.billing')->assertSee('Manage payment method'); }); test('the payment method button posts to the billing portal', function () { $user = User::factory()->create(); $user->currentOrganization()->first()->forceFill(['stripe_id' => 'cus_123'])->save(); $this->actingAs($user) ->get(route('billing.edit')) ->assertSee('action="'.route('billing.portal').'"', escape: false); }); test('the billing portal falls back to billing settings without a Stripe customer', function () { $this->actingAs(User::factory()->unsubscribed()->create()) ->post(route('billing.portal')) ->assertRedirect(route('billing.edit')); }); test('a guest cannot reach the billing portal', function () { $this->post(route('billing.portal'))->assertRedirect(route('login')); }); test('billing is listed in the settings navigation', function () { $this->actingAs(User::factory()->create()) ->get(route('billing.edit')) ->assertSee('data-test="billing-nav-link"', escape: false); }); test('the confirmation page waits for the subscription to arrive', function () { $this->actingAs(User::factory()->unsubscribed()->create()); Livewire::test('pages::subscription-confirmed') ->assertSee('Confirming your subscription') ->set('waitedSeconds', 29) ->call('confirm') ->assertSee('Still confirming your payment'); }); test('the confirmation page moves on once the subscription lands', function () { $user = User::factory()->unsubscribed()->create(); $this->actingAs($user); Livewire::test('pages::subscription-confirmed') ->set('waitedSeconds', 29) ->call('confirm') ->assertSee('Still confirming your payment'); Subscription::factory()->active()->create([ 'organization_id' => $user->current_organization_id, ]); Livewire::test('pages::subscription-confirmed') ->assertSee('Your subscription is active') ->call('confirm') ->assertRedirect(route('dashboard')); });