Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions spec/support/solidus_stripe/backend_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
54 changes: 34 additions & 20 deletions spec/system/backend/solidus_stripe/orders/payments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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