diff --git a/spec/support/solidus_stripe/backend_test_helper.rb b/spec/support/solidus_stripe/backend_test_helper.rb index 17e15283..e4b85cd2 100644 --- a/spec/support/solidus_stripe/backend_test_helper.rb +++ b/spec/support/solidus_stripe/backend_test_helper.rb @@ -161,43 +161,6 @@ def cancel_order # Helper methods for checking expected outcomes and states - def expects_page_to_display_successfully_captured_payment(payment) - expect(page).to have_content('Payment Updated') - expect(payment.reload.state).to eq('completed') - expect(payment.capture_events.first.amount).to eq(payment.amount) - end - - def expects_page_to_display_successfully_refunded_payment(payment) - expect(page).to have_content('Refund has been successfully created!') - expect(payment).to be_fully_refunded - end - - def expects_page_to_display_successfully_partially_refunded_payment(payment, amount) - expect(page).to have_content('Refund has been successfully created!') - expect(payment.reload.state).to eq('completed') - expect(payment.refunds.first.amount).to eq(amount) - end - - def expects_page_to_display_successfully_voided_payment(payment) - expect(page).to have_content('Payment Updated') - expect(payment.reload.state).to eq('void') - end - - def expects_page_to_display_successfully_canceled_order_payment(payment) - expect(page).to have_content('Order canceled') - expect(payment.reload.state).to eq('void') - end - - def expects_page_to_display_capture_fail_message(payment, message) - expect(page).to have_content(message) - expect(payment.reload.state).to eq('failed') - end - - def expects_page_to_display_payment(payment) - click_on 'Payments' - expect(page).to have_content(payment.number) - end - def expects_page_to_display_log_messages(log_messages = []) expect(page).to have_content('Log Entries') log_messages.each do |log_message| diff --git a/spec/system/backend/solidus_stripe/orders/payments_spec.rb b/spec/system/backend/solidus_stripe/orders/payments_spec.rb index 8edb45e2..4c7f5058 100644 --- a/spec/system/backend/solidus_stripe/orders/payments_spec.rb +++ b/spec/system/backend/solidus_stripe/orders/payments_spec.rb @@ -4,14 +4,18 @@ RSpec.describe 'SolidusStripe Orders Payments', :js do include SolidusStripe::BackendTestHelper + include Devise::Test::IntegrationHelpers stub_authorization! + let(:user) { create(:admin_user) } + context 'with successful payment operations' do it 'navigates to the payments page' do payment = create_authorized_payment visit_payments_page - expects_page_to_display_payment(payment) + click_on 'Payments' + expect(page).to have_content(payment.number) end it 'displays log entries for a payment' do @@ -28,7 +32,9 @@ capture_payment - expects_page_to_display_successfully_captured_payment(payment) + expect(page).to have_content('Payment Updated') + expect(payment.reload.state).to eq('completed') + expect(payment.capture_events.first.amount).to eq(payment.amount) expects_payment_to_have_correct_capture_amount_on_stripe(payment, payment.amount) end @@ -40,7 +46,9 @@ capture_partial_payment_amount(payment, partial_capture_amount) - expects_page_to_display_successfully_captured_payment(payment) + expect(page).to have_content('Payment Updated') + expect(payment.reload.state).to eq('completed') + expect(payment.capture_events.first.amount).to eq(payment.amount) expects_payment_to_have_correct_capture_amount_on_stripe(payment, partial_capture_amount) end @@ -50,7 +58,8 @@ void_payment - expects_page_to_display_successfully_voided_payment(payment) + expect(page).to have_content('Payment Updated') + expect(payment.reload.state).to eq('void') expects_payment_to_be_voided_on_stripe(payment) end @@ -60,7 +69,8 @@ refund_payment - expects_page_to_display_successfully_refunded_payment(payment) + expect(page).to have_content('Refund has been successfully created!') + expect(payment).to be_fully_refunded expects_payment_to_be_refunded_on_stripe(payment, payment.amount) end @@ -72,35 +82,35 @@ partial_refund_amount = 25 partially_refund_payment(refund_reason, partial_refund_amount) - expects_page_to_display_successfully_partially_refunded_payment(payment, partial_refund_amount) + expect(page).to have_content('Refund has been successfully created!') + expect(payment.reload.state).to eq('completed') + expect(payment.refunds.first.amount).to eq(partial_refund_amount) expects_payment_to_be_refunded_on_stripe(payment, partial_refund_amount) end it 'cancels an order with captured payment' do payment = create_captured_payment + + sign_in user visit_payments_page cancel_order - # https://github.com/solidusio/solidus/blob/ab59d6435239b50db79d73b9a974af057ad56b52/core/app/models/spree/payment_method.rb#L169-L181 - pending "needs to implement try_void method to handle voiding payments on order cancellation" - - expects_page_to_display_successfully_canceled_order_payment(payment) - expects_payment_to_be_voided_on_stripe(payment) + expect(page).to have_content('Order canceled') + expect(payment.reload.state).to eq('completed') + expects_payment_to_be_refunded_on_stripe(payment, payment.amount) end it 'cancels an order with authorized payment' do payment = create_authorized_payment + + sign_in user visit_payments_page cancel_order - # https://github.com/solidusio/solidus/blob/ab59d6435239b50db79d73b9a974af057ad56b52/core/app/models/spree/payment_method.rb#L169-L181 - # Note that for this specific case, the test is pending also because there is an issue - # with locating the user who canceled the order. - pending "needs to implement try_void method to handle voiding payments on order cancellation" - - expects_page_to_display_successfully_canceled_order_payment(payment) + expect(page).to have_content('Order canceled') + expect(payment.reload.state).to eq('void') expects_payment_to_be_voided_on_stripe(payment) end @@ -112,7 +122,9 @@ capture_payment payment = last_valid_payment - expects_page_to_display_successfully_captured_payment(payment) + expect(page).to have_content('Payment Updated') + expect(payment.reload.state).to eq('completed') + expect(payment.capture_events.first.amount).to eq(payment.amount) expects_payment_to_have_correct_capture_amount_on_stripe(payment, payment.amount) end end @@ -124,8 +136,10 @@ capture_payment - expects_page_to_display_capture_fail_message(payment, - 'This PaymentIntent could not be captured because it has a status of requires_action.') + expect(page).to have_content( + 'This PaymentIntent could not be captured because it has a status of requires_action.' + ) + expect(payment.reload.state).to eq('failed') end end end