webpay-mock 0.0.1 → 0.1.1

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: 71da9d72eb0dbbb1fea856fa17cb521ae26a79cf
4
- data.tar.gz: 2e7a1f855395a7072c3287632b22715d68bd778c
3
+ metadata.gz: f0f052e8210caccab939a6bb84e2a27bfbdd3e05
4
+ data.tar.gz: 0c1d5335bbc63fac0fb61d3d34b3ab564b8733bd
5
5
  SHA512:
6
- metadata.gz: 4f62f0cf5f92a6654caf9a685c0005000a05a34296967dcea30fd82e4901d069eabecc29b39894f3a2513bc1df6866f43253fd8e5da342b18afa359b6a39b6b2
7
- data.tar.gz: 0874e01c7dd5c5b9a310427f6060cd790caab9824be3c8c2e79783eef8ff8fac0185232c054640d5e605454fb012db84c02e761c912f85c8f5a2f87da258468c
6
+ metadata.gz: 2df12a63be1ed292e7cec629cca83ea72687139e17c9ebd85e140352809193a448df0d280eaec52ced57bd92449520a143951dd09c26136edd2c9d4e9a781296
7
+ data.tar.gz: 1bb7b8e0230ba0bfe567654fbc86b1e26e3a7597217d21b63065c19c0d3f3e8cfbd9f7e29dbe3dde2ed53c2ce18f3b07ed2de8d4b9085e0860689742b7203708
data/README.md CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
25
25
  In `spec_helper.rb`,
26
26
 
27
27
  ```ruby
28
- require 'webpay-mock'
28
+ require 'webpay/mock'
29
29
 
30
30
  RSpec.configure do |c|
31
31
  c.include WebPay::Mock::WebMockWrapper
@@ -38,10 +38,10 @@ In your spec file,
38
38
  let(:params) { { amount: 1000, currency: 'jpy', card: 'tok_xxxxxxxxx', description: 'test charge' } }
39
39
  let!(:response) { webpay_stub(:charges, :create, params: params) }
40
40
 
41
- specify { expect(WebPay::Charge.create(params).id).to eq response['id'] }
41
+ specify { expect(webpay.charge.create(params).id).to eq response['id'] }
42
42
  ```
43
43
 
