Builds for
1 pipeline
failed
in
0 seconds
Test card charge creation
Showing
3 changed files
with
66 additions
and
4 deletions
| ... | @@ -19,8 +19,8 @@ module ActsAsChargeable | ... | @@ -19,8 +19,8 @@ module ActsAsChargeable | 
| 19 | return { error_message: error_message } | 19 | return { error_message: error_message } | 
| 20 | end | 20 | end | 
| 21 | send("charge_with_#{service}", options) | 21 | send("charge_with_#{service}", options) | 
| 22 | - rescue Exception => exception | 22 | + # rescue Exception => exception | 
| 23 | - { error_message: exception.message } | 23 | + # { error_message: exception.message } | 
| 24 | end | 24 | end | 
| 25 | 25 | ||
| 26 | def charge_with_conekta(options) | 26 | def charge_with_conekta(options) | ... | ... | 
spec/conekta_card_handler_spec.rb
0 → 100644
| 1 | +# frozen_string_literal: true | ||
| 2 | +require 'spec_helper' | ||
| 3 | + | ||
| 4 | +describe Var::ConektaCardHandler do | ||
| 5 | + let!(:product) { | ||
| 6 | + # product = instance_double('Product') | ||
| 7 | + # allow(product).to receive(:charge_with).and_return(:success) | ||
| 8 | + # product | ||
| 9 | + Product.create | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + let!(:var_mock) { | ||
| 13 | + var = class_double('Var') | ||
| 14 | + allow(var).to receive(:find_charge).and_return(product) | ||
| 15 | + var | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + it 'processes card charge' do | ||
| 19 | + conekta_object_mock = JSON.parse( | ||
| 20 | + ConektaChargeCreateObject::CARD_CREATE_CHARGE_OBJECT, | ||
| 21 | + object_class: OpenStruct) | ||
| 22 | + allow(product).to receive(:conekta_charge).and_return(conekta_object_mock) | ||
| 23 | + | ||
| 24 | + Var.create_charge(:conekta, product, { conekta_type: 'card' }) | ||
| 25 | + | ||
| 26 | + expect(product.var_id).to eq conekta_object_mock.id | ||
| 27 | + expect(product.var_service).to eq 'conekta' | ||
| 28 | + expect(product.var_status).to eq('paid') | ||
| 29 | + | ||
| 30 | + Var::ConektaHandler.analyze(WebHookPostRequest::CARD_CHARGE_CREATED) | ||
| 31 | + | ||
| 32 | + expect(product.var_id).to eq conekta_object_mock.id | ||
| 33 | + expect(product.var_service).to eq 'conekta' | ||
| 34 | + expect(product.var_status).to eq('paid') | ||
| 35 | + end | ||
| 36 | + | ||
| 37 | + it 'processes card payment' do | ||
| 38 | + conekta_object_mock = JSON.parse( | ||
| 39 | + ConektaChargeCreateObject::CARD_CREATE_CHARGE_OBJECT, | ||
| 40 | + object_class: OpenStruct) | ||
| 41 | + allow(product).to receive(:conekta_charge).and_return(conekta_object_mock) | ||
| 42 | + | ||
| 43 | + Var.create_charge(:conekta, product, { conekta_type: 'card' }) | ||
| 44 | + | ||
| 45 | + expect(product.var_id).to eq conekta_object_mock.id | ||
| 46 | + expect(product.var_service).to eq 'conekta' | ||
| 47 | + expect(product.var_status).to eq('paid') | ||
| 48 | + | ||
| 49 | + Var::ConektaHandler.analyze(WebHookPostRequest::CARD_CHARGE_PAID) | ||
| 50 | + | ||
| 51 | + expect(product.var_id).to eq conekta_object_mock.id | ||
| 52 | + expect(product.var_service).to eq 'conekta' | ||
| 53 | + expect(product.var_status).to eq('paid') | ||
| 54 | + expect(product.var_paid_amount).to eq 0.00 | ||
| 55 | + end | ||
| 56 | +end | ||
| 57 | + # Conekta.config do |c| | ||
| 58 | + # c.locale = :en | ||
| 59 | + # # Llave de Sandbox | ||
| 60 | + # c.api_key = 'key_mGmC5ry7s71JSLCv2WcxUg' | ||
| 61 | + # c::PUBLIC_KEY = 'key_K6WVsv82RrEHGocJQcoEqPw' | ||
| 62 | + # end | ||
| 63 | + # Var.create_charge(:conekta, product, { conekta_type: 'card', card_token: 'tok_ZGFFi3sv18a3duJWR' }) | 
| ... | @@ -125,8 +125,7 @@ describe Var do | ... | @@ -125,8 +125,7 @@ describe Var do | 
| 125 | end | 125 | end | 
| 126 | 126 | ||
| 127 | it 'handles payout paid' do | 127 | it 'handles payout paid' do | 
| 128 | - null = nil | 128 | + params = { "data": { "object": { "livemode": true, "currency": 'MXN', "method": { "id": 'pytmtd_MymQ7favB2hQJC', "created_at": 1_467_832_748, "payee_id": nil, "_type": 'BankTransferPayoutMethod', "object": 'bank_transfer_payout_method', "account_number": '072580002374915018', "account_holder": 'UKKO SOLUTIONS SA DE CV', "bank": 'Banco Mercantil del Norte, S.A.' }, "object": 'transfer', "amount": 303_534, "id": '577d59ac243c7fee8100146d', "created_at": 1_467_832_748, "status": 'scheduled', "statement_reference": '4632539', "statement_description": 'Conekta 4632539' }, "previous_attributes": {} } } | 
| 129 | - params = { "object": { "livemode": true, "currency": 'MXN', "method": { "id": 'pytmtd_MymQ7favB2hQJC', "created_at": 1_467_832_748, "payee_id": null, "_type": 'BankTransferPayoutMethod', "object": 'bank_transfer_payout_method', "account_number": '072580002374915018', "account_holder": 'UKKO SOLUTIONS SA DE CV', "bank": 'Banco Mercantil del Norte, S.A.' }, "object": 'transfer', "amount": 303_534, "id": '577d59ac243c7fee8100146d', "created_at": 1_467_832_748, "status": 'scheduled', "statement_reference": '4632539', "statement_description": 'Conekta 4632539' }, "previous_attributes": {} } | ||
| 130 | payout_handler = class_double('Var::ConektaPayoutHandler') | 129 | payout_handler = class_double('Var::ConektaPayoutHandler') | 
| 131 | .as_stubbed_const(transfer_nested_constants: true) | 130 | .as_stubbed_const(transfer_nested_constants: true) | 
| 132 | expect(payout_handler).to receive(:analyze).with(params) | 131 | expect(payout_handler).to receive(:analyze).with(params) | ... | ... | 
- 
Please register or login to post a comment