mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-03-08 18:49:15 +00:00
simplify the http stubs
This commit is contained in:
parent
4b41756cfa
commit
1315d240e6
@ -1,5 +1,4 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
require_relative '../../support/dd_helper'
|
|
||||||
|
|
||||||
shared_examples 'failure response' do |message_key|
|
shared_examples 'failure response' do |message_key|
|
||||||
let(:body) { JSON.parse(response.body) }
|
let(:body) { JSON.parse(response.body) }
|
||||||
@ -87,30 +86,7 @@ module DiscourseDonations
|
|||||||
"tax_info_verification": "null"
|
"tax_info_verification": "null"
|
||||||
}
|
}
|
||||||
|
|
||||||
stub_request(:get, "https://api.stripe.com/v1/customers?email=foobar@example.com").
|
stub_request(:get, /v1\/customers/).to_return(status: 200, body: customer.to_json)
|
||||||
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: {})
|
|
||||||
|
|
||||||
plans = {
|
plans = {
|
||||||
"object": "list",
|
"object": "list",
|
||||||
@ -142,30 +118,8 @@ module DiscourseDonations
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
stub_request(:get, "https://api.stripe.com/v1/plans").
|
stub_request(:get, "https://api.stripe.com/v1/plans").to_return(status: 200, body: plans.to_json)
|
||||||
with(
|
stub_request(:post, "https://api.stripe.com/v1/plans").to_return(status: 200, body: plans.to_json)
|
||||||
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: {})
|
|
||||||
|
|
||||||
products = {
|
products = {
|
||||||
"object": "list",
|
"object": "list",
|
||||||
@ -196,43 +150,9 @@ module DiscourseDonations
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
stub_request(:get, "https://api.stripe.com/v1/products?type=service").
|
stub_request(:get, "https://api.stripe.com/v1/products?type=service").to_return(status: 200, body: products.to_json)
|
||||||
with(
|
stub_request(:post, "https://api.stripe.com/v1/products").to_return(status: 200, body: products.to_json)
|
||||||
headers: {
|
stub_request(:post, "https://api.stripe.com/v1/customers").to_return(status: 200, body: customer.to_json)
|
||||||
'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: {})
|
|
||||||
|
|
||||||
subscription = {
|
subscription = {
|
||||||
"id": "sub_8epEF0PuRhmltU",
|
"id": "sub_8epEF0PuRhmltU",
|
||||||
@ -331,30 +251,7 @@ module DiscourseDonations
|
|||||||
"trial_start": "null"
|
"trial_start": "null"
|
||||||
}
|
}
|
||||||
|
|
||||||
stub_request(:post, "https://api.stripe.com/v1/subscriptions").
|
stub_request(:post, "https://api.stripe.com/v1/subscriptions").to_return(status: 200, body: subscription.to_json)
|
||||||
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: {})
|
|
||||||
|
|
||||||
invoices = {
|
invoices = {
|
||||||
"object": "list",
|
"object": "list",
|
||||||
@ -479,17 +376,8 @@ module DiscourseDonations
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
stub_request(:get, "https://api.stripe.com/v1/invoices?customer=cus_FhHJDzf0OxYtb8&subscription=sub_8epEF0PuRhmltU").
|
stub_request(:get, "https://api.stripe.com/v1/invoices?customer=cus_FhHJDzf0OxYtb8&subscription=sub_8epEF0PuRhmltU")
|
||||||
with(
|
.to_return(status: 200, body: invoices.to_json)
|
||||||
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: {})
|
|
||||||
|
|
||||||
post :create, params: { email: 'foobar@example.com' }, format: :json
|
post :create, params: { email: 'foobar@example.com' }, format: :json
|
||||||
expect(body['messages'][0]).to end_with(I18n.t('donations.payment.success'))
|
expect(body['messages'][0]).to end_with(I18n.t('donations.payment.success'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user