From 96c2b75a0a24eaab6a0a4528546f23eba0ec7215 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 11 Feb 2026 15:47:55 +1100 Subject: [PATCH] Spec admin display of Taler payment actions This should satisfy code coverage. --- spec/factories/order_factory.rb | 6 +-- spec/support/table_helper.rb | 8 ++++ spec/system/admin/payments_taler_spec.rb | 52 ++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 spec/support/table_helper.rb create mode 100644 spec/system/admin/payments_taler_spec.rb diff --git a/spec/factories/order_factory.rb b/spec/factories/order_factory.rb index 59b72b9c18..3a29d99833 100644 --- a/spec/factories/order_factory.rb +++ b/spec/factories/order_factory.rb @@ -238,6 +238,8 @@ FactoryBot.define do factory :completed_order_with_fees, parent: :order_with_distributor do transient do payment_fee { 5 } + payment_calculator { build(:calculator_per_item, preferred_amount: payment_fee) } + payment_method { build(:payment_method, calculator: payment_calculator) } shipping_fee { 3 } shipping_tax_category { nil } end @@ -250,11 +252,9 @@ FactoryBot.define do product = create(:simple_product) create(:line_item, order:, product:) - payment_calculator = build(:calculator_per_item, preferred_amount: evaluator.payment_fee) - payment_method = create(:payment_method, calculator: payment_calculator) create(:payment, order:, amount: order.total, - payment_method:, + payment_method: evaluator.payment_method, state: 'checkout') create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee, diff --git a/spec/support/table_helper.rb b/spec/support/table_helper.rb new file mode 100644 index 0000000000..5847851ea4 --- /dev/null +++ b/spec/support/table_helper.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module TableHelper + # Selector for table row that has the given string + def row_containing(value) + find(:xpath, "(//tr[contains(., '#{value}')])") + end +end diff --git a/spec/system/admin/payments_taler_spec.rb b/spec/system/admin/payments_taler_spec.rb new file mode 100644 index 0000000000..1ef2b6dfa9 --- /dev/null +++ b/spec/system/admin/payments_taler_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'system_helper' + +RSpec.describe "Admin -> Order -> Payments" do + include AuthenticationHelper + include TableHelper + + let(:distributor) { build(:distributor_enterprise) } + let(:order) { create(:completed_order_with_fees, distributor:, payments: [payment]) } + let(:payment) { + build(:payment, :completed, payment_method: taler, source: taler, response_code: "taler-id-1") + } + let(:taler) { + Spree::PaymentMethod::Taler.new( + name: "Taler", + distributors: [distributor], + environment: "test", + preferred_backend_url: "https://taler.example.com", + preferred_api_key: "sandbox", + ) + } + + before do + login_as distributor.owner + end + + it "allows to refund a Taler payment" do + order_status = { + order_status: "paid", + contract_terms: { + amount: "KUDOS:2", + } + } + order_endpoint = "https://taler.example.com/private/orders/taler-id-1" + refund_endpoint = "https://taler.example.com/private/orders/taler-id-1/refund" + stub_request(:get, order_endpoint).to_return(body: order_status.to_json) + stub_request(:post, refund_endpoint).to_return(body: "{}") + + visit spree.admin_order_payments_path(order.number) + + within row_containing("Taler") do + expect(page).to have_text "COMPLETED" + expect(page).to have_link class: "icon-void" + + click_link class: "icon-void" + + expect(page).to have_text "VOID" + expect(page).not_to have_link class: "icon-void" + end + end +end