Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/PaymentMollieTest.php
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | public function testPayment(): void | ||||
->submitLogon('payment-test@kolabnow.com', 'simple123', true, ['paymentProvider' => 'mollie']) | ->submitLogon('payment-test@kolabnow.com', 'simple123', true, ['paymentProvider' => 'mollie']) | ||||
->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') | ||||
// Note we use double click to assert it does not create redundant requests | // Note we use double click to assert it does not create redundant requests | ||||
->click('@body #payment-form button') | ->click('@button-action') | ||||
->click('@body #payment-form button'); | ->click('@button-action'); | ||||
}) | }) | ||||
->on(new PaymentMollie()) | ->on(new PaymentMollie()) | ||||
->assertSeeIn('@title', \config('app.name') . ' Payment') | ->assertSeeIn('@title', \config('app.name') . ' Payment') | ||||
->assertSeeIn('@amount', 'CHF 12.34'); | ->assertSeeIn('@amount', 'CHF 12.34'); | ||||
$this->assertSame(1, $user->wallets()->first()->payments()->count()); | $this->assertSame(1, $user->wallets()->first()->payments()->count()); | ||||
// Looks like the Mollie testing mode is limited. | // Looks like the Mollie testing mode is limited. | ||||
Show All 34 Lines | public function testAutoPaymentSetup(): void | ||||
]); | ]); | ||||
$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' => 'mollie']) | ->submitLogon('payment-test@kolabnow.com', 'simple123', true, ['paymentProvider' => 'mollie']) | ||||
->on(new Dashboard()) | ->on(new Dashboard()) | ||||
->click('@links .link-wallet') | ->click('@links .link-wallet') | ||||
->on(new WalletPage()) | ->on(new WalletPage()) | ||||
->click('@main button') | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->assertSeeIn('@title', 'Top up your wallet') | |||||
->assertSeeIn('@button-cancel', 'Cancel') | |||||
->assertSeeIn('@body #mandate-form button', 'Set up auto-payment') | |||||
->assertSeeIn('@body #mandate-form p', 'Add auto-payment, so you never') | |||||
->assertMissing('@body #mandate-form .alert') | ->assertMissing('@body #mandate-form .alert') | ||||
->click('@body #mandate-form button') | ->click('@main #mandate-form button') | ||||
->assertSeeIn('@title', 'Add auto-payment') | ->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ||||
$browser->assertSeeIn('@title', 'Add auto-payment') | |||||
->waitFor('#payment-method-selection #creditcard') | |||||
machniak: It would be good to have some assertions on the payment methods list. | |||||
->assertMissing('#payment-method-selection #paypal') | |||||
->assertMissing('#payment-method-selection #banktransfer') | |||||
->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 20 Lines | public function testAutoPaymentSetup(): void | ||||
->click('@button-action'); | ->click('@button-action'); | ||||
}) | }) | ||||
->on(new PaymentMollie()) | ->on(new PaymentMollie()) | ||||
->assertSeeIn('@title', \config('app.name') . ' Auto-Payment Setup') | ->assertSeeIn('@title', \config('app.name') . ' Auto-Payment Setup') | ||||
->assertMissing('@amount') | ->assertMissing('@amount') | ||||
->submitValidCreditCard() | ->submitValidCreditCard() | ||||
->waitForLocation('/wallet') | ->waitForLocation('/wallet') | ||||
->visit('/wallet?paymentProvider=mollie') | ->visit('/wallet?paymentProvider=mollie') | ||||
->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 Mastercard (**** **** **** 6787).'; | |||||
$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') | ||||
->assertMissing('@body .alert') | ->assertSeeIn( | ||||
->click('@button-cancel'); | '#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)', | |||||
'Mastercard (**** **** **** 6787)' | |||||
) | |||||
->assertMissing('@body .alert'); | |||||
$this->assertSame(1, $user->wallets()->first()->payments()->count()); | $this->assertSame(1, $user->wallets()->first()->payments()->count()); | ||||
}); | }); | ||||
// Test updating (disabled) auto-payment | // Test updating (disabled) auto-payment | ||||
$this->browse(function (Browser $browser) use ($user) { | $this->browse(function (Browser $browser) use ($user) { | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->setSetting('mandate_disabled', 1); | $wallet->setSetting('mandate_disabled', 1); | ||||
$browser->refresh() | $browser->refresh() | ||||
->on(new WalletPage()) | ->on(new WalletPage()) | ||||
->click('@main button') | ->waitFor('#mandate-info') | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->waitFor('@body #mandate-info') | |||||
->assertSeeIn( | ->assertSeeIn( | ||||
'@body #mandate-info .disabled-mandate', | '#mandate-info .disabled-mandate', | ||||
'The configured auto-payment has been disabled' | 'The configured auto-payment has been disabled' | ||||
) | ) | ||||
->assertSeeIn('@body #mandate-info button.btn-primary', 'Change auto-payment') | ->assertSeeIn('#mandate-info button.btn-primary', 'Change auto-payment') | ||||
->click('@body #mandate-info button.btn-primary') | ->click('#mandate-info button.btn-primary') | ||||
->assertSeeIn('@title', 'Update auto-payment') | ->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ||||
$browser->assertSeeIn('@title', 'Update auto-payment') | |||||
->assertSeeIn( | ->assertSeeIn( | ||||
'@body form .disabled-mandate', | '@body form .disabled-mandate', | ||||
'The auto-payment is disabled.' | '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.') | ||||
// Open the dialog again and make sure the "disabled" text isn't there | // make sure the "disabled" text isn't there | ||||
->click('@main button') | ->assertMissing('#mandate-info .disabled-mandate') | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | ->click('#mandate-info button.btn-primary') | ||||
$browser->assertMissing('@body #mandate-info .disabled-mandate') | ->assertMissing('form .disabled-mandate') | ||||
->click('@body #mandate-info button.btn-primary') | ->click('button.modal-cancel'); | ||||
->assertMissing('@body form .disabled-mandate') | |||||
->click('@button-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'); | ||||
->click('@button-cancel'); | |||||
}); | |||||
}); | }); | ||||
// Test pending and failed mandate | // Test pending and failed mandate | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->on(new WalletPage()) | $browser->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') | ||||
->waitFor('#payment-method-selection #creditcard') | |||||
Done Inline ActionsAlso assert on expected methods for auto-payment. machniak: Also assert on expected methods for auto-payment. | |||||
Done Inline ActionsI think we're already testing this on the controller, so I wouldn't test all methods here again. Otherwise we'll have to adjust in all places whenever anything changes. Do you still want this tested? mollekopf: I think we're already testing this on the controller, so I wouldn't test all methods here again. | |||||
Done Inline ActionsYes. We want the vue code tested. machniak: Yes. We want the vue code tested. | |||||
->click('#creditcard'); | |||||
}) | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->assertSeeIn('@title', 'Add auto-payment') | |||||
->assertSeeIn('@button-cancel', 'Cancel') | ->assertSeeIn('@button-cancel', 'Cancel') | ||||
->assertSeeIn('@body #mandate-form button', 'Set up auto-payment') | ->assertSeeIn('@button-action', 'Continue') | ||||
->assertSeeIn('@body #mandate-form p', 'Add auto-payment, so you never') | |||||
->assertMissing('@body #mandate-form .alert') | |||||
->click('@body #mandate-form button') | |||||
->assertSeeIn('@title', 'Add auto-payment') | |||||
->assertMissing('@body .alert') | |||||
// 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') | ||||
->click('@button-action'); | ->click('@button-action'); | ||||
}) | }) | ||||
->on(new PaymentMollie()) | ->on(new PaymentMollie()) | ||||
->submitValidCreditCard('open') | ->submitValidCreditCard('open') | ||||
->waitForLocation('/wallet') | ->waitForLocation('/wallet') | ||||
->visit('/wallet?paymentProvider=mollie') | ->visit('/wallet?paymentProvider=mollie') | ||||
->on(new WalletPage()) | ->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 Credit Card.'; | |||||
$browser->assertSeeIn('@title', 'Top up your wallet') | |||||
->waitFor('#mandate-info') | |||||
->assertSeeIn('#mandate-info p:first-child', $expected) | |||||
->assertSeeIn( | ->assertSeeIn( | ||||
'#mandate-info .alert-warning', | '#mandate-info .alert-warning', | ||||
'The setup of the automatic payment is still in progress.' | 'The setup of the automatic payment is still in progress.' | ||||
) | ) | ||||
->assertSeeIn('@body #mandate-info .btn-danger', 'Cancel auto-payment') | |||||
->assertSeeIn('@body #mandate-info .btn-primary', 'Change auto-payment') | |||||
// Delete the mandate | // Delete the mandate | ||||
->click('@body #mandate-info .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.') | ||||
->assertSeeIn('@body #mandate-form p', 'Add auto-payment, so you never') | |||||
->assertMissing('@body #mandate-form .alert') | ->assertMissing('@body #mandate-form .alert') | ||||
->click('@body #mandate-form button') | |||||
->assertSeeIn('@title', 'Add auto-payment') | // Create a new mandate | ||||
->assertMissing('@body .alert') | ->click('@main #mandate-form button') | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->assertSeeIn('@title', 'Add auto-payment') | |||||
->waitFor('#payment-method-selection #creditcard') | |||||
->click('#creditcard'); | |||||
}) | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->assertSeeIn('@title', 'Add auto-payment') | |||||
->assertSeeIn('@button-cancel', 'Cancel') | |||||
->assertSeeIn('@button-action', 'Continue') | |||||
// 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') | ||||
->click('@button-action'); | ->click('@button-action'); | ||||
}) | }) | ||||
->on(new PaymentMollie()) | ->on(new PaymentMollie()) | ||||
->submitValidCreditCard('failed') | ->submitValidCreditCard('failed') | ||||
->waitForLocation('/wallet') | ->waitForLocation('/wallet') | ||||
->visit('/wallet?paymentProvider=mollie') | ->visit('/wallet?paymentProvider=mollie') | ||||
->on(new WalletPage()) | ->on(new WalletPage()) | ||||
->click('@main button') | |||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->waitFor('#mandate-form') | |||||
->assertMissing('#mandate-info') | |||||
->assertSeeIn('#mandate-form p', 'Add auto-payment') | |||||
->waitFor('#mandate-form .alert-danger') | ->waitFor('#mandate-form .alert-danger') | ||||
->assertSeeIn( | ->assertSeeIn( | ||||
'#mandate-form .alert-danger', | '#mandate-form .alert-danger', | ||||
'The setup of automatic payments failed. Restart the process to enable' | 'The setup of automatic payments failed. Restart the process to enable' | ||||
) | ) | ||||
->assertSeeIn('@body #mandate-form .btn-primary', 'Set up auto-payment'); | ->click('@main button') | ||||
->with(new Dialog('@payment-dialog'), function (Browser $browser) { | |||||
$browser->waitFor('#mandate-form') | |||||
->assertMissing('#mandate-info'); | |||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
} | } |
It would be good to have some assertions on the payment methods list.