simplify the http stubs
This commit is contained in:
parent
4b41756cfa
commit
1315d240e6
|
@ -1,5 +1,4 @@
|
|||
require 'rails_helper'
|
||||
require_relative '../../support/dd_helper'
|
||||
|
||||
shared_examples 'failure response' do |message_key|
|
||||
let(:body) { JSON.parse(response.body) }
|
||||
|
@ -87,30 +86,7 @@ module DiscourseDonations
|
|||
"tax_info_verification": "null"
|
||||
}
|
||||
|
||||
stub_request(:get, "https://api.stripe.com/v1/customers?email=foobar@example.com").
|
||||
with(
|
||||
headers: {
|
||||
'Accept' => '*/*',
|
||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization' => 'Bearer secret-key-yo',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'User-Agent' => 'Stripe/v1 RubyBindings/2.8.0',
|
||||
'X-Stripe-Client-User-Agent' => '{"bindings_version":"2.8.0","lang":"ruby","lang_version":"2.6.2 p47 (2019-03-13)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin 192-168-1-102.tpgi.com.au 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64","hostname":"192-168-1-102.tpgi.com.au"}'
|
||||
}).
|
||||
to_return(status: 200, body: customer.to_json, headers: {})
|
||||
|
||||
stub_request(:post, "https://api.stripe.com/v1/customers").
|
||||
with(
|
||||
body: { "email" => "foobar@example.com" },
|
||||
headers: {
|
||||
'Accept' => '*/*',
|
||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization' => 'Bearer secret-key-yo',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'User-Agent' => 'Stripe/v1 RubyBindings/2.8.0',
|
||||
'X-Stripe-Client-User-Agent' => '{"bindings_version":"2.8.0","lang":"ruby","lang_version":"2.6.2 p47 (2019-03-13)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin 192-168-1-102.tpgi.com.au 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64","hostname":"192-168-1-102.tpgi.com.au"}'
|
||||
}).
|
||||
to_return(status: 200, body: customer.to_json, headers: {})
|
||||
stub_request(:get, /v1\/customers/).to_return(status: 200, body: customer.to_json)
|
||||
|
||||
plans = {
|
||||
"object": "list",
|
||||
|
@ -142,30 +118,8 @@ module DiscourseDonations
|
|||
]
|
||||
}
|
||||
|
||||
stub_request(:get, "https://api.stripe.com/v1/plans").
|
||||
with(
|
||||
headers: {
|
||||
'Accept' => '*/*',
|
||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization' => 'Bearer secret-key-yo',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'User-Agent' => 'Stripe/v1 RubyBindings/2.8.0',
|
||||
'X-Stripe-Client-User-Agent' => '{"bindings_version":"2.8.0","lang":"ruby","lang_version":"2.6.2 p47 (2019-03-13)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin 192-168-1-102.tpgi.com.au 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64","hostname":"192-168-1-102.tpgi.com.au"}'
|
||||
}).
|
||||
to_return(status: 200, body: plans.to_json, headers: {})
|
||||
|
||||
stub_request(:post, "https://api.stripe.com/v1/plans").
|
||||
with(
|
||||
body: { "amount" => "0", "currency" => "AUD", "id" => "discourse_donation_recurring__", "nickname" => "Discourse Donation Recurring " },
|
||||
headers: {
|
||||
'Accept' => '*/*',
|
||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization' => 'Bearer secret-key-yo',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'User-Agent' => 'Stripe/v1 RubyBindings/2.8.0',
|
||||
'X-Stripe-Client-User-Agent' => '{"bindings_version":"2.8.0","lang":"ruby","lang_version":"2.6.2 p47 (2019-03-13)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin 192-168-1-102.tpgi.com.au 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64","hostname":"192-168-1-102.tpgi.com.au"}'
|
||||
}).
|
||||
to_return(status: 200, body: plans.to_json, headers: {})
|
||||
stub_request(:get, "https://api.stripe.com/v1/plans").to_return(status: 200, body: plans.to_json)
|
||||
stub_request(:post, "https://api.stripe.com/v1/plans").to_return(status: 200, body: plans.to_json)
|
||||
|
||||
products = {
|
||||
"object": "list",
|
||||
|
@ -196,43 +150,9 @@ module DiscourseDonations
|
|||
]
|
||||
}
|
||||
|
||||
stub_request(:get, "https://api.stripe.com/v1/products?type=service").
|
||||
with(
|
||||
headers: {
|
||||
'Accept' => '*/*',
|
||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization' => 'Bearer secret-key-yo',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'User-Agent' => 'Stripe/v1 RubyBindings/2.8.0',
|
||||
'X-Stripe-Client-User-Agent' => '{"bindings_version":"2.8.0","lang":"ruby","lang_version":"2.6.2 p47 (2019-03-13)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin 192-168-1-102.tpgi.com.au 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64","hostname":"192-168-1-102.tpgi.com.au"}'
|
||||
}).
|
||||
to_return(status: 200, body: products.to_json, headers: {})
|
||||
|
||||
stub_request(:post, "https://api.stripe.com/v1/products").
|
||||
with(
|
||||
body: { "id" => "Discourse_recurring_donation", "name" => "Discourse Recurring Donation", "type" => "service" },
|
||||
headers: {
|
||||
'Accept' => '*/*',
|
||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization' => 'Bearer secret-key-yo',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'User-Agent' => 'Stripe/v1 RubyBindings/2.8.0',
|
||||
'X-Stripe-Client-User-Agent' => '{"bindings_version":"2.8.0","lang":"ruby","lang_version":"2.6.2 p47 (2019-03-13)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin 192-168-1-102.tpgi.com.au 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64","hostname":"192-168-1-102.tpgi.com.au"}'
|
||||
}).
|
||||
to_return(status: 200, body: products.to_json, headers: {})
|
||||
|
||||
stub_request(:post, "https://api.stripe.com/v1/customers").
|
||||
with(
|
||||
body: { "email" => "foobar@example.com", "metadata" => { "discourse_user_id" => "1" } },
|
||||
headers: {
|
||||
'Accept' => '*/*',
|
||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization' => 'Bearer secret-key-yo',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'User-Agent' => 'Stripe/v1 RubyBindings/2.8.0',
|
||||
'X-Stripe-Client-User-Agent' => '{"bindings_version":"2.8.0","lang":"ruby","lang_version":"2.6.2 p47 (2019-03-13)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin 192-168-1-102.tpgi.com.au 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64","hostname":"192-168-1-102.tpgi.com.au"}'
|
||||
}).
|
||||
to_return(status: 200, body: customer.to_json, headers: {})
|
||||
stub_request(:get, "https://api.stripe.com/v1/products?type=service").to_return(status: 200, body: products.to_json)
|
||||
stub_request(:post, "https://api.stripe.com/v1/products").to_return(status: 200, body: products.to_json)
|
||||
stub_request(:post, "https://api.stripe.com/v1/customers").to_return(status: 200, body: customer.to_json)
|
||||
|
||||
subscription = {
|
||||
"id": "sub_8epEF0PuRhmltU",
|
||||
|
@ -331,30 +251,7 @@ module DiscourseDonations
|
|||
"trial_start": "null"
|
||||
}
|
||||
|
||||
stub_request(:post, "https://api.stripe.com/v1/subscriptions").
|
||||
with(
|
||||
body: { "customer" => "cus_FhHJDzf0OxYtb8", "metadata" => { "discourse_user_id" => "1" } },
|
||||
headers: {
|
||||
'Accept' => '*/*',
|
||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization' => 'Bearer secret-key-yo',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'User-Agent' => 'Stripe/v1 RubyBindings/2.8.0',
|
||||
'X-Stripe-Client-User-Agent' => '{"bindings_version":"2.8.0","lang":"ruby","lang_version":"2.6.2 p47 (2019-03-13)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin 192-168-1-102.tpgi.com.au 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64","hostname":"192-168-1-102.tpgi.com.au"}'
|
||||
}).
|
||||
to_return(status: 200, body: subscription.to_json, headers: {})
|
||||
|
||||
stub_request(:get, "https://api.stripe.com/v1/customers/cus_FhHJDzf0OxYtb8").
|
||||
with(
|
||||
headers: {
|
||||
'Accept' => '*/*',
|
||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization' => 'Bearer secret-key-yo',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'User-Agent' => 'Stripe/v1 RubyBindings/2.8.0',
|
||||
'X-Stripe-Client-User-Agent' => '{"bindings_version":"2.8.0","lang":"ruby","lang_version":"2.6.2 p47 (2019-03-13)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin 192-168-1-102.tpgi.com.au 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64","hostname":"192-168-1-102.tpgi.com.au"}'
|
||||
}).
|
||||
to_return(status: 200, body: customer.to_json, headers: {})
|
||||
stub_request(:post, "https://api.stripe.com/v1/subscriptions").to_return(status: 200, body: subscription.to_json)
|
||||
|
||||
invoices = {
|
||||
"object": "list",
|
||||
|
@ -479,17 +376,8 @@ module DiscourseDonations
|
|||
]
|
||||
}
|
||||
|
||||
stub_request(:get, "https://api.stripe.com/v1/invoices?customer=cus_FhHJDzf0OxYtb8&subscription=sub_8epEF0PuRhmltU").
|
||||
with(
|
||||
headers: {
|
||||
'Accept' => '*/*',
|
||||
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
||||
'Authorization' => 'Bearer secret-key-yo',
|
||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
||||
'User-Agent' => 'Stripe/v1 RubyBindings/2.8.0',
|
||||
'X-Stripe-Client-User-Agent' => '{"bindings_version":"2.8.0","lang":"ruby","lang_version":"2.6.2 p47 (2019-03-13)","platform":"x86_64-darwin18","engine":"ruby","publisher":"stripe","uname":"Darwin 192-168-1-102.tpgi.com.au 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64","hostname":"192-168-1-102.tpgi.com.au"}'
|
||||
}).
|
||||
to_return(status: 200, body: invoices.to_json, headers: {})
|
||||
stub_request(:get, "https://api.stripe.com/v1/invoices?customer=cus_FhHJDzf0OxYtb8&subscription=sub_8epEF0PuRhmltU")
|
||||
.to_return(status: 200, body: invoices.to_json)
|
||||
|
||||
post :create, params: { email: 'foobar@example.com' }, format: :json
|
||||
expect(body['messages'][0]).to end_with(I18n.t('donations.payment.success'))
|
||||
|
|
Loading…
Reference in New Issue