1
0
зеркало из https://github.com/glebtv/yookassa.git synced 2026-09-03 17:55:51 +03:00

Rewriting Client and changing interface

Этот коммит содержится в:
Ivan Shamatov
2021-11-01 23:12:07 +03:00
родитель ddcc7a3e6b
Коммит f3ff78fee1
13 изменённых файлов: 175 добавлений и 134 удалений

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

@@ -1,9 +1,11 @@
# frozen_string_literal: true
RSpec.describe Yookassa::Payment do
let(:settings) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
let(:idempotency_key) { 12_345 }
let(:payment) { described_class.new(**settings) }
RSpec.describe Yookassa::Payments do
let(:config) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
let(:client) { Yookassa::Client.new(**config) }
let(:idempotency_key) { SecureRandom.hex(1) }
let(:payment) { client.payments }
let(:body) { File.read("spec/fixtures/payment_response.json") }
before { stub_request(:any, //).to_return(body: body, headers: { "Content-Type" => "application/json" }) }
@@ -55,11 +57,11 @@ RSpec.describe Yookassa::Payment do
it_behaves_like "returns_payment_object"
end
describe "#get_payment_info" do
describe "#find" do
let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:url) { "https://api.yookassa.ru/v3/payments/#{payment_id}" }
subject { payment.get_payment_info(payment_id: payment_id) }
subject { payment.find(payment_id: payment_id) }
it "sends a request" do
subject

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

@@ -1,9 +1,10 @@
# frozen_string_literal: true
RSpec.describe Yookassa::Refund do
let(:settings) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
let(:idempotency_key) { 12_345 }
let(:payment) { described_class.new(**settings) }
RSpec.describe Yookassa::Refunds do
let(:config) { { shop_id: "SHOP_ID", api_key: "API_KEY" } }
let(:client) { Yookassa::Client.new(**config) }
let(:idempotency_key) { SecureRandom.hex(1) }
let(:refund) { client.refunds }
let(:body) { File.read("spec/fixtures/refund_response.json") }
before { stub_request(:any, //).to_return(body: body, headers: { "Content-Type" => "application/json" }) }
@@ -27,7 +28,7 @@ RSpec.describe Yookassa::Refund do
let(:payload) { JSON.parse(File.read("spec/fixtures/refund.json")) }
let(:url) { "https://api.yookassa.ru/v3/refunds" }
subject { payment.create(payload: payload, idempotency_key: idempotency_key) }
subject { refund.create(payload: payload, idempotency_key: idempotency_key) }
it "sends a request" do
subject
@@ -37,11 +38,11 @@ RSpec.describe Yookassa::Refund do
it_behaves_like "returns_refund_object"
end
describe "#get_refund_info" do
describe "#find" do
let(:payment_id) { "2490ded1-000f-5000-8000-1f64111bc63e" }
let(:url) { "https://api.yookassa.ru/v3/refunds/#{payment_id}" }
subject { payment.get_refund_info(payment_id: payment_id) }
subject { refund.find(payment_id: payment_id) }
it "sends a request" do
subject

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

@@ -5,17 +5,40 @@ RSpec.describe Yookassa do
expect(Yookassa::VERSION).not_to be nil
end
describe ".configure" do
before do
Yookassa.configure do |config|
config.shop_id = 123
config.api_key = "test_321"
end
before do
Yookassa.configure do |config|
config.shop_id = 123
config.api_key = "test_321"
end
end
describe ".configure" do
it "stores settings and provides access to credentials" do
expect(Yookassa.config.shop_id).to eq(123)
expect(Yookassa.config.api_key).to eq("test_321")
end
end
describe ".client" do
context "when no settings are provided" do
before { Yookassa.instance_variable_set(:@config, nil) }
it "raises an error" do
expect { Yookassa.client }.to raise_error(Yookassa::ConfigError)
end
end
context "when instance configured" do
it "creates and stores client" do
expect(Yookassa.client).to be_a(Yookassa::Client)
expect(Yookassa.client).to eq(Yookassa.client)
end
end
end
describe ".payments" do
it "delegates request to client and creates an instance" do
expect(Yookassa.payments).to be_a(Yookassa::Payments)
end
end
end