webpay-mock 0.1.1 → 0.1.2

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: f0f052e8210caccab939a6bb84e2a27bfbdd3e05
4
- data.tar.gz: 0c1d5335bbc63fac0fb61d3d34b3ab564b8733bd
3
+ metadata.gz: 3c646a455055caf1fe597bf977b68a7e54582f82
4
+ data.tar.gz: 98dfd0e1aa816edc408d15ab865020c6a1ee213a
5
5
  SHA512:
6
- metadata.gz: 2df12a63be1ed292e7cec629cca83ea72687139e17c9ebd85e140352809193a448df0d280eaec52ced57bd92449520a143951dd09c26136edd2c9d4e9a781296
7
- data.tar.gz: 1bb7b8e0230ba0bfe567654fbc86b1e26e3a7597217d21b63065c19c0d3f3e8cfbd9f7e29dbe3dde2ed53c2ce18f3b07ed2de8d4b9085e0860689742b7203708
6
+ metadata.gz: 4d6c2ff3ec10265b66b9fc73baee8be3796e723c854a8160cdd4417507abaf428966a94c4ebc71f2843133877fa50a34b2cfda5e0e82153059ccda3dae3a40c6
7
+ data.tar.gz: 0403e897c37fb52d9db7a718e3faf1aac7ad30844da973c8e5512aca98b75a8daab8c280ff2e2c12a641f3e5bbb4531eb6d0f9f05b3285771f125bc57531804c
data/.travis.yml CHANGED
@@ -1,11 +1,16 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
- - 2.0.0
4
+ - 2.1.2
5
5
  - jruby-head
6
- - rbx-2.1.1
6
+ - jruby-1.7
7
+ - rbx-2.2.7
7
8
  script: "bundle exec rake"
8
9
  notifications:
9
10
  hipchat:
10
11
  rooms:
11
12
  secure: ykLsXlebzR9nnb+9ttpCySOg2hE4Ve699s2Owd7YahcZyVNxnG4q1P8Mps4jFlOgPNQ6JwkcB4A6QLavavtJlX7vXTDj1GD+zVAScjbtN/6ZV94S2eHA7hBUXHUwBmH0Cw5glrFoPEDBsQdOYbrOrJKwFNEhUTHdY0SRgEXv5Wo=
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: jruby-head # cryptic gemspec problem in f444c68
16
+ - rvm: rbx-2.2.7
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # WebPay::Mock
1
+ # WebPay::Mock [![Build Status](https://travis-ci.org/webpay/webpay-mock.svg)](https://travis-ci.org/webpay/webpay-mock)
2
2
 
3
3
  WebPay::Mock helps development of WebPay client applications.
4
4
 
@@ -43,6 +43,35 @@ specify { expect(webpay.charge.create(params).id).to eq response['id'] }
43
43
 
