spec/features/admin/orders/payments_spec.rb in solidus_backend-1.2.3 vs spec/features/admin/orders/payments_spec.rb in solidus_backend-1.3.0.beta1

- old
+ new

@@ -1,45 +1,35 @@ require 'spec_helper' -describe 'Payments', :type => :feature do +describe 'Payments', type: :feature do stub_authorization! context "with a pre-existing payment" do - let!(:payment) do create(:payment, order: order, amount: order.outstanding_balance, payment_method: create(:credit_card_payment_method), state: state ) end - let(:order) { create(:completed_order_with_totals, number: 'R100', line_items_count: 5) } + let(:order) { create(:completed_order_with_totals, number: 'R100', line_items_price: 50) } let(:state) { 'checkout' } before do - visit spree.admin_path - click_link 'Orders' - within_row(1) do - click_link order.number - end - click_link 'Payments' + visit "/admin/orders/#{order.number}/payments" end - def refresh_page - visit current_path - end - # Regression tests for https://github.com/spree/spree/issues/1453 context 'with a check payment' do let(:order) { create(:completed_order_with_totals, number: 'R100') } let!(:payment) do create(:payment, order: order, amount: order.outstanding_balance, - payment_method: create(:check_payment_method) # Check + payment_method: create(:check_payment_method) # Check ) end it 'capturing a check payment from a new order' do click_icon(:capture) @@ -52,19 +42,19 @@ expect(page).to have_content('Payment Updated') end end it 'should list all captures for a payment' do - capture_amount = order.outstanding_balance/2 * 100 + capture_amount = order.outstanding_balance / 2 * 100 payment.capture!(capture_amount) visit spree.admin_order_payment_path(order, payment) - expect(page).to have_content 'Capture events' + expect(page).to have_content 'Capture Events' # within '#capture_events' do - within_row(1) do - expect(page).to have_content(capture_amount / 100) - end + within_row(1) do + expect(page).to have_content(capture_amount / 100) + end # end end it 'displays the address for a credit card when present' do payment.source.update!(address: create(:address, address1: 'my cc address')) @@ -115,19 +105,21 @@ it 'allows the amount to be edited by clicking on the edit button then saving' do within_row(1) do click_icon(:edit) fill_in('amount', with: '$1') + click_icon(:save) expect(page).to have_selector('td.amount span', text: '$1.00') expect(payment.reload.amount).to eq(1.00) end end it 'allows the amount to be edited by clicking on the amount then saving' do within_row(1) do find('td.amount span').click fill_in('amount', with: '$1.01') + click_icon(:save) expect(page).to have_selector('td.amount span', text: '$1.01') expect(payment.reload.amount).to eq(1.01) end end @@ -148,10 +140,11 @@ it 'displays an error when the amount is invalid' do within_row(1) do click_icon(:edit) fill_in('amount', with: 'invalid') + click_icon(:save) end expect(page).to have_selector('.flash.error', text: 'Invalid resource. Please fix errors and try again.') expect(page).to have_field('amount', with: 'invalid') expect(payment.reload.amount).to eq(150.00) end @@ -161,31 +154,30 @@ let(:state) { 'completed' } it 'does not allow the amount to be edited' do within_row(1) do expect(page).not_to have_selector('.fa-edit') - expect(page).not_to have_selector('td.amount span') end end end end context "with no prior payments" do - let(:order) { create(:order_with_line_items, :line_items_count => 1) } - let!(:payment_method) { create(:credit_card_payment_method)} + let(:order) { create(:order_with_line_items, line_items_count: 1) } + let!(:payment_method) { create(:credit_card_payment_method) } # Regression tests for https://github.com/spree/spree/issues/4129 context "with a credit card payment method" do before do visit spree.admin_order_payments_path(order) end - it "is able to create a new credit card payment with valid information", :js => true do - fill_in "Card Number", :with => "4111 1111 1111 1111" - fill_in "Name *", :with => "Test User" - fill_in "Expiration", :with => "09 / #{Time.current.year + 1}" - fill_in "Card Code", :with => "007" + it "is able to create a new credit card payment with valid information", js: true do + fill_in "Card Number", with: "4111 1111 1111 1111" + fill_in "Name", with: "Test User" + fill_in "Expiration", with: "09 / #{Time.current.year + 1}" + fill_in "Card Code", with: "007" # Regression test for https://github.com/spree/spree/issues/4277 expect(page).to have_css('.ccType[value="visa"]', visible: false) click_button "Continue" expect(page).to have_content("Payment has been successfully created!") end @@ -214,10 +206,10 @@ expect(page).to have_content("Payment has been successfully created!") end end context "with a check" do - let(:order) { create(:completed_order_with_totals, :line_items_count => 1) } + let(:order) { create(:completed_order_with_totals, line_items_count: 1) } let!(:payment_method) { create(:check_payment_method) } before do visit spree.admin_order_payments_path(order.reload) end