1
0
зеркало из https://github.com/glebtv/yookassa.git synced 2026-09-04 10:15:49 +03:00
Этот коммит содержится в:
Ivan Shamatov
2021-10-28 20:15:08 +03:00
родитель 847c90bb6c
Коммит e6a7b5cb7f
23 изменённых файлов: 254 добавлений и 138 удалений

Просмотреть файл

@@ -1,13 +1,13 @@
# frozen_string_literal: true
begin
require 'pry'
require "pry"
rescue LoadError
nil
end
require 'yookassa'
require 'webmock/rspec'
require "yookassa"
require "webmock/rspec"
RSpec.configure do |config|
config.order = :random

Просмотреть файл

@@ -1,104 +1,104 @@
# frozen_string_literal: true
RSpec.describe Yookassa::Payment do
let(:settings) { { shop_id: 'SHOP_ID', api_key: 'API_KEY' } }
let(:settings) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
let(:idempotency_key) { 12_345 }
let(:payment) { described_class.new(settings) }
shared_examples 'returns_payment_object' do
it 'returns success' do
shared_examples "returns_payment_object" do
it "returns success" do
expect(subject).to be_kind_of Yookassa::Response
expect(subject.id).to eq '2490ded1-000f-5000-8000-1f64111bc63e'
expect(subject.id).to eq "2490ded1-000f-5000-8000-1f64111bc63e"
expect(subject.test).to eq true
expect(subject.paid).to eq false
expect(subject.status).to eq 'pending'
expect(subject.status).to eq "pending"
expect(subject.captured_at).to eq nil
expect(subject.created_at).to eq '2019-06-10T21:26:41.395Z'
expect(subject.created_at).to eq "2019-06-10T21:26:41.395Z"
expect(subject.description).to eq nil
expect(subject.expires_at).to eq nil
expect(subject.metadata).to eq Hash[]
expect(subject.metadata).to eq({})
expect(subject.amount).to be_kind_of Yookassa::Entity::Amount
expect(subject.amount.currency).to eq 'RUB'
expect(subject.amount.currency).to eq "RUB"
expect(subject.amount.value).to eq 10.0
expect(subject.confirmation).to be_kind_of Yookassa::Entity::Confirmation
expect(subject.confirmation.confirmation_url).to eq 'https://money.yookassa.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e'
expect(subject.confirmation.type).to eq 'redirect'
expect(subject.confirmation.return_url).to eq 'https://url.test'
expect(subject.confirmation.confirmation_url).to eq "https://money.yookassa.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e"
expect(subject.confirmation.type).to eq "redirect"
expect(subject.confirmation.return_url).to eq "https://url.test"
expect(subject.confirmation.enforce).to eq nil
expect(subject.payment_method).to be_kind_of Yookassa::Entity::PaymentMethod
expect(subject.payment_method.card).to eq nil
expect(subject.payment_method.id).to eq '2490ded1-000f-5000-8000-1f64111bc63e'
expect(subject.payment_method.id).to eq "2490ded1-000f-5000-8000-1f64111bc63e"
expect(subject.payment_method.saved).to eq false
expect(subject.payment_method.type).to eq 'bank_card'
expect(subject.payment_method.type).to eq "bank_card"
expect(subject.payment_method.title).to eq nil
end
end
describe '#create' do
let(:params) { { payment: File.read('spec/fixtures/payment.json') } }
let(:url) { 'https://api.yookassa.ru/v3/payments' }
let(:body) { File.read('spec/fixtures/payment_response.json') }
describe "#create" do
let(:params) { { payment: File.read("spec/fixtures/payment.json") } }
let(:url) { "https://api.yookassa.ru/v3/payments" }
let(:body) { File.read("spec/fixtures/payment_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.create(payment: params, idempotency_key: idempotency_key) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:post, url)).to have_been_made
end
it_behaves_like 'returns_payment_object'
it_behaves_like "returns_payment_object"
end
describe '#get_payment_info' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
describe "#get_payment_info" do
let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}" }
let(:body) { File.read('spec/fixtures/payment_response.json') }
let(:body) { File.read("spec/fixtures/payment_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.get_payment_info(payment_id: payment_id) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:get, url)).to have_been_made
end
it_behaves_like 'returns_payment_object'
it_behaves_like "returns_payment_object"
end
describe '#capture' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
let(:params) { { payment: File.read('spec/fixtures/payment.json') } }
describe "#capture" do
let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:params) { { payment: File.read("spec/fixtures/payment.json") } }
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}/capture" }
let(:body) { File.read('spec/fixtures/payment_response.json') }
let(:body) { File.read("spec/fixtures/payment_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.capture(payment_id: payment_id, idempotency_key: idempotency_key) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:post, url)).to have_been_made
end
it_behaves_like 'returns_payment_object'
it_behaves_like "returns_payment_object"
end
describe '#cancel' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
describe "#cancel" do
let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}/cancel" }
let(:body) { File.read('spec/fixtures/payment_response.json') }
let(:body) { File.read("spec/fixtures/payment_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.cancel(payment_id: payment_id, idempotency_key: idempotency_key) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:post, url)).to have_been_made
end
it_behaves_like 'returns_payment_object'
it_behaves_like "returns_payment_object"
end
end

Просмотреть файл

@@ -1,54 +1,54 @@
# frozen_string_literal: true
RSpec.describe Yookassa::Refund do
let(:settings) { { shop_id: 'SHOP_ID', api_key: 'API_KEY' } }
let(:settings) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
let(:idempotency_key) { 12_345 }
let(:payment) { described_class.new(settings) }
shared_examples 'returns_refund_object' do
it 'returns success' do
shared_examples "returns_refund_object" do
it "returns success" do
expect(subject).to be_kind_of Yookassa::Response
expect(subject.id).to eq '2491ab0c-0015-5000-9000-1640c7f1a6f0'
expect(subject.payment_id).to eq '2491a6e2-000f-5000-9000-1480e820ae17'
expect(subject.status).to eq 'succeeded'
expect(subject.created_at).to eq '2019-06-11T11:58:04.502Z'
expect(subject.description).to eq 'test refund, idem-key 78c95366-ec4b-4284-a0fd-41e694bcdf11'
expect(subject.id).to eq "2491ab0c-0015-5000-9000-1640c7f1a6f0"
expect(subject.payment_id).to eq "2491a6e2-000f-5000-9000-1480e820ae17"
expect(subject.status).to eq "succeeded"
expect(subject.created_at).to eq "2019-06-11T11:58:04.502Z"
expect(subject.description).to eq "test refund, idem-key 78c95366-ec4b-4284-a0fd-41e694bcdf11"
expect(subject.amount).to be_kind_of Yookassa::Entity::Amount
expect(subject.amount.currency).to eq 'RUB'
expect(subject.amount.currency).to eq "RUB"
expect(subject.amount.value).to eq 8.0
end
end
describe '#create' do
let(:payload) { File.read('spec/fixtures/refund.json') }
let(:url) { 'https://api.yookassa.ru/v3/refunds' }
let(:body) { File.read('spec/fixtures/refund_response.json') }
describe "#create" do
let(:payload) { File.read("spec/fixtures/refund.json") }
let(:url) { "https://api.yookassa.ru/v3/refunds" }
let(:body) { File.read("spec/fixtures/refund_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.create(payload: payload, idempotency_key: idempotency_key) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:post, url)).to have_been_made
end
it_behaves_like 'returns_refund_object'
it_behaves_like "returns_refund_object"
end
describe '#get_refund_info' do
let(:payment_id) { '2490ded1-000f-5000-8000-1f64111bc63e' }
describe "#get_refund_info" do
let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:url) { "https://api.yookassa.ru/v3/refunds/#{payment_id}" }
let(:body) { File.read('spec/fixtures/refund_response.json') }
let(:body) { File.read("spec/fixtures/refund_response.json") }
before { stub_request(:any, //).to_return(body: body) }
subject { payment.get_refund_info(payment_id: payment_id) }
it 'sends a request' do
it "sends a request" do
subject
expect(a_request(:get, url)).to have_been_made
end
it_behaves_like 'returns_refund_object'
it_behaves_like "returns_refund_object"
end
end

Просмотреть файл

@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe Yookassa do
it 'has a version number' do
it "has a version number" do
expect(Yookassa::VERSION).not_to be nil
end
end