added pricing, orgs
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-04 20:34:19 -07:00
parent 999d5ad28d
commit 2ca3860557
52 changed files with 3467 additions and 47 deletions
+36 -1
View File
@@ -1,5 +1,6 @@
<?php
use App\Models\User;
use Laravel\Fortify\Features;
beforeEach(function () {
@@ -18,10 +19,44 @@ test('new users can register', function () {
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'plan' => 'pro',
]);
$response->assertSessionHasNoErrors()
->assertRedirect(route('dashboard', absolute: false));
->assertRedirect(route('pricing', absolute: false));
$this->assertAuthenticated();
});
test('new users are given a personal organization to subscribe with', function () {
$this->post(route('register.store'), [
'name' => 'John Doe',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'plan' => 'pro',
]);
$user = User::where('email', 'test@example.com')->sole();
expect($user->currentOrganization()->first())
->not->toBeNull()
->personal_workspace->toBeTrue()
->lifetime_access->toBeFalse();
});
test('a new user is sent to pricing because they have not subscribed', function () {
$this->post(route('register.store'), [
'name' => 'John Doe',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'plan' => 'pro',
]);
$user = User::where('email', 'test@example.com')->sole();
expect($user->hasActiveSubscription())->toBeFalse();
$this->actingAs($user)->get(route('dashboard'))->assertRedirect(route('pricing'));
});
+12
View File
@@ -22,3 +22,15 @@ test('base data seeding is idempotent', function () {
expect(User::where('email', 'admin@example.com')->count())->toBe(1);
});
test('the seeded admin is grandfathered so a fresh install works', function () {
seed(BaseDatabaseSeeder::class);
$admin = User::where('email', 'admin@example.com')->firstOrFail();
expect($admin->currentOrganization()->first())
->not->toBeNull()
->lifetime_access->toBeTrue();
expect($admin->hasActiveSubscription())->toBeTrue();
});
@@ -0,0 +1,140 @@
<?php
use App\Models\User;
use Laravel\Cashier\Subscription;
use Livewire\Livewire;
test('an unsubscribed user sees why they have no access', function () {
$this->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'));
});
+157
View File
@@ -0,0 +1,157 @@
<?php
use App\Models\Organization;
use App\Models\Setting;
use App\Models\User;
use Laravel\Cashier\Subscription;
use Livewire\Livewire;
test('guests can see the pricing page', function () {
$this->get(route('pricing'))->assertOk();
});
test('a guest is asked to create an account rather than subscribe', function () {
Livewire::test('pages::pricing')
->assertSee(route('register'))
->assertDontSee('subscribe-', false);
});
test('a configured plan is offered with its trial', function () {
$this->actingAs(User::factory()->unsubscribed()->create());
Livewire::test('pages::pricing')
->assertSee('Pro')
->assertOk();
});
test('a plan card shows the advertised price', function () {
Setting::put(Setting::planAmountKey('pro'), '1250');
$this->actingAs(User::factory()->unsubscribed()->create());
Livewire::test('pages::pricing')
->assertOk()
->assertSee('data-test="plan-pro-amount"', escape: false)
->assertSee('$12.50');
});
test('a plan without a price is hidden', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => null, 'interval' => 'month'],
]);
expect(Organization::availablePlans())->toBe([]);
Livewire::test('pages::pricing')
->assertSee('No plans are available');
});
test('available plans fall back to a usable name and interval', function () {
config()->set('plans.plans', [
'mystery' => ['price' => 'price_123'],
]);
expect(Organization::availablePlans())->toBe([
'mystery' => ['name' => 'mystery', 'price' => 'price_123', 'interval' => 'month', 'amount' => 1000],
]);
});
test('an unknown plan is not available', function () {
expect(Organization::isAvailablePlan('pro'))->toBeTrue()
->and(Organization::isAvailablePlan('enterprise'))->toBeFalse();
});
test('an already subscribed user is sent to manage their subscription instead', function () {
$this->actingAs(User::factory()->create());
Livewire::test('pages::pricing')
->assertSee('Manage your subscription')
->assertDontSee('Start 14-day free trial');
});
test('a guest cannot start a subscription', function () {
Livewire::test('pages::pricing')
->call('subscribe', 'pro')
->assertForbidden();
});
test('a plan that is not configured cannot be subscribed to', function () {
$this->actingAs(User::factory()->unsubscribed()->create());
Livewire::test('pages::pricing')
->call('subscribe', 'enterprise')
->assertHasErrors('plan');
});
test('a plan removed from configuration cannot be subscribed to', function () {
$this->actingAs(User::factory()->unsubscribed()->create());
Livewire::test('pages::pricing')->assertOk();
config()->set('plans.plans', []);
Livewire::test('pages::pricing')
->call('subscribe', 'pro')
->assertHasErrors('plan');
});
test('a trial shorter than Stripe allows is treated as no trial', function () {
expect(Organization::trialDays())->toBe(14);
config()->set('plans.trial_days', 1);
expect(Organization::trialDays())->toBe(0);
config()->set('plans.trial_days', 0);
expect(Organization::trialDays())->toBe(0);
});
test('checkout options are shared by every entry point', function () {
expect(Organization::checkoutOptions())
->toHaveKey('success_url', route('subscription.confirmed', ['session_id' => '{CHECKOUT_SESSION_ID}']))
->toHaveKey('cancel_url', route('pricing'))
->toHaveKey('allow_promotion_codes', true);
});
test('the trial length comes from configuration', function () {
config()->set('plans.trial_days', 0);
$this->actingAs(User::factory()->unsubscribed()->create());
Livewire::test('pages::pricing')
->assertSee('Subscribe')
->assertDontSee('free trial');
});
test('the current plan is resolved from the subscription price', function () {
$user = User::factory()->unsubscribed()->create();
$organization = $user->currentOrganization()->first();
Subscription::factory()
->active()
->withPrice('price_test_placeholder')
->create(['organization_id' => $organization->id]);
expect($organization->refresh()->currentPlan())->toBe([
'name' => 'Pro',
'price' => 'price_test_placeholder',
'interval' => 'month',
'amount' => 1000,
]);
});
test('a subscription on an unknown price has no resolvable plan', function () {
$organization = Organization::factory()->create();
Subscription::factory()
->active()
->withPrice('price_legacy')
->create(['organization_id' => $organization->id]);
expect($organization->refresh()->currentPlan())->toBeNull();
});
test('an organization with no subscription has no plan', function () {
expect(Organization::factory()->create()->currentPlan())->toBeNull();
});
+110
View File
@@ -0,0 +1,110 @@
<?php
use App\Models\Organization;
use App\Models\User;
use App\OrganizationRole;
use Laravel\Cashier\Subscription;
test('every new account is given a personal organization that is current', function () {
$user = User::factory()->unsubscribed()->create();
$organization = $user->currentOrganization()->first();
expect($organization)->not->toBeNull()
->and($organization->personal_workspace)->toBeTrue()
->and($organization->lifetime_access)->toBeFalse()
->and($organization->userHasRole($user, OrganizationRole::Owner))->toBeTrue();
});
test('an active subscription entitles the user', function () {
$user = User::factory()->unsubscribed()->create();
expect($user->hasActiveSubscription())->toBeFalse();
Subscription::factory()->active()->create([
'organization_id' => $user->current_organization_id,
]);
expect($user->refresh()->hasActiveSubscription())->toBeTrue();
});
test('a trialing subscription entitles the user', function () {
$user = User::factory()->unsubscribed()->create();
Subscription::factory()->trialing(now()->addDays(7))->create([
'organization_id' => $user->current_organization_id,
]);
expect($user->refresh()->hasActiveSubscription())->toBeTrue();
});
test('a canceled subscription that has not lapsed yet still entitles the user', function () {
$user = User::factory()->unsubscribed()->create();
Subscription::factory()->create([
'organization_id' => $user->current_organization_id,
'stripe_status' => 'canceled',
'ends_at' => now()->addDays(14),
]);
expect($user->refresh()->hasActiveSubscription())->toBeTrue();
});
test('a canceled subscription that has lapsed does not entitle the user', function () {
$user = User::factory()->unsubscribed()->create();
Subscription::factory()->create([
'organization_id' => $user->current_organization_id,
'stripe_status' => 'canceled',
'ends_at' => now()->subDay(),
]);
expect($user->refresh()->hasActiveSubscription())->toBeFalse();
});
test('a past due subscription does not entitle the user', function () {
$user = User::factory()->unsubscribed()->create();
Subscription::factory()->pastDue()->create([
'organization_id' => $user->current_organization_id,
]);
expect($user->refresh()->hasActiveSubscription())->toBeFalse();
});
test('a lifetime organization is entitled without any subscription', function () {
$organization = Organization::factory()->withLifetimeAccess()->create();
expect($organization->isEntitled())->toBeTrue()
->and($organization->hasLifetimeAccess())->toBeTrue();
});
test('an organization without a subscription is not entitled', function () {
$organization = Organization::factory()->create();
expect($organization->isEntitled())->toBeFalse();
});
test('a user without a current organization is never entitled', function () {
$user = User::factory()->unsubscribed()->create();
$user->forceFill(['current_organization_id' => null])->save();
expect($user->refresh()->hasActiveSubscription())->toBeFalse();
});
test('a subscription on another organization does not entitle the user', function () {
$user = User::factory()->unsubscribed()->create();
$other = Organization::factory()->create();
Subscription::factory()->active()->create([
'organization_id' => $other->id,
]);
expect($user->refresh()->hasActiveSubscription())->toBeFalse();
});
test('the factory user is entitled by default and unsubscribed opts out', function () {
expect(User::factory()->create()->hasActiveSubscription())->toBeTrue()
->and(User::factory()->unsubscribed()->create()->hasActiveSubscription())->toBeFalse();
});
+218
View File
@@ -0,0 +1,218 @@
<?php
use App\Models\Organization;
use App\Models\Setting;
use App\Models\User;
use Livewire\Livewire;
test('guests are redirected from the plan pricing page', function () {
$this->get(route('admin.plan-pricing'))
->assertRedirect(route('login'));
});
test('non-admins cannot access the plan pricing page', function () {
$this->actingAs(User::factory()->create());
$this->get(route('admin.plan-pricing'))->assertForbidden();
});
test('non-admins do not see the plan pricing navigation item', function () {
$this->actingAs(User::factory()->create());
$this->get(route('dashboard'))
->assertOk()
->assertDontSee('Plan pricing');
});
test('admins see the plan pricing navigation item', function () {
$this->actingAs(User::factory()->asAdmin()->create());
$this->get(route('dashboard'))
->assertOk()
->assertSee('Plan pricing');
});
test('admins can view the plan pricing page', function () {
$this->actingAs(User::factory()->asAdmin()->create());
$this->get(route('admin.plan-pricing'))->assertOk();
});
test('the plan pricing page shows the current price for each configured plan', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
'team' => ['name' => 'Team', 'price' => 'price_team', 'interval' => 'year'],
]);
Setting::put(Setting::planAmountKey('pro'), '1250');
Setting::put(Setting::planAmountKey('team'), '9900');
$this->actingAs(User::factory()->asAdmin()->create());
Livewire::test('pages::admin.plan-pricing')
->assertOk()
->assertSet('amounts.pro', '12.50')
->assertSet('amounts.team', '99.00');
});
test('the plan price field is pre-filled with the stored price', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
]);
Setting::put(Setting::planAmountKey('pro'), '1250');
$this->actingAs(User::factory()->asAdmin()->create());
// A pre-filled field is what stops an administrator saving a blank price
// over a real one, so the value has to reach the rendered input.
expect(preg_replace('/\s+/', ' ', Livewire::test('pages::admin.plan-pricing')->html()))
->toContain('value="12.50"');
});
test('a plan without a Stripe price is still listed but marked as not on sale', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => null, 'interval' => 'month'],
]);
$this->actingAs(User::factory()->asAdmin()->create());
Livewire::test('pages::admin.plan-pricing')
->assertOk()
->assertSee('This plan is not on sale yet');
});
test('a deployment with no plans configured says so', function () {
config()->set('plans.plans', []);
$this->actingAs(User::factory()->asAdmin()->create());
Livewire::test('pages::admin.plan-pricing')
->assertOk()
->assertSee('No plans are configured');
});
test('an admin can change the advertised price of a plan', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
]);
$this->actingAs(User::factory()->asAdmin()->create());
Livewire::test('pages::admin.plan-pricing')
->set('amounts.pro', '12.50')
->call('saveAmounts')
->assertHasNoErrors();
expect(Setting::get(Setting::planAmountKey('pro')))->toBe('1250')
->and(Organization::planAmount('pro'))->toBe(1250);
});
test('an admin can give a plan away for free', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
]);
$this->actingAs(User::factory()->asAdmin()->create());
Livewire::test('pages::admin.plan-pricing')
->set('amounts.pro', '0')
->call('saveAmounts')
->assertHasNoErrors();
expect(Organization::planAmount('pro'))->toBe(0);
});
test('a price with cents is stored without floating point drift', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
]);
$this->actingAs(User::factory()->asAdmin()->create());
Livewire::test('pages::admin.plan-pricing')
->set('amounts.pro', '0.07')
->call('saveAmounts')
->assertHasNoErrors();
expect(Organization::planAmount('pro'))->toBe(7);
});
test('a negative price is rejected and the stored price is left alone', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
]);
$this->actingAs(User::factory()->asAdmin()->create());
Livewire::test('pages::admin.plan-pricing')
->set('amounts.pro', '-5')
->call('saveAmounts')
->assertHasErrors(['amounts.pro']);
expect(Organization::planAmount('pro'))->toBe(1000);
});
test('a price with more than two decimal places is rejected', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
]);
$this->actingAs(User::factory()->asAdmin()->create());
Livewire::test('pages::admin.plan-pricing')
->set('amounts.pro', '1.234')
->call('saveAmounts')
->assertHasErrors(['amounts.pro']);
});
test('an emptied price is rejected rather than stored as a free plan', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
]);
$this->actingAs(User::factory()->asAdmin()->create());
Livewire::test('pages::admin.plan-pricing')
->set('amounts.pro', '')
->call('saveAmounts')
->assertHasErrors(['amounts.pro']);
expect(Organization::planAmount('pro'))->toBe(1000);
});
test('a stored price that is not a number falls back to the default', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
]);
Setting::put(Setting::planAmountKey('pro'), 'free');
expect(Organization::planAmount('pro'))->toBe(1000);
});
test('a plan with no stored price falls back to the default', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
'team' => ['name' => 'Team', 'price' => 'price_team', 'interval' => 'year'],
]);
Setting::put(Setting::planAmountKey('pro'), '2500');
expect(Organization::planAmount('pro'))->toBe(2500)
->and(Organization::planAmount('team'))->toBe(1000);
});
test('the amount is formatted in the configured currency', function () {
expect(Organization::formatAmount(1250))->toBe('$12.50');
config()->set('cashier.currency', 'eur');
expect(Organization::formatAmount(1250))->toContain('12.50');
});
test('an unrecognised currency falls back to a plain number rather than a blank price', function () {
config()->set('cashier.currency', 'x');
expect(Organization::formatAmount(1250))->toBe('12.50');
});
@@ -0,0 +1,211 @@
<?php
use App\Models\Organization;
use App\Models\Setting;
use App\Models\User;
use Laravel\Fortify\Features;
beforeEach(function () {
$this->skipUnlessFortifyHas(Features::registration());
});
/**
* Get the response body with runs of whitespace collapsed to single spaces, so
* that assertions about attributes do not depend on Blade's indentation.
*/
function normalizedHtml($response): string
{
return preg_replace('/\s+/', ' ', $response->getContent());
}
test('the signup form offers a plan picker', function () {
$this->get(route('register'))
->assertOk()
->assertSee('Choose your plan')
->assertSee('value="pro"', escape: false)
->assertSee('Free for 14 days, then billed every month')
->assertSee('Continue to payment');
});
test('the signup plan box shows the advertised price', function () {
$this->get(route('register'))
->assertOk()
->assertSee('data-test="register-plan-pro-amount"', escape: false)
->assertSee('$10.00');
});
test('the signup plan box shows a price changed by an administrator', function () {
Setting::put(Setting::planAmountKey('pro'), '1250');
$this->get(route('register'))
->assertOk()
->assertSee('$12.50')
->assertDontSee('$10.00');
});
test('each plan box shows its own price', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
'team' => ['name' => 'Team', 'price' => 'price_team', 'interval' => 'year'],
]);
Setting::put(Setting::planAmountKey('pro'), '1250');
Setting::put(Setting::planAmountKey('team'), '9900');
$this->get(route('register'))
->assertOk()
->assertSee('$12.50')
->assertSee('$99.00');
});
test('the first plan is preselected', function () {
expect(normalizedHtml($this->get(route('register'))))
->toContain('value="pro" checked');
});
test('every configured plan gets an option', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
'team' => ['name' => 'Team', 'price' => 'price_team', 'interval' => 'year'],
]);
$this->get(route('register'))
->assertSee('data-test="register-plan-pro"', escape: false)
->assertSee('data-test="register-plan-team"', escape: false)
->assertSee('billed every year');
});
test('a plan is required when plans are configured', function () {
$this->post(route('register.store'), [
'name' => 'John Doe',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
])->assertSessionHasErrors('plan');
expect(User::where('email', 'test@example.com')->exists())->toBeFalse();
});
test('an unknown plan is rejected and no account is created', function () {
$this->post(route('register.store'), [
'name' => 'John Doe',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'plan' => 'enterprise',
])->assertSessionHasErrors('plan');
expect(User::where('email', 'test@example.com')->exists())->toBeFalse();
});
test('signing up with a plan creates the account and its organization', function () {
$this->post(route('register.store'), [
'name' => 'John Doe',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'plan' => 'pro',
])->assertSessionHasNoErrors();
$user = User::where('email', 'test@example.com')->sole();
expect($user->currentOrganization()->first())->not->toBeNull()
->personal_workspace->toBeTrue();
expect($user->hasActiveSubscription())->toBeFalse();
});
test('a Stripe failure does not turn a completed signup into an error page', function () {
// Checkout calls Stripe, which is not reachable from the test suite, so
// this exercises the fallback: the account survives and the user is sent
// somewhere they can retry rather than shown a 500.
$response = $this->post(route('register.store'), [
'name' => 'John Doe',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'plan' => 'pro',
]);
$response->assertRedirect(route('pricing'));
$response->assertSessionHas('billing.checkout_failed');
$this->assertAuthenticated();
expect(User::where('email', 'test@example.com')->exists())->toBeTrue();
});
test('the fallback message is shown on the pricing page', function () {
$this->post(route('register.store'), [
'name' => 'John Doe',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'plan' => 'pro',
]);
$this->get(route('pricing'))
->assertOk()
->assertSee('we could not start checkout');
});
test('signing up without a plan configured still works', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => null, 'interval' => 'month'],
]);
$this->get(route('register'))
->assertOk()
->assertDontSee('Choose your plan')
->assertSee('Create account');
$this->post(route('register.store'), [
'name' => 'John Doe',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
])
->assertSessionHasNoErrors()
->assertRedirect(route('dashboard', absolute: false));
$this->assertAuthenticated();
});
test('the chosen plan is remembered when validation fails', function () {
config()->set('plans.plans', [
'pro' => ['name' => 'Pro', 'price' => 'price_pro', 'interval' => 'month'],
'team' => ['name' => 'Team', 'price' => 'price_team', 'interval' => 'year'],
]);
$this->post(route('register.store'), [
'name' => 'John Doe',
'email' => 'not-an-email',
'password' => 'password',
'password_confirmation' => 'password',
'plan' => 'team',
])->assertSessionHasErrors('email');
expect(normalizedHtml($this->get(route('register'))))
->toContain('value="team" checked');
});
test('a json registration is unaffected by the plan picker', function () {
config()->set('plans.plans', []);
$this->postJson(route('register.store'), [
'name' => 'John Doe',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
])->assertCreated();
});
test('the trial is not offered when it is shorter than Stripe allows', function () {
config()->set('plans.trial_days', 1);
$this->get(route('register'))
->assertOk()
->assertSee('Billed every month')
->assertDontSee('Free for 1 days');
expect(Organization::trialDays())->toBe(0);
});
@@ -0,0 +1,105 @@
<?php
use App\Models\Organization;
use App\Models\User;
use Laravel\Cashier\Subscription;
test('guests are sent to login', function () {
$this->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'));
});
+51
View File
@@ -607,6 +607,57 @@ test('dragging accounts for the pagination offset', function () {
expect($todoTwelve->fresh()->position)->toBe(10);
});
test('the table re-renders in the new order after a drag', function () {
$user = User::factory()->create();
$this->actingAs($user);
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
$second = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
$third = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Third todo', 'position' => 2]);
Livewire::test('pages::dashboard')
->assertSeeInOrder(['First todo', 'Second todo', 'Third todo'])
->call('handleSort', $first->id, 2)
->assertSeeInOrder(['Second todo', 'Third todo', 'First todo']);
});
test('the table re-renders in the new order after moving a todo', function () {
$user = User::factory()->create();
$this->actingAs($user);
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
$first = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
Livewire::test('pages::dashboard')
->assertSeeInOrder(['First todo', 'Second todo'])
->call('moveTodo', $first->id, 'down')
->assertSeeInOrder(['Second todo', 'First todo']);
});
test('reordering while filtered keeps the order of the todos the filter hides', function () {
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
$home = Folder::factory()->for($user)->create(['name' => 'Home']);
Todo::factory()->recycle($user)->for($home)->create(['description' => 'Home one', 'position' => 0]);
Todo::factory()->recycle($user)->for($home)->create(['description' => 'Home two', 'position' => 1]);
$workOne = Todo::factory()->recycle($user)->for($work)->create(['description' => 'Work one', 'position' => 2]);
Todo::factory()->recycle($user)->for($work)->create(['description' => 'Work two', 'position' => 3]);
Livewire::test('pages::dashboard')
->set('folderId', $work->id)
->call('handleSort', $workOne->id, 1);
Livewire::test('pages::dashboard')
->assertSeeInOrder(['Home one', 'Home two', 'Work two', 'Work one']);
});
test('completed todos sort last regardless of their position', function () {
$user = User::factory()->create();
$this->actingAs($user);
+37
View File
@@ -202,6 +202,43 @@ test('users can move a todo up in the priority order', function () {
expect($third->fresh()->position)->toBe(1);
});
test('the reorder arrows reflect the new order after a move', function () {
$user = User::factory()->create();
$this->actingAs($user);
$folder = Folder::factory()->for($user)->create(['name' => 'Work']);
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'First todo', 'position' => 0]);
Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Second todo', 'position' => 1]);
$third = Todo::factory()->recycle($user)->for($folder)->create(['description' => 'Third todo', 'position' => 2]);
// The last todo cannot move down until it has been moved up.
Livewire::test('pages::todos')
->assertDontSee('move-todo-down-'.$third->id)
->call('moveTodo', $third->id, 'up')
->assertSee('move-todo-down-'.$third->id);
});
test('reordering while filtered keeps the order of the todos the filter hides', function () {
$user = User::factory()->create();
$this->actingAs($user);
$work = Folder::factory()->for($user)->create(['name' => 'Work']);
$home = Folder::factory()->for($user)->create(['name' => 'Home']);
Todo::factory()->recycle($user)->for($home)->create(['description' => 'Home one', 'position' => 0]);
Todo::factory()->recycle($user)->for($home)->create(['description' => 'Home two', 'position' => 1]);
$workOne = Todo::factory()->recycle($user)->for($work)->create(['description' => 'Work one', 'position' => 2]);
Todo::factory()->recycle($user)->for($work)->create(['description' => 'Work two', 'position' => 3]);
Livewire::test('pages::todos')
->set('folderId', $work->id)
->call('handleSort', $workOne->id, 1);
Livewire::test('pages::todos')
->assertSeeInOrder(['Home one', 'Home two', 'Work two', 'Work one']);
});
test('users can delete a todo', function () {
$user = User::factory()->create();
$this->actingAs($user);