44
44
  See [our test cases](https://github.com/webpay/webpay-mock/blob/master/spec/webmock_wrapper_spec.rb) for more examples.
45
45
 
46
+ ### Testing error responses
47
+
48
+ Just return an error by type.
49
+
50
+ ```ruby
51
+ webpay_stub(:charges, :create, error: :card_error, params: params)
52
+ ```
53
+
54
+ Error kinds are:
55
+
56
+ - bad_request (400)
57
+ - unauthorized (401)
58
+ - card_error (402)
59
+ - not_found (404)
60
+ - internal_server_error (500)
61
+
62
+ Specify all fields to test a specific error.
63
+
64
+ ```ruby
65
+ webpay_stub(:charges, :create, params: params, response: card_error(
66
+ message: "You must provide the card which is not expired",
67
+ caused_by: "buyer",
68
+ param: "exp_month",
69
+ code: "invalid_expiry_month"
70
+ ))
71
+ ```
72
+
73
+ For up-to-date details about error structure, see [API error document](https://webpay.jp/docs/api_errors) on our website.
74
+
46
75
  ## Contributing
47
76
 
48
77
  1. Fork it
@@ -5,7 +5,14 @@ module WebPay::Mock::FakeEntity
5
5
  end
6
6
 
7
7
  def basic_attributes
8
- { statement_descriptor: nil, details_submitted: false, charge_enabled: false, currencies_supported: ["jpy"], email: 'test@example.com' }
8
+ {
9
+ charge_enabled: false,
10
+ currencies_supported: ["jpy"],
11
+ details_submitted: false,
12
+ email: 'test@example.com',
13
+ statement_descriptor: nil,
14
+ card_types_supported: ["Visa", "American Express", "MasterCard", "JCB", "Diners Club"],
15
+ }
9
16
  end
10
17
 
11
18
  def copy_attributes
@@ -5,7 +5,29 @@ module WebPay::Mock::FakeEntity
5
5
  end
6
6
 
7
7
  def basic_attributes
8
- { amount: 1000, currency: 'jpy', amount_refunded: 0, paid: true, refunded: false, failure_message: nil, captured: true, expire_time: nil, card: fake_card }
8
+ {
9
+ amount: 1000,
10
+ card: fake_card,
11
+ currency: 'jpy',
12
+ paid: true,
13
+ captured: true,
14
+ refunded: false,
15
+ amount_refunded: 0,
16
+ customer: nil,
17
+ shop: nil,
18
+ recursion: nil,
19
+ description: nil,
20
+ failure_message: nil,
21
+ expire_time: nil,
22
+ fees: [{
23
+ object: 'fee',
24
+ transaction_type: 'payment',
25
+ transaction_fee: 0,
26
+ rate: 3.25,
27
+ amount: 33,
28
+ created: Time.now.to_i
29
+ }]
30
+ }
9
31
  end
10
32
 
11
33
  def copy_attributes
@@ -5,7 +5,7 @@ module WebPay::Mock::FakeEntity
5
5
  end
6
6
 
7
7
  def basic_attributes
8
- { email: nil, description: nil, active_card: nil }
8
+ { email: nil, description: nil, active_card: nil, recursions: [] }
9
9
  end
10
10
 
11
11
  def copy_attributes
@@ -10,8 +10,8 @@ module WebPay::Mock::FakeEntity
10
10
  currency: 'jpy',
11
11
  period: 'month',
12
12
  customer: 'cus_XXXXXXXXX',
13
- last_executed: nil,
14
- next_scheduled: Time.now.to_i,
13
+ last_executed: Time.now.to_i,
14
+ next_scheduled: Time.now.to_i + 30 * 24 * 60 * 60,
15
15
  status: 'active'
16
16
  }
17
17
  end
@@ -25,6 +25,7 @@ module WebPay::Mock::FakeEntity
25
25
  when 'first_scheduled'
26
26
  if value
27
27
  {
28
+ last_executed: nil,
28
29
  next_scheduled: value
29
30
  }
30
31
  end
@@ -1,5 +1,5 @@
1
1
  class WebPay
2
2
  module Mock
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -94,6 +94,10 @@ module WebPay::Mock::WebMockWrapper
94
94
  end
95
95
  end
96
96
 
97
+ unless path
98
+ raise ArgumentError.new("Unknown entity or action is given to webpay_stub()")
99
+ end
100
+
97
101
  if path.include?(':id')
98
102
  if id.nil? || id == ''
99
103
  raise ArgumentError.new(":id in parameters is required")
@@ -101,7 +105,7 @@ module WebPay::Mock::WebMockWrapper
101
105
  path = path.gsub(':id', id)
102
106
  end
103
107
 
104
- spec =
108
+ spec = options[:response] ||
105
109
  case options[:error]
106
110
  when :bad_request
107
111
  bad_request
@@ -14,8 +14,8 @@ describe WebPay::Mock::FakeEntity::Recursion do
14
14
  specify { expect(recursion['currency']).to eq 'jpy' }
15
15
  specify { expect(recursion['period']).to eq 'month' }
16
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) }
17
+ specify { expect(recursion['last_executed']).to be_within(2).of(Time.now.to_i) }
18
+ specify { expect(recursion['next_scheduled']).to be_within(2).of(Time.now.to_i + 30 * 24 * 60 * 60) }
19
19
  specify { expect(recursion['status']).to eq 'active' }
20
20
  end
21
21
 
