Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/SignupTest.php
<?php | <?php | ||||
namespace Tests\Browser; | namespace Tests\Browser; | ||||
use App\Discount; | use App\Discount; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Plan; | use App\Plan; | ||||
use App\SignupCode; | use App\SignupCode; | ||||
use App\SignupInvitation; | use App\SignupInvitation; | ||||
use App\User; | use App\User; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\Menu; | use Tests\Browser\Components\Menu; | ||||
use Tests\Browser\Components\Toast; | use Tests\Browser\Components\Toast; | ||||
use Tests\Browser\Pages\Dashboard; | use Tests\Browser\Pages\Dashboard; | ||||
use Tests\Browser\Pages\Home; | use Tests\Browser\Pages\Home; | ||||
use Tests\Browser\Pages\PaymentMollie; | |||||
use Tests\Browser\Pages\PaymentStatus; | |||||
use Tests\Browser\Pages\Signup; | use Tests\Browser\Pages\Signup; | ||||
use Tests\Browser\Pages\Wallet; | |||||
use Tests\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | use Illuminate\Foundation\Testing\DatabaseMigrations; | ||||
class SignupTest extends TestCaseDusk | class SignupTest extends TestCaseDusk | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->deleteTestUser('signuptestdusk@' . \config('app.domain')); | $this->deleteTestUser('signuptestdusk@' . \config('app.domain')); | ||||
$this->deleteTestUser('admin@user-domain-signup.com'); | $this->deleteTestUser('admin@user-domain-signup.com'); | ||||
$this->deleteTestDomain('user-domain-signup.com'); | $this->deleteTestDomain('user-domain-signup.com'); | ||||
Plan::whereIn('mode', ['token', 'mandate'])->update(['mode' => 'email']); | Plan::whereNot('mode', Plan::MODE_EMAIL)->update(['mode' => Plan::MODE_EMAIL]); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('signuptestdusk@' . \config('app.domain')); | $this->deleteTestUser('signuptestdusk@' . \config('app.domain')); | ||||
$this->deleteTestUser('admin@user-domain-signup.com'); | $this->deleteTestUser('admin@user-domain-signup.com'); | ||||
$this->deleteTestDomain('user-domain-signup.com'); | $this->deleteTestDomain('user-domain-signup.com'); | ||||
SignupInvitation::truncate(); | SignupInvitation::truncate(); | ||||
Plan::whereIn('mode', ['token', 'mandate'])->update(['mode' => 'email']); | Plan::whereNot('mode', Plan::MODE_EMAIL)->update(['mode' => Plan::MODE_EMAIL]); | ||||
@unlink(storage_path('signup-tokens.txt')); | @unlink(storage_path('signup-tokens.txt')); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test signup code verification with a link | * Test signup code verification with a link | ||||
▲ Show 20 Lines • Show All 460 Lines • ▼ Show 20 Lines | public function testSignupGroup(): void | ||||
$browser->within(new Menu(), function ($browser) { | $browser->within(new Menu(), function ($browser) { | ||||
$browser->clickMenuItem('logout'); | $browser->clickMenuItem('logout'); | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test signup with a mandate plan, also the wallet lock | * Test signup with a mandate plan, also the UI lock | ||||
* | |||||
* @group mollie | |||||
*/ | */ | ||||
public function testSignupMandate(): void | public function testSignupMandate(): void | ||||
{ | { | ||||
// Test the individual plan | // Test the individual plan | ||||
$plan = Plan::withEnvTenantContext()->where('title', 'individual')->first(); | $plan = Plan::withEnvTenantContext()->where('title', 'individual')->first(); | ||||
$plan->mode = 'mandate'; | $plan->mode = Plan::MODE_MANDATE; | ||||
$plan->save(); | $plan->save(); | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$config = ['paymentProvider' => 'mollie']; | |||||
$browser->visit(new Signup()) | $browser->visit(new Signup()) | ||||
// Force Mollie | |||||
->execScript(sprintf('Object.assign(window.config, %s)', \json_encode($config))) | |||||
->waitFor('@step0 .plan-individual button') | ->waitFor('@step0 .plan-individual button') | ||||
->click('@step0 .plan-individual button') | ->click('@step0 .plan-individual button') | ||||
// Test Back button | // Test Back button | ||||
->whenAvailable('@step3', function ($browser) { | ->whenAvailable('@step3', function ($browser) { | ||||
$browser->click('button[type=button]'); | $browser->click('button[type=button]'); | ||||
}) | }) | ||||
->whenAvailable('@step0', function ($browser) { | ->whenAvailable('@step0', function ($browser) { | ||||
$browser->click('.plan-individual button'); | $browser->click('.plan-individual button'); | ||||
}) | }) | ||||
// Test submit | // Test submit | ||||
->whenAvailable('@step3', function ($browser) { | ->whenAvailable('@step3', function ($browser) { | ||||
$domains = Domain::getPublicDomains(); | $domains = Domain::getPublicDomains(); | ||||
$domains_count = count($domains); | $domains_count = count($domains); | ||||
$browser->assertMissing('.card-title') | $browser->assertMissing('.card-title') | ||||
->assertElementsCount('select#signup_domain option', $domains_count, false) | ->assertElementsCount('select#signup_domain option', $domains_count, false) | ||||
->assertText('select#signup_domain option:nth-child(1)', $domains[0]) | ->assertText('select#signup_domain option:nth-child(1)', $domains[0]) | ||||
->assertValue('select#signup_domain option:nth-child(1)', $domains[0]) | ->assertValue('select#signup_domain option:nth-child(1)', $domains[0]) | ||||
->type('#signup_login', 'signuptestdusk') | ->type('#signup_login', 'signuptestdusk') | ||||
->type('#signup_password', '12345678') | ->type('#signup_password', '12345678') | ||||
->type('#signup_password_confirmation', '12345678') | ->type('#signup_password_confirmation', '12345678') | ||||
->click('[type=submit]'); | ->click('[type=submit]'); | ||||
}) | }) | ||||
->waitUntilMissing('@step3') | ->whenAvailable('@step4', function ($browser) { | ||||
->on(new Wallet()) | $browser->assertSeeIn('.card-text', 'The account is about to be created!') | ||||
->assertSeeIn('#lock-alert', "The account is locked") | ->assertSeeIn('.card-text', 'You signed up for an account') | ||||
->within(new Menu(), function ($browser) { | ->assertSeeIn('button.btn-primary', 'Continue') | ||||
$browser->clickMenuItem('logout'); | ->assertSeeIn('button.btn-secondary', 'Back') | ||||
}); | ->click('button.btn-secondary'); | ||||
}) | |||||
->whenAvailable('@step3', function ($browser) { | |||||
$browser->assertValue('#signup_login', 'signuptestdusk') | |||||
->click('[type=submit]'); | |||||
}) | |||||
->whenAvailable('@step4', function ($browser) { | |||||
$browser->click('button.btn-primary'); | |||||
}) | |||||
->on(new PaymentMollie()) | |||||
->assertSeeIn('@title', 'Auto-Payment Setup') | |||||
->assertMissing('@amount') | |||||
->submitPayment('open') | |||||
->on(new PaymentStatus()) | |||||
->assertSeeIn('@lock-alert', 'The account is locked') | |||||
->assertSeeIn('@content', 'Checking the status...') | |||||
->assertSeeIn('@button', 'Try again'); | |||||
}); | }); | ||||
$user = User::where('email', 'signuptestdusk@' . \config('app.domain'))->first(); | $user = User::where('email', 'signuptestdusk@' . \config('app.domain'))->first(); | ||||
$this->assertSame($plan->id, $user->getSetting('plan_id')); | $this->assertSame($plan->id, $user->getSetting('plan_id')); | ||||
$this->assertFalse($user->isActive()); | |||||
// Login again and see that the account is still locked | // Refresh and see that the account is still locked | ||||
$this->browse(function (Browser $browser) use ($user) { | $this->browse(function (Browser $browser) use ($user) { | ||||
$browser->on(new Home()) | $browser->visit('/dashboard') | ||||
->submitLogon($user->email, '12345678', false) | ->on(new PaymentStatus()) | ||||
->waitForLocation('/wallet') | ->assertSeeIn('@lock-alert', 'The account is locked') | ||||
->on(new Wallet()) | ->assertSeeIn('@content', 'Checking the status...'); | ||||
->assertSeeIn('#lock-alert', "The account is locked") | |||||
// Mark the payment paid, and activate the user in background, | |||||
// expect unlock and redirect to the dashboard | |||||
// TODO: Move this to a separate tests file for PaymentStatus page | |||||
$payment = $user->wallets()->first()->payments()->first(); | |||||
$payment->credit('Test'); | |||||
$payment->status = \App\Payment::STATUS_PAID; | |||||
$payment->save(); | |||||
$this->assertTrue($user->fresh()->isActive()); | |||||
$browser->waitForLocation('/dashboard', 10) | |||||
->within(new Menu(), function ($browser) { | ->within(new Menu(), function ($browser) { | ||||
$browser->clickMenuItem('logout'); | $browser->clickMenuItem('logout'); | ||||
}); | }); | ||||
// TODO: Test automatic UI unlock after creating a valid auto-payment mandate | |||||
}); | }); | ||||
// TODO: Test the 'Try again' button on /payment/status page | |||||
} | } | ||||
/** | /** | ||||
* Test signup with a token plan | * Test signup with a token plan | ||||
*/ | */ | ||||
public function testSignupToken(): void | public function testSignupToken(): void | ||||
{ | { | ||||
// Test the individual plan | // Test the individual plan | ||||
Plan::where('title', 'individual')->update(['mode' => 'token']); | Plan::where('title', 'individual')->update(['mode' => Plan::MODE_TOKEN]); | ||||
// Register some valid tokens | // Register some valid tokens | ||||
$tokens = ['1234567890', 'abcdefghijk']; | $tokens = ['1234567890', 'abcdefghijk']; | ||||
file_put_contents(storage_path('signup-tokens.txt'), implode("\n", $tokens)); | file_put_contents(storage_path('signup-tokens.txt'), implode("\n", $tokens)); | ||||
$this->browse(function (Browser $browser) use ($tokens) { | $this->browse(function (Browser $browser) use ($tokens) { | ||||
$browser->visit(new Signup()) | $browser->visit(new Signup()) | ||||
->waitFor('@step0 .plan-individual button') | ->waitFor('@step0 .plan-individual button') | ||||
Show All 36 Lines | public function testSignupToken(): void | ||||
}); | }); | ||||
}); | }); | ||||
$user = User::where('email', 'signuptestdusk@' . \config('app.domain'))->first(); | $user = User::where('email', 'signuptestdusk@' . \config('app.domain'))->first(); | ||||
$this->assertSame($tokens[0], $user->getSetting('signup_token')); | $this->assertSame($tokens[0], $user->getSetting('signup_token')); | ||||
$this->assertSame(null, $user->getSetting('external_email')); | $this->assertSame(null, $user->getSetting('external_email')); | ||||
// Test the group plan | // Test the group plan | ||||
Plan::where('title', 'group')->update(['mode' => 'token']); | Plan::where('title', 'group')->update(['mode' => Plan::MODE_TOKEN]); | ||||
$this->browse(function (Browser $browser) use ($tokens) { | $this->browse(function (Browser $browser) use ($tokens) { | ||||
$browser->visit(new Signup()) | $browser->visit(new Signup()) | ||||
->waitFor('@step0 .plan-group button') | ->waitFor('@step0 .plan-group button') | ||||
->click('@step0 .plan-group button') | ->click('@step0 .plan-group button') | ||||
// Step 1 | // Step 1 | ||||
->whenAvailable('@step1', function ($browser) use ($tokens) { | ->whenAvailable('@step1', function ($browser) use ($tokens) { | ||||
$browser->assertSeeIn('.card-title', 'Sign Up - Step 1/2') | $browser->assertSeeIn('.card-title', 'Sign Up - Step 1/2') | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |