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); });