@@ -48,13 +48,5 @@ describe WebPay::Mock::FakeEntity::Recursion do
48
48
  specify { expect(recursion['last_executed']).to eq nil }
49
49
  specify { expect(recursion['next_scheduled']).to eq(first_scheduled) }
50
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
51
  end
60
52
  end
@@ -18,12 +18,41 @@ describe WebPay::Mock::WebMockWrapper do
18
18
  specify { expect(webpay.charge.create(params).id).to eq response['id'] }
19
19
  end
20
20
 
21
+ describe 'create responds card error' do
22
+ let(:params) { { amount: 1000, currency: 'jpy', card: 'tok_xxxxxxxxx', description: 'test charge' } }
23
+ let!(:response) { webpay_stub(:charges, :create, error: :card_error, params: params) }
24
+
25
+ specify { expect { webpay.charge.create(params).id }.to raise_error(WebPay::ErrorResponse::CardError) }
26
+ end
27
+
28
+ describe 'create responds card error with specified cause' do
29
+ let(:params) { { amount: 1000, currency: 'jpy', card: 'tok_xxxxxxxxx', description: 'test charge' } }
30
+ let!(:response) { webpay_stub(:charges, :create, params: params, response: card_error(
31
+ message: "You must provide the card which is not expired",
32
+ caused_by: "buyer",
33
+ param: "exp_month",
34
+ code: "invalid_expiry_month"
35
+ )) }
36
+
37
+ specify { expect { webpay.charge.create(params).id }.to raise_error { |e|
38
+ expect(e.data.error.caused_by).to eq 'buyer'
39
+ expect(e.data.error.code).to eq 'invalid_expiry_month'
40
+ } }
41
+ end
42
+
21
43
  describe 'retrieve' do
22
44
  let(:id) { 'ch_xxxxxxxxx' }
23
45
  before { webpay_stub(:charges, :retrieve, id: id) }
24
46
  specify { expect(webpay.charge.retrieve(id).id).to eq id }
25
47
  end
26
48
 
49
+ describe 'retrieve responds not found' do
50
+ let(:params) { { amount: 1000, currency: 'jpy', card: 'tok_xxxxxxxxx', description: 'test charge' } }
51
+ let!(:response) { webpay_stub(:charges, :create, error: :not_found, params: params) }
52
+
53
+ specify { expect { webpay.charge.create(params).id }.to raise_error(WebPay::ErrorResponse::InvalidRequestError) }
54
+ end
55
+
27
56
  describe 'refund' do
28
57
  let(:id) { 'ch_xxxxxxxxx' }
29
58
  let(:data) { charge_from({amount: 5000}, id: id) }
data/webpay-mock.gemspec CHANGED
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency 'rspec', '~> 3.0'
26
- spec.add_development_dependency 'webpay', '~> 3.0.0'
26
+ spec.add_development_dependency 'webpay', '~> 3.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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - webpay
@@ -9,78 +9,78 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-11 00:00:00.000000000 Z
12
+ date: 2014-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: webmock
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
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
27
  version: 1.18.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '1.3'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ~>
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '1.3'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
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
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: 3.0.0
76
+ version: '3.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: 3.0.0
83
+ version: '3.0'
84
84
  description: WebPay::Mock helps development of WebPay client applications
85
85
  email:
86
86
  - administrators@webpay.jp
@@ -89,8 +89,8 @@ executables: []
89
89
  extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
- - .gitignore
93
- - .travis.yml
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
94
  - Gemfile
95
95
  - LICENSE.txt
96
96
  - README.md
@@ -130,17 +130,17 @@ require_paths:
130
130
  - lib
131
131
  required_ruby_version: !ruby/object:Gem::Requirement
132
132
  requirements:
133
- - - '>='
133
+ - - ">="
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - '>='
138
+ - - ">="
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
142
  rubyforge_project:
143
- rubygems_version: 2.0.14
143
+ rubygems_version: 2.2.2
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Dummy response generator and wrapper of webmock gem for WebPay
@@ -154,4 +154,3 @@ test_files:
154
154
  - spec/fake_entity_spec.rb
155
155
  - spec/spec_helper.rb
156
156
  - spec/webmock_wrapper_spec.rb
157
- has_rdoc: