webpay-mock 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c646a455055caf1fe597bf977b68a7e54582f82
4
- data.tar.gz: 98dfd0e1aa816edc408d15ab865020c6a1ee213a
3
+ metadata.gz: eb0dd9999cc3d3dc74d84f7f0c612fafe45db3ab
4
+ data.tar.gz: e50c6b8cc4f2bfd9b7f3d4491cf4efbf53a4683f
5
5
  SHA512:
6
- metadata.gz: 4d6c2ff3ec10265b66b9fc73baee8be3796e723c854a8160cdd4417507abaf428966a94c4ebc71f2843133877fa50a34b2cfda5e0e82153059ccda3dae3a40c6
7
- data.tar.gz: 0403e897c37fb52d9db7a718e3faf1aac7ad30844da973c8e5512aca98b75a8daab8c280ff2e2c12a641f3e5bbb4531eb6d0f9f05b3285771f125bc57531804c
6
+ metadata.gz: f599f77b6251d9d4eb19f79f644a95bace9316f0b383b9b566087777c6c0244e0b09db25e16edfac9f4c1c5ab6b4886e025517434d62d7ca11c49c8dcda5d027
7
+ data.tar.gz: 4fe76762f6aec970f48467701a48ea7a3c952ad5cd68d577ce0900d025a7c5909273547eba4d55e48972a1aa1dc182682afbf46f82f13abac9ac0c1ae430c2ac
@@ -44,7 +44,7 @@ module WebPay::Mock::FakeEntity
44
44
  if value == false
45
45
  {
46
46
  captured: false,
47
- paid: false,
47
+ paid: true,
48
48
  expire_time: Time.now.to_i + 60 * 60 * 24 * 7
49
49
  }
50
50
  end
@@ -5,9 +5,10 @@ module WebPay::Mock::FakeError
5
5
  {
6
6
  status: 400,
7
7
  body: { error: {
8
- 'type' => 'invalid_request_error',
9
- 'message' => "can't save charge: Amount can't be blank",
10
- 'param' => 'amount'
8
+ 'message' => 'Missing required param: amount',
9
+ 'caused_by' => 'insufficient',
10
+ 'param' => 'amount',
11
+ 'type' => 'invalid_request_error'
11
12
  }.merge(stringify_keys(overrides)) }.to_json
12
13
  }
13
14
  end
@@ -16,7 +17,9 @@ module WebPay::Mock::FakeError
16
17
  {
17
18
  status: 401,
18
19
  body: { error: {
19
- 'message' => "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY')."
20
+ 'message' => "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY').",
21
+ 'caused_by' => 'insufficient',
22
+ 'type' => 'unauthorized'
20
23
  }.merge(stringify_keys(overrides)) }.to_json
21
24
  }
22
25
  end
@@ -25,9 +28,11 @@ module WebPay::Mock::FakeError
25
28
  {
26
29
  status: 402,
27
30
  body: { error: {
28
- 'type' => 'card_error',
29
- 'message' => 'This card cannot be used.',
30
- 'code' => 'card_declined'
31
+ 'message' => 'The card number is invalid. Make sure the number entered matches your credit card.',
32
+ 'caused_by' => 'buyer',
33
+ 'param' => 'number',
34
+ 'type' => 'card_error',
35
+ 'code' => 'incorrect_number'
31
36
  }.merge(stringify_keys(overrides)) }.to_json
32
37
  }
33
38
  end
@@ -36,9 +41,10 @@ module WebPay::Mock::FakeError
36
41
  {
37
42
  status: 404,
38
43
  body: { error: {
39
- 'type' => 'invalid_request_error',
40
- 'message' => 'No such charge: ch_bBM4IJ0XF2VIch8',
41
- 'param' => 'id'
44
+ 'message' => 'No such charge',
45
+ 'caused_by' => 'missing',
46
+ 'param' => 'id',
47
+ 'type' => 'invalid_request_error'
42
48
  }.merge(stringify_keys(overrides)) }.to_json
43
49
  }
44
50
  end
@@ -47,8 +53,9 @@ module WebPay::Mock::FakeError
47
53
  {
48
54
  status: 500,
49
55
  body: { error: {
50
- 'type' => 'api_error',
51
- 'message' => 'Unkown error occured',
56
+ 'type' => 'api_error',
57
+ 'message' => 'Unkown error occured',
58
+ 'caused_by' => 'service'
52
59
  }.merge(stringify_keys(overrides)) }.to_json
53
60
  }
54
61
  end
@@ -1,5 +1,5 @@
1
1
  class WebPay
2
2
  module Mock
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -57,6 +57,8 @@ module WebPay::Mock::WebMockWrapper
57
57
  [:delete, '/customers/:id', { 'id' => id, 'deleted' => true }]
58
58
  when :all
59
59
  [:get, '/customers', fake_list('/customers', lambda { customer_from({}, overrides) })]
60
+ when :delete_active_card
61
+ [:delete, '/customers/:id/active_card',customer_from({}, { id: id }.merge(overrides.merge(active_card: nil)))]
60
62
  end
61
63
  when :recursion, :recursions
62
64
  case action.to_sym
data/lib/webpay/mock.rb CHANGED
@@ -2,7 +2,6 @@ require "webpay/mock/version"
2
2
 
3
3
  class WebPay
4
4
  module Mock
5
- # Your code goes here...
6
5
  end
7
6
  end
8
7
 
@@ -69,7 +69,7 @@ describe WebPay::Mock::FakeEntity::Charge do
69
69
  subject(:charge) { charge_from(capture: false) }
70
70
 
71
71
  specify { expect(charge['captured']).to eq false }
72
- specify { expect(charge['paid']).to eq false }
72
+ specify { expect(charge['paid']).to eq true }
73
73
  specify { expect(charge['expire_time']).to be_within(2).of(Time.now.to_i + 60 * 60 * 24 * 7) }
74
74
  end
75
75
 
@@ -1,4 +1,6 @@
1
1
  require 'spec_helper'
2
+ require 'webpay'
3
+
2
4
  describe WebPay::Mock::FakeEntity do
3
5
  include WebPay::Mock::FakeEntity
4
6
 
@@ -9,4 +11,14 @@ describe WebPay::Mock::FakeEntity do
9
11
  specify { expect(list['count']).to eq 3 }
10
12
  specify { expect(list['data']).to eq [1, 2, 3] }
11
13
  end
14
+
15
+ describe 'fake webhook request from event' do
16
+ let(:webpay) { WebPay.new('test_secret_xxxxxx') }
17
+
18
+ it 'should accept string event as webhook body' do
19
+ fake = fake_event
20
+ received = webpay.receive_webhook(fake.to_json)
21
+ expect(received.id).to eq fake['id']
22
+ end
23
+ end
12
24
  end
@@ -106,6 +106,16 @@ describe WebPay::Mock::WebMockWrapper do
106
106
  before { webpay_stub(:customers, :all) }
107
107
  specify { expect(webpay.customer.all.count).to eq 3 }
108
108
  end
109
+
110
+ describe 'delete_active_card' do
111
+ let(:id) { 'cus_xxxxxxxxx' }
112
+ let!(:updated) { webpay_stub(:customers, :delete_active_card, id: id) }
113
+ specify do
114
+ response = webpay.customer.delete_active_card(id: id)
115
+ expect(response.id).to eq id
116
+ expect(response.active_card).to be_nil
117
+ end
118
+ end
109
119
  end
110
120
 
111
121
  describe 'recursios' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpay-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - webpay
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-07 00:00:00.000000000 Z
12
+ date: 2015-01-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: webmock