mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-07-08 15:22:46 +00:00
name space fabricators. add plans
This commit is contained in:
parent
c8bcc1eb28
commit
53b1e47216
@ -35,42 +35,14 @@ module DiscourseDonations
|
|||||||
it 'responds ok for anonymous users' do
|
it 'responds ok for anonymous users' do
|
||||||
controller.expects(:current_user).at_least(1).returns(user)
|
controller.expects(:current_user).at_least(1).returns(user)
|
||||||
|
|
||||||
customer = Fabricate(:customer)
|
customer = Fabricate(:stripe_customer).to_json
|
||||||
|
|
||||||
stub_request(:get, /v1\/customers/).to_return(status: 200, body: customer.to_json)
|
stub_request(:get, /v1\/customers/).to_return(status: 200, body: customer)
|
||||||
|
|
||||||
plans = {
|
plans = Fabricate(:stripe_plans).to_json
|
||||||
"object": "list",
|
|
||||||
"url": "/v1/plans",
|
|
||||||
"has_more": false,
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"id": "plan_EeE4ns3bvb34ZP",
|
|
||||||
"object": "plan",
|
|
||||||
"active": true,
|
|
||||||
"aggregate_usage": "null",
|
|
||||||
"amount": 3000,
|
|
||||||
"amount_decimal": "3000",
|
|
||||||
"billing_scheme": "per_unit",
|
|
||||||
"created": 1551862832,
|
|
||||||
"currency": "usd",
|
|
||||||
"interval": "month",
|
|
||||||
"interval_count": 1,
|
|
||||||
"livemode": false,
|
|
||||||
"metadata": {},
|
|
||||||
"nickname": "Pro Plan",
|
|
||||||
"product": "prod_BT942zL7VcClrn",
|
|
||||||
"tiers": "null",
|
|
||||||
"tiers_mode": "null",
|
|
||||||
"transform_usage": "null",
|
|
||||||
"trial_period_days": "null",
|
|
||||||
"usage_type": "licensed"
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
stub_request(:get, "https://api.stripe.com/v1/plans").to_return(status: 200, body: plans.to_json)
|
stub_request(:get, "https://api.stripe.com/v1/plans").to_return(status: 200, body: plans)
|
||||||
stub_request(:post, "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)
|
||||||
|
|
||||||
products = {
|
products = {
|
||||||
"object": "list",
|
"object": "list",
|
||||||
@ -103,7 +75,7 @@ module DiscourseDonations
|
|||||||
|
|
||||||
stub_request(:get, "https://api.stripe.com/v1/products?type=service").to_return(status: 200, body: products.to_json)
|
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/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)
|
stub_request(:post, "https://api.stripe.com/v1/customers").to_return(status: 200, body: customer)
|
||||||
|
|
||||||
subscription = {
|
subscription = {
|
||||||
"id": "sub_8epEF0PuRhmltU",
|
"id": "sub_8epEF0PuRhmltU",
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
|
|
||||||
|
Fabricator(:stripe_customer, from: "DiscourseDonations::StripeResponse") do
|
||||||
class Customer
|
|
||||||
attr_accessor :to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
Fabricator(:customer) do
|
|
||||||
response = {
|
response = {
|
||||||
"id": "cus_FhHJDzf0OxYtb8",
|
"id": "cus_FhHJDzf0OxYtb8",
|
||||||
"object": "customer",
|
"object": "customer",
|
||||||
|
34
spec/fabricators/plans_fabricator.rb
Normal file
34
spec/fabricators/plans_fabricator.rb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
Fabricator(:stripe_plans, from: "DiscourseDonations::StripeResponse") do
|
||||||
|
response = {
|
||||||
|
"object": "list",
|
||||||
|
"url": "/v1/plans",
|
||||||
|
"has_more": false,
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": "plan_EeE4ns3bvb34ZP",
|
||||||
|
"object": "plan",
|
||||||
|
"active": true,
|
||||||
|
"aggregate_usage": "null",
|
||||||
|
"amount": 3000,
|
||||||
|
"amount_decimal": "3000",
|
||||||
|
"billing_scheme": "per_unit",
|
||||||
|
"created": 1551862832,
|
||||||
|
"currency": "usd",
|
||||||
|
"interval": "month",
|
||||||
|
"interval_count": 1,
|
||||||
|
"livemode": false,
|
||||||
|
"metadata": {},
|
||||||
|
"nickname": "Pro Plan",
|
||||||
|
"product": "prod_BT942zL7VcClrn",
|
||||||
|
"tiers": "null",
|
||||||
|
"tiers_mode": "null",
|
||||||
|
"transform_usage": "null",
|
||||||
|
"trial_period_days": "null",
|
||||||
|
"usage_type": "licensed"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}.to_json
|
||||||
|
|
||||||
|
to_json response
|
||||||
|
end
|
10
spec/fabricators/stripe_response.rb
Normal file
10
spec/fabricators/stripe_response.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
# This is for building http responses with Fabricate
|
||||||
|
# Usage: Fabricate(:customer).to_json
|
||||||
|
# See: https://stripe.com/docs/api
|
||||||
|
|
||||||
|
module DiscourseDonations
|
||||||
|
class StripeResponse
|
||||||
|
attr_accessor :to_json
|
||||||
|
end
|
||||||
|
end
|
@ -1,2 +1,4 @@
|
|||||||
|
|
||||||
|
require_relative './fabricators/stripe_response.rb'
|
||||||
require_relative './fabricators/customer_fabricator.rb'
|
require_relative './fabricators/customer_fabricator.rb'
|
||||||
|
require_relative './fabricators/plans_fabricator.rb'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user