Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/PaymentStripeTest.php
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | public function testPayment(): void | ||||
->submitLogon('payment-test@kolabnow.com', 'simple123', true, ['paymentProvider' => 'stripe']) | ->submitLogon('payment-test@kolabnow.com', 'simple123', true, ['paymentProvider' => 'stripe']) | ||||
->on(new Dashboard()) | ->on(new Dashboard()) | ||||
->click('@links .link-wallet') | ->click('@links .link-wallet') | ||||
->on(new WalletPage()) | ->on(new WalletPage()) | ||||
->assertSeeIn('@main button', 'Add credit') | ->assertSeeIn('@main button', 'Add credit') | ||||
->click('@main button') | ->click('@main button') | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ||||
$browser->assertSeeIn('@title', 'Top up your wallet') | $browser->assertSeeIn('@title', 'Top up your wallet') | ||||
->waitFor('#payment-method-selection #creditcard') | |||||
->waitFor('#payment-method-selection #paypal') | |||||
->assertMissing('#payment-method-selection #banktransfer') | |||||
->click('#creditcard'); | |||||
}) | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->assertSeeIn('@title', 'Top up your wallet') | |||||
->assertFocused('#amount') | ->assertFocused('#amount') | ||||
->assertSeeIn('@button-cancel', 'Cancel') | ->assertSeeIn('@button-cancel', 'Cancel') | ||||
->assertSeeIn('@body #payment-form button', 'Continue') | ->assertSeeIn('@button-action', 'Continue') | ||||
// Test error handling | // Test error handling | ||||
->type('@body #amount', 'aaa') | ->type('@body #amount', 'aaa') | ||||
->click('@body #payment-form button') | ->click('@button-action') | ||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ||||
->assertSeeIn('#amount + span + .invalid-feedback', 'The amount must be a number.') | ->assertSeeIn('#amount + span + .invalid-feedback', 'The amount must be a number.') | ||||
// Submit valid data | // Submit valid data | ||||
->type('@body #amount', '12.34') | ->type('@body #amount', '12.34') | ||||
->click('@body #payment-form button'); | // Note we use double click to assert it does not create redundant requests | ||||
->click('@button-action') | |||||
->click('@button-action'); | |||||
}) | }) | ||||
->on(new PaymentStripe()) | ->on(new PaymentStripe()) | ||||
->assertSeeIn('@title', \config('app.name') . ' Payment') | ->assertSeeIn('@title', \config('app.name') . ' Payment') | ||||
->assertSeeIn('@amount', 'CHF 12.34') | ->assertSeeIn('@amount', 'CHF 12.34') | ||||
->assertValue('@email-input', $user->email) | ->assertValue('@email-input', $user->email) | ||||
->submitValidCreditCard(); | ->submitValidCreditCard(); | ||||
// Now it should redirect back to wallet page and in background | // Now it should redirect back to wallet page and in background | ||||
Show All 21 Lines | public function testAutoPaymentSetup(): void | ||||
// Test creating auto-payment | // Test creating auto-payment | ||||
$this->browse(function (Browser $browser) use ($user) { | $this->browse(function (Browser $browser) use ($user) { | ||||
$browser->visit(new Home()) | $browser->visit(new Home()) | ||||
->submitLogon('payment-test@kolabnow.com', 'simple123', true, ['paymentProvider' => 'stripe']) | ->submitLogon('payment-test@kolabnow.com', 'simple123', true, ['paymentProvider' => 'stripe']) | ||||
->on(new Dashboard()) | ->on(new Dashboard()) | ||||
->click('@links .link-wallet') | ->click('@links .link-wallet') | ||||
->on(new WalletPage()) | ->on(new WalletPage()) | ||||
->click('@main button') | ->assertMissing('@body #mandate-form .alert') | ||||
->click('@main #mandate-form button') | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ||||
$browser->assertSeeIn('@title', 'Top up your wallet') | $browser->assertSeeIn('@title', 'Add auto-payment') | ||||
->assertSeeIn('@button-cancel', 'Cancel') | ->waitFor('#payment-method-selection #creditcard') | ||||
->assertSeeIn('@body #mandate-form button', 'Set up auto-payment') | ->assertMissing('#payment-method-selection #paypal') | ||||
->click('@body #mandate-form button') | ->assertMissing('#payment-method-selection #banktransfer') | ||||
->assertSeeIn('@title', 'Add auto-payment') | ->click('#creditcard'); | ||||
}) | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->assertSeeIn('@title', 'Add auto-payment') | |||||
->assertSeeIn('@body label[for="mandate_amount"]', 'Fill up by') | ->assertSeeIn('@body label[for="mandate_amount"]', 'Fill up by') | ||||
->assertValue('@body #mandate_amount', PaymentProvider::MIN_AMOUNT / 100) | ->assertValue('@body #mandate_amount', PaymentProvider::MIN_AMOUNT / 100) | ||||
->assertSeeIn('@body label[for="mandate_balance"]', 'when account balance is below') // phpcs:ignore | ->assertSeeIn('@body label[for="mandate_balance"]', 'when account balance is below') // phpcs:ignore | ||||
->assertValue('@body #mandate_balance', '0') | ->assertValue('@body #mandate_balance', '0') | ||||
->assertSeeIn('@button-cancel', 'Cancel') | ->assertSeeIn('@button-cancel', 'Cancel') | ||||
->assertSeeIn('@button-action', 'Continue') | ->assertSeeIn('@button-action', 'Continue') | ||||
// Test error handling | // Test error handling | ||||
->type('@body #mandate_amount', 'aaa') | ->type('@body #mandate_amount', 'aaa') | ||||
Show All 10 Lines | public function testAutoPaymentSetup(): void | ||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ||||
->assertVisible('@body #mandate_amount.is-invalid') | ->assertVisible('@body #mandate_amount.is-invalid') | ||||
->assertMissing('@body #mandate_balance.is-invalid') | ->assertMissing('@body #mandate_balance.is-invalid') | ||||
->assertSeeIn('#mandate_amount + span + .invalid-feedback', 'The amount must be a number.') | ->assertSeeIn('#mandate_amount + span + .invalid-feedback', 'The amount must be a number.') | ||||
->assertMissing('#mandate_balance + span + .invalid-feedback') | ->assertMissing('#mandate_balance + span + .invalid-feedback') | ||||
// Submit valid data | // Submit valid data | ||||
->type('@body #mandate_amount', '100') | ->type('@body #mandate_amount', '100') | ||||
->type('@body #mandate_balance', '0') | ->type('@body #mandate_balance', '0') | ||||
// Note we use double click to assert it does not create redundant requests | |||||
->click('@button-action') | |||||
->click('@button-action'); | ->click('@button-action'); | ||||
}) | }) | ||||
->on(new PaymentStripe()) | ->on(new PaymentStripe()) | ||||
->assertMissing('@title') | ->assertMissing('@title') | ||||
->assertMissing('@amount') | ->assertMissing('@amount') | ||||
->assertValue('@email-input', $user->email) | ->assertValue('@email-input', $user->email) | ||||
->submitValidCreditCard() | ->submitValidCreditCard() | ||||
->waitForLocation('/wallet', 30) // need more time than default 5 sec. | ->waitForLocation('/wallet', 30) // need more time than default 5 sec. | ||||
->visit('/wallet?paymentProvider=stripe') | ->visit('/wallet?paymentProvider=stripe') | ||||
->on(new WalletPage()) | |||||
->click('@main button') | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$expected = 'Auto-payment is set to fill up your account by 100 CHF every' | |||||
. ' time your account balance gets under 0 CHF. You will be charged' | |||||
. ' via Visa (**** **** **** 4242).'; | |||||
$browser->assertSeeIn('@title', 'Top up your wallet') | |||||
->waitFor('#mandate-info') | ->waitFor('#mandate-info') | ||||
->assertSeeIn('#mandate-info p:first-child', $expected) | ->assertPresent('#mandate-info p:first-child') | ||||
->click('@button-cancel'); | ->assertSeeIn( | ||||
}); | '#mandate-info p:first-child', | ||||
'Auto-payment is set to fill up your account by 100 CHF ' . | |||||
'every time your account balance gets under 0 CHF.' | |||||
) | |||||
->assertSeeIn( | |||||
'#mandate-info p:nth-child(2)', | |||||
'Visa (**** **** **** 4242)' | |||||
) | |||||
->assertMissing('@body .alert'); | |||||
}); | }); | ||||
// Test updating auto-payment | |||||
$this->browse(function (Browser $browser) { | // Test updating (disabled) auto-payment | ||||
$browser->on(new WalletPage()) | $this->browse(function (Browser $browser) use ($user) { | ||||
->click('@main button') | $wallet = $user->wallets()->first(); | ||||
$wallet->setSetting('mandate_disabled', 1); | |||||
$browser->refresh() | |||||
->on(new WalletPage()) | |||||
->waitFor('#mandate-info') | |||||
->assertSeeIn( | |||||
'#mandate-info .disabled-mandate', | |||||
'The configured auto-payment has been disabled' | |||||
) | |||||
->assertSeeIn('#mandate-info button.btn-primary', 'Change auto-payment') | |||||
->click('#mandate-info button.btn-primary') | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ||||
$browser->assertSeeIn('@body #mandate-info button.btn-primary', 'Change auto-payment') | $browser->assertSeeIn('@title', 'Update auto-payment') | ||||
->click('@body #mandate-info button.btn-primary') | ->assertSeeIn( | ||||
->assertSeeIn('@title', 'Update auto-payment') | '@body form .disabled-mandate', | ||||
'The auto-payment is disabled.' | |||||
) | |||||
->assertValue('@body #mandate_amount', '100') | ->assertValue('@body #mandate_amount', '100') | ||||
->assertValue('@body #mandate_balance', '0') | ->assertValue('@body #mandate_balance', '0') | ||||
->assertSeeIn('@button-cancel', 'Cancel') | ->assertSeeIn('@button-cancel', 'Cancel') | ||||
->assertSeeIn('@button-action', 'Submit') | ->assertSeeIn('@button-action', 'Submit') | ||||
// Test error handling | // Test error handling | ||||
->type('@body #mandate_amount', 'aaa') | ->type('@body #mandate_amount', 'aaa') | ||||
->click('@button-action') | ->click('@button-action') | ||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ||||
->assertVisible('@body #mandate_amount.is-invalid') | ->assertVisible('@body #mandate_amount.is-invalid') | ||||
->assertSeeIn('#mandate_amount + span + .invalid-feedback', 'The amount must be a number.') | ->assertSeeIn('#mandate_amount + span + .invalid-feedback', 'The amount must be a number.') | ||||
// Submit valid data | // Submit valid data | ||||
->type('@body #mandate_amount', '50') | ->type('@body #mandate_amount', '50') | ||||
->click('@button-action'); | ->click('@button-action'); | ||||
}) | }) | ||||
->waitUntilMissing('#payment-dialog') | ->waitUntilMissing('#payment-dialog') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been updated.'); | ->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been updated.') | ||||
// make sure the "disabled" text isn't there | |||||
->assertMissing('#mandate-info .disabled-mandate') | |||||
->click('#mandate-info button.btn-primary') | |||||
->assertMissing('form .disabled-mandate') | |||||
->click('button.modal-cancel'); | |||||
}); | }); | ||||
// Test deleting auto-payment | // Test deleting auto-payment | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->on(new WalletPage()) | $browser->on(new WalletPage()) | ||||
->click('@main button') | ->waitFor('#mandate-info') | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ->assertSeeIn('#mandate-info * button.btn-danger', 'Cancel auto-payment') | ||||
$browser->assertSeeIn('@body #mandate-info button.btn-danger', 'Cancel auto-payment') | ->assertVisible('#mandate-info * button.btn-danger') | ||||
->click('@body #mandate-info button.btn-danger') | ->click('#mandate-info * button.btn-danger') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been removed.') | ->assertToast(Toast::TYPE_SUCCESS, 'The auto-payment has been removed.') | ||||
->assertVisible('@body #mandate-form') | ->assertVisible('#mandate-form') | ||||
->assertMissing('@body #mandate-info'); | ->assertMissing('#mandate-info'); | ||||
}); | |||||
}); | }); | ||||
} | } | ||||
} | } |