44
- See [our test cases](https://github.com/tomykaira/webpay-mock/blob/master/spec/webmock_wrapper_spec.rb) for more examples.
44
+ See [our test cases](https://github.com/webpay/webpay-mock/blob/master/spec/webmock_wrapper_spec.rb) for more examples.
45
45
 
46
46
  ## Contributing
47
47
 
data/lib/webpay/mock.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "webpay/mock/version"
2
2
 
3
- module WebPay
3
+ class WebPay
4
4
  module Mock
5
5
  # Your code goes here...
6
6
  end
@@ -3,6 +3,7 @@ class WebPay::Mock::Builder
3
3
  PREFIX = {
4
4
  charge: 'ch',
5
5
  customer: 'cus',
6
+ recursion: 'rec',
6
7
  token: 'tok',
7
8
  event: 'evt',
8
9
  account: 'acct'
@@ -3,12 +3,16 @@ require 'securerandom'
3
3
  module WebPay::Mock::FakeEntity
4
4
  include WebPay::Mock::Util
5
5
 
6
+ def charge_from(params, overrides = {}, base = {})
7
+ Charge.new(base).set_params(params).override(overrides).build
8
+ end
9
+
6
10
  def customer_from(params, overrides = {}, base = {})
7
11
  Customer.new(base).set_params(params).override(overrides).build
8
12
  end
9
13
 
10
- def charge_from(params, overrides = {}, base = {})
11
- Charge.new(base).set_params(params).override(overrides).build
14
+ def recursion_from(params, overrides = {}, base = {})
15
+ Recursion.new(base).set_params(params).override(overrides).build
12
16
  end
13
17
 
14
18
  def token_from(params, overrides = {})
@@ -49,6 +53,7 @@ require 'webpay/mock/fake_entity/base'
49
53
  require 'webpay/mock/fake_entity/card'
50
54
  require 'webpay/mock/fake_entity/charge'
51
55
  require 'webpay/mock/fake_entity/customer'
56
+ require 'webpay/mock/fake_entity/recursion'
52
57
  require 'webpay/mock/fake_entity/token'
53
58
  require 'webpay/mock/fake_entity/event'
54
59
  require 'webpay/mock/fake_entity/account'
@@ -0,0 +1,34 @@
1
+ module WebPay::Mock::FakeEntity
2
+ class Recursion < Base
3
+ def object_name
4
+ 'recursion'
5
+ end
6
+
7
+ def basic_attributes
8
+ {
9
+ amount: 400,
10
+ currency: 'jpy',
11
+ period: 'month',
12
+ customer: 'cus_XXXXXXXXX',
13
+ last_executed: nil,
14
+ next_scheduled: Time.now.to_i,
15
+ status: 'active'
16
+ }
17
+ end
18
+
19
+ def copy_attributes
20
+ [:amount, :currency, :customer, :description, :period]
21
+ end
22
+
23
+ def conversion(key, value)
24
+ case key
25
+ when 'first_scheduled'
26
+ if value
27
+ {
28
+ next_scheduled: value
29
+ }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
- module WebPay
1
+ class WebPay
2
2
  module Mock
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -58,6 +58,19 @@ module WebPay::Mock::WebMockWrapper
58
58
  when :all
59
59
  [:get, '/customers', fake_list('/customers', lambda { customer_from({}, overrides) })]
60
60
  end
61
+ when :recursion, :recursions
62
+ case action.to_sym
63
+ when :create
64
+ [:post, '/recursions', recursion_from(params, overrides)]
65
+ when :retrieve
66
+ [:get, '/recursions/:id', recursion_from({}, { id: id }.merge(overrides))]
67
+ when :resume
68
+ [:post, '/recursions/:id/resume', recursion_from({}, { id: id, status: 'active' }.merge(overrides), base)]
69
+ when :delete
70
+ [:delete, '/recursions/:id', { 'id' => id, 'deleted' => true }]
71
+ when :all
72
+ [:get, '/recursions', fake_list('/recursions', lambda { recursion_from({}, overrides) })]
73
+ end
61
74
  when :token, :tokens
62
75
  case action.to_sym
63
76
  when :create
@@ -104,7 +117,7 @@ module WebPay::Mock::WebMockWrapper
104
117
  { body: response.to_json }
105
118
  end
106
119
 
107
- stub_request(method, base_url + path).with(params).to_return(spec)
120
+ stub_request(method, base_url + path).with(query: hash_including({})).with(params).to_return(spec)
108
121
 
109
122
  JSON.parse(spec[:body])
110
123
  end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe WebPay::Mock::FakeEntity::Recursion do
4
+ include WebPay::Mock::FakeEntity
5
+
6
+ context 'params is empty' do
7
+ subject(:recursion) { recursion_from({}) }
8
+
9
+ specify { expect(recursion['id']).to start_with 'rec_' }
10
+ specify { expect(recursion['object']).to eq 'recursion' }
11
+ specify { expect(recursion['livemode']).to eq false }
12
+ specify { expect(recursion['created']).to be_within(2).of(Time.now.to_i) }
13
+ specify { expect(recursion['amount']).to eq 400 }
14
+ specify { expect(recursion['currency']).to eq 'jpy' }
15
+ specify { expect(recursion['period']).to eq 'month' }
16
+ specify { expect(recursion['customer']).to eq 'cus_XXXXXXXXX' }
17
+ specify { expect(recursion['last_executed']).to eq nil }
18
+ specify { expect(recursion['next_scheduled']).to be_within(2).of(Time.now.to_i) }
19
+ specify { expect(recursion['status']).to eq 'active' }
20
+ end
21
+
22
+ context 'params has amount, currency, customer, description' do
23
+ let(:amount) { 100 }
24
+ let(:currency) { 'usd' }
25
+ let(:customer) { 'cus_YYYYYYYY' }
26
+ let(:description) { 'desc' }
27
+
28
+ subject(:recursion) do
29
+ recursion_from(amount: amount, currency: currency, customer: customer, description: description)
30
+ end
31
+
32
+ specify { expect(recursion['amount']).to eq amount }
33
+ specify { expect(recursion['currency']).to eq currency }
34
+ specify { expect(recursion['customer']).to eq customer }
35
+ specify { expect(recursion['description']).to eq description }
36
+ end
37
+
38
+ context 'params period or first_scheduled' do
39
+ subject(:recursion) do
40
+ recursion_from(period: period, first_scheduled: first_scheduled)
41
+ end
42
+
43
+ context 'params has period and first_scheduled' do
44
+ let(:period) { 'year' }
45
+ let(:first_scheduled) { Time.now.to_i + 60 * 60 * 24 * 10 }
46
+
47
+ specify { expect(recursion['period']).to eq 'year' }
48
+ specify { expect(recursion['last_executed']).to eq nil }
49
+ specify { expect(recursion['next_scheduled']).to eq(first_scheduled) }
50
+ end
51
+
52
+ context 'params has period no first_scheduled' do
53
+ let(:period) { 'year' }
54
+ let(:first_scheduled) { nil }
55
+
56
+ specify { expect(recursion['last_executed']).to eq nil }
57
+ specify { expect(recursion['next_scheduled']).to be_within(2).of(Time.now.to_i) }
58
+ end
59
+ end
60
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,6 @@ require 'webmock/rspec'
2
2
  require 'webpay/mock'
3
3
 
4
4
  RSpec.configure do |config|
5
- config.treat_symbols_as_metadata_keys_with_true_values = true
6
5
  config.run_all_when_everything_filtered = true
7
6
  config.filter_run :focus
8
7
 
@@ -8,79 +8,110 @@ describe WebPay::Mock::WebMockWrapper do
8
8
  # c.include WebPay::Mock::WebMockWrapper
9
9
  # end
10
10
  include WebPay::Mock::WebMockWrapper
11
+ let(:webpay) { WebPay.new('test_secret_xxxxxx') }
11
12
 
12
13
  describe 'charges' do
13
14
  describe 'create' do
14
15
  let(:params) { { amount: 1000, currency: 'jpy', card: 'tok_xxxxxxxxx', description: 'test charge' } }
15
16
  let!(:response) { webpay_stub(:charges, :create, params: params) }
16
17
 
17
- specify { expect(WebPay::Charge.create(params).id).to eq response['id'] }
18
+ specify { expect(webpay.charge.create(params).id).to eq response['id'] }
18
19
  end
19
20
 
20
21
  describe 'retrieve' do
21
22
  let(:id) { 'ch_xxxxxxxxx' }
22
23
  before { webpay_stub(:charges, :retrieve, id: id) }
23
- specify { expect(WebPay::Charge.retrieve(id).id).to eq id }
24
+ specify { expect(webpay.charge.retrieve(id).id).to eq id }
24
25
  end
25
26
 
26
27
  describe 'refund' do
27
28
  let(:id) { 'ch_xxxxxxxxx' }
28
- let!(:retrieved) { webpay_stub(:charges, :retrieve, id: id) }
29
- let!(:refunded) { webpay_stub(:charges, :refund, params: { 'amount' => retrieved['amount'] }, base: retrieved) }
30
- specify { expect(WebPay::Charge.retrieve(id).refund.refunded).to eq true }
29
+ let(:data) { charge_from({amount: 5000}, id: id) }
30
+ let!(:refunded) { webpay_stub(:charges, :refund, params: { 'amount' => data['amount'] }, base: data) }
31
+ specify { expect(webpay.charge.refund(id).refunded).to eq true }
31
32
  end
32
33
 
33
34
  describe 'capture' do
34
35
  let(:id) { 'ch_xxxxxxxxx' }
35
- let!(:retrieved) { webpay_stub(:charges, :retrieve, id: id, overrides: { captured: false } ) }
36
- let!(:captured) { webpay_stub(:charges, :capture, base: retrieved) }
37
- specify { expect(WebPay::Charge.retrieve(id).captured).to eq false }
38
- specify { expect(WebPay::Charge.retrieve(id).capture.captured).to eq true }
36
+ let!(:captured) { webpay_stub(:charges, :capture, params: { id: id }) }
37
+ specify { expect(webpay.charge.capture(id).captured).to eq true }
39
38
  end
40
39
 
41
40
  describe 'all' do
42
41
  before { webpay_stub(:charges, :all) }
43
- specify { expect(WebPay::Charge.all.count).to eq 3 }
42
+ specify { expect(webpay.charge.all.count).to eq 3 }
44
43
  end
45
44
  end
46
45
 
47
46
  describe 'customers' do
48
47
  describe 'create' do
49
48
  let!(:response) { webpay_stub(:customers, :create, params: {}) }
50
- specify { expect(WebPay::Customer.create({}).id).to eq response['id'] }
49
+ specify { expect(webpay.customer.create({}).id).to eq response['id'] }
51
50
  end
52
51
 
53
52
  describe 'retrieve' do
54
53
  let(:id) { 'cus_xxxxxxxxx' }
55
54
  before { webpay_stub(:customers, :retrieve, id: id) }
56
- specify { expect(WebPay::Customer.retrieve(id).id).to eq id }
55
+ specify { expect(webpay.customer.retrieve(id).id).to eq id }
57
56
  end
58
57
 
59
58
  describe 'update' do
60
59
  let(:id) { 'cus_xxxxxxxxx' }
61
- let!(:retrieved) { webpay_stub(:customers, :retrieve, id: id) }
62
- let!(:updated) { webpay_stub(:customers, :update, params: { 'email' => 'new@example.com' }, base: retrieved) }
60
+ let!(:updated) { webpay_stub(:customers, :update, params: { 'email' => 'new@example.com', 'id' => id }) }
63
61
  specify do
64
- customer = WebPay::Customer.retrieve(id)
65
- customer.email = 'new@example.com'
66
- customer.save
67
- expect(customer.email).to eq 'new@example.com'
62
+ response = webpay.customer.update(id: id, email: 'new@example.com')
63
+ expect(response.email).to eq 'new@example.com'
68
64
  end
69
65
  end
70
66
 
71
67
  describe 'delete' do
72
68
  let(:id) { 'cus_xxxxxxxxx' }
73
- let!(:retrieved) { webpay_stub(:customers, :retrieve, id: id) }
74
69
  let!(:updated) { webpay_stub(:customers, :delete, id: id) }
75
70
  specify do
76
- customer = WebPay::Customer.retrieve(id)
77
- expect(customer.delete).to eq true
71
+ customer = webpay.customer.delete(id)
72
+ expect(customer.deleted).to eq true
78
73
  end
79
74
  end
80
75
 
81
76
  describe 'all' do
82
77
  before { webpay_stub(:customers, :all) }
83
- specify { expect(WebPay::Customer.all.count).to eq 3 }
78
+ specify { expect(webpay.customer.all.count).to eq 3 }
79
+ end
80
+ end
81
+
82
+ describe 'recursios' do
83
+ describe 'create' do
84
+ let(:params) { { amount: 1000, currency: 'jpy', customer: 'cus_xxxxxxxxx', period: 'month', description: 'test charge' } }
85
+ let!(:response) { webpay_stub(:recursion, :create, params: params) }
86
+ specify { expect(webpay.recursion.create({}).id).to eq response['id'] }
87
+ end
88
+
89
+ describe 'retrieve' do
90
+ let(:id) { 'rec_xxxxxxxxx' }
91
+ before { webpay_stub(:recursions, :retrieve, id: id) }
92
+ specify { expect(webpay.recursion.retrieve(id).id).to eq id }
93
+ end
94
+
95
+ describe 'resume' do
96
+ let(:id) { 'rec_xxxxxxxxx' }
97
+ let!(:retrieved) { webpay_stub(:recursions, :retrieve, id: id, overrides: { status: 'suspended' }) }
98
+ let!(:resumed) { webpay_stub(:recursions, :resume, base: retrieved) }
99
+ specify { expect(webpay.recursion.retrieve(id).status).to eq 'suspended' }
100
+ specify { expect(webpay.recursion.resume(id).status).to eq 'active' }
101
+ end
102
+
103
+ describe 'delete' do
104
+ let(:id) { 'rec_xxxxxxxxx' }
105
+ let!(:updated) { webpay_stub(:recursions, :delete, id: id) }
106
+ specify do
107
+ recursion = webpay.recursion.delete(id)
108
+ expect(recursion.deleted).to eq true
109
+ end
110
+ end
111
+
112
+ describe 'all' do
113
+ before { webpay_stub(:recursions, :all) }
114
+ specify { expect(webpay.recursion.all.count).to eq 3 }
84
115
  end
85
116
  end
86
117
 
@@ -92,13 +123,13 @@ describe WebPay::Mock::WebMockWrapper do
92
123
  :cvc=>"123",
93
124
  :name=>"KIYOKI IPPYO"} }
94
125
  let!(:response) { webpay_stub(:tokens, :create, params: card_params) }
95
- specify { expect(WebPay::Token.create(card: card_params).id).to eq response['id'] }
126
+ specify { expect(webpay.token.create(card: card_params).id).to eq response['id'] }
96
127
  end
97
128
 
98
129
  describe 'retrieve' do
99
130
  let(:id) { 'tok_xxxxxxxxx' }
100
131
  before { webpay_stub(:tokens, :retrieve, id: id) }
101
- specify { expect(WebPay::Token.retrieve(id).id).to eq id }
132
+ specify { expect(webpay.token.retrieve(id).id).to eq id }
102
133
  end
103
134
  end
104
135
 
@@ -106,24 +137,24 @@ describe WebPay::Mock::WebMockWrapper do
106
137
  describe 'retrieve' do
107
138
  let(:id) { 'evt_xxxxxxxxx' }
108
139
  before { webpay_stub(:events, :retrieve, id: id) }
109
- specify { expect(WebPay::Event.retrieve(id).id).to eq id }
140
+ specify { expect(webpay.event.retrieve(id).id).to eq id }
110
141
  end
111
142
 
112
143
  describe 'all' do
113
144
  before { webpay_stub(:events, :all) }
114
- specify { expect(WebPay::Event.all.count).to eq 3 }
145
+ specify { expect(webpay.event.all.count).to eq 3 }
115
146
  end
116
147
  end
117
148
 
118
149
  describe 'account' do
119
150
  describe 'retrieve' do
120
151
  before { webpay_stub(:account, :retrieve) }
121
- specify { expect(WebPay::Account.retrieve.id).to start_with 'acct_' }
152
+ specify { expect(webpay.account.retrieve.id).to start_with 'acct_' }
122
153
  end
123
154
 
124
155
  describe 'delete_data' do
125
156
  before { webpay_stub(:account, :delete_data) }
126
- specify { expect(WebPay::Account.delete_data).to eq true }
157
+ specify { expect(webpay.account.delete_data.deleted).to eq true }
127
158
  end
128
159
  end
129
160
  end
data/webpay-mock.gemspec CHANGED
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'webmock', '~> 1.13.0'
21
+ spec.add_dependency 'webmock', '~> 1.18.0'
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
- spec.add_development_dependency 'rspec', '~> 2.14.0'
26
- spec.add_development_dependency 'webpay', '~> 2.1.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'webpay', '~> 3.0.0'
27
27
  end
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.0.1
4
+ version: 0.1.1
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-04-09 00:00:00.000000000 Z
12
+ date: 2014-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: webmock
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: 1.13.0
20
+ version: 1.18.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: 1.13.0
27
+ version: 1.18.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -59,28 +59,28 @@ dependencies:
59
59
  requirements:
60
60
  - - ~>
61
61
  - !ruby/object:Gem::Version
62
- version: 2.14.0
62
+ version: '3.0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 2.14.0
69
+ version: '3.0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: webpay
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- version: 2.1.0
76
+ version: 3.0.0
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ~>
82
82
  - !ruby/object:Gem::Version
83
- version: 2.1.0
83
+ version: 3.0.0
84
84
  description: WebPay::Mock helps development of WebPay client applications
85
85
  email:
86
86
  - administrators@webpay.jp
@@ -104,6 +104,7 @@ files:
104
104
  - lib/webpay/mock/fake_entity/charge.rb
105
105
  - lib/webpay/mock/fake_entity/customer.rb
106
106
  - lib/webpay/mock/fake_entity/event.rb
107
+ - lib/webpay/mock/fake_entity/recursion.rb
107
108
  - lib/webpay/mock/fake_entity/token.rb
108
109
  - lib/webpay/mock/fake_error.rb
109
110
  - lib/webpay/mock/util.rb
@@ -113,6 +114,7 @@ files:
113
114
  - spec/fake_entity/charge_spec.rb
114
115
  - spec/fake_entity/customer_spec.rb
115
116
  - spec/fake_entity/event_spec.rb
117
+ - spec/fake_entity/recursion_spec.rb
116
118
  - spec/fake_entity/token_spec.rb
117
119
  - spec/fake_entity_spec.rb
118
120
  - spec/spec_helper.rb
@@ -147,7 +149,9 @@ test_files:
147
149
  - spec/fake_entity/charge_spec.rb
148
150
  - spec/fake_entity/customer_spec.rb
149
151
  - spec/fake_entity/event_spec.rb
152
+ - spec/fake_entity/recursion_spec.rb
150
153
  - spec/fake_entity/token_spec.rb
151
154
  - spec/fake_entity_spec.rb
152
155
  - spec/spec_helper.rb
153
156
  - spec/webmock_wrapper_spec.rb
157
+ has_rdoc: