mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
87 lines
2.6 KiB
Ruby
87 lines
2.6 KiB
Ruby
# 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 void a Taler payment" do
|
|
order_status = {
|
|
order_status: "paid",
|
|
contract_terms: {
|
|
amount: "KUDOS:2",
|
|
}
|
|
}
|
|
token_endpoint = "https://taler.example.com/private/token"
|
|
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(:post, token_endpoint).to_return(body: { token: "abc" }.to_json)
|
|
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 "Void"
|
|
|
|
click_link class: "icon-void"
|
|
|
|
expect(page).to have_text "VOID"
|
|
expect(page).not_to have_link "Void"
|
|
end
|
|
end
|
|
|
|
it "allows to credit a Taler payment" do
|
|
order_status = {
|
|
order_status: "paid",
|
|
contract_terms: {
|
|
amount: "KUDOS:2",
|
|
}
|
|
}
|
|
token_endpoint = "https://taler.example.com/private/token"
|
|
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(:post, token_endpoint).to_return(body: { token: "abc" }.to_json)
|
|
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 "Credit"
|
|
|
|
click_link class: "icon-credit"
|
|
|
|
expect(page).to have_text "COMPLETED"
|
|
expect(page).not_to have_link "Credit"
|
|
end
|
|
|
|
# Our payment system creates a new payment to show the credit.
|
|
within row_containing("$-9.75") do
|
|
expect(page).not_to have_link "Void"
|
|
end
|
|
end
|
|
end
|