diff --git a/spec/fixtures/payment_response.json b/spec/fixtures/payment_response.json new file mode 100644 index 0000000..5082c25 --- /dev/null +++ b/spec/fixtures/payment_response.json @@ -0,0 +1,28 @@ +{ + "id": "2490ded1-000f-5000-8000-1f64111bc63e", + "status": "pending", + "paid": false, + "amount": { + "value": "10.00", + "currency": "RUB" + }, + "confirmation": { + "type": "redirect", + "return_url": "https://url.test", + "confirmation_url": "https://money.yandex.ru/payments/external/confirmation?orderId=2490ded1-000f-5000-8000-1f64111bc63e" + }, + "created_at": "2019-06-10T21:26:41.395Z", + "metadata": { + }, + "payment_method": { + "type": "bank_card", + "id": "2490ded1-000f-5000-8000-1f64111bc63e", + "saved": false + }, + "recipient": { + "account_id": "54401", + "gateway_id": "289250" + }, + "refundable": false, + "test": true +} diff --git a/spec/yandex-checkout/payment_spec.rb b/spec/yandex-checkout/payment_spec.rb index 6100478..60a5b46 100644 --- a/spec/yandex-checkout/payment_spec.rb +++ b/spec/yandex-checkout/payment_spec.rb @@ -3,27 +3,48 @@ RSpec.describe YandexCheckout::Payment do describe '#make_payment' do let(:settings) { { shop_id: 'SHOP_ID', api_key: 'API_KEY' } } - let(:idempotence_key) { 123 } + let(:idempotence_key) { 12_345 } let(:payment) { described_class.new(settings) } - let(:params) { { payment: File.read('spec/fixtures/payment.json') } } - let(:answer) { { result: 'accepted' } } + let(:params) { { payment: File.read('spec/fixtures/payment.json') } } + let(:url) { 'https://payment.yandex.net/api/v3/payments' } + let(:body) { File.read('spec/fixtures/payment_response.json') } - before { stub_request(:any, //).to_return(body: answer.to_json) } + before { stub_request(:any, //).to_return(body: body) } subject { payment.create(params) } - context 'using ssl via POST:' do - let(:url) { 'https://payment.yandex.net/api/v3/payments' } + it 'sends a request' do + subject + expect(a_request(:post, url)).to have_been_made + end - it 'sends a request' do - # binding.pry - subject - expect(a_request(:post, url)).to have_been_made - end + it 'returns success' do + expect(subject).to be_kind_of YandexCheckout::Response + 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.captured_at).to eq nil + 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[] - it 'returns success' do - expect(subject).to be_kind_of YandexCheckout::Response - expect(subject.result).to eq 'accepted' - end + expect(subject.amount).to be_kind_of YandexCheckout::Entity::Amount + expect(subject.amount.currency).to eq 'RUB' + expect(subject.amount.value).to eq 10.0 + + expect(subject.confirmation).to be_kind_of YandexCheckout::Entity::Confirmation + expect(subject.confirmation.confirmation_url).to eq 'https://money.yandex.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 YandexCheckout::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.saved).to eq false + expect(subject.payment_method.type).to eq 'bank_card' + expect(subject.payment_method.title).to eq nil end end end