mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-07-08 07:12:46 +00:00
DEV: fix backend tests
After the engine url got moved to /subscriptions, the tests had to be adapted. The subscribe controller does not return products anymore after moving to the stripe pricing table, so the respective tests were removed.
This commit is contained in:
parent
411ac6ec80
commit
fcc414dbbe
@ -12,7 +12,7 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||||||
context "when unauthenticated" do
|
context "when unauthenticated" do
|
||||||
it "does nothing" do
|
it "does nothing" do
|
||||||
::Stripe::PromotionCode.expects(:list).never
|
::Stripe::PromotionCode.expects(:list).never
|
||||||
get "/s/admin/coupons.json"
|
get "/subscriptions/admin/coupons.json"
|
||||||
expect(response.status).to eq(404)
|
expect(response.status).to eq(404)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -29,7 +29,7 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||||||
.with({ limit: 100 })
|
.with({ limit: 100 })
|
||||||
.returns({ data: [{ id: "promo_123", coupon: { valid: true } }] })
|
.returns({ data: [{ id: "promo_123", coupon: { valid: true } }] })
|
||||||
|
|
||||||
get "/s/admin/coupons.json"
|
get "/subscriptions/admin/coupons.json"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.parsed_body[0]["id"]).to eq("promo_123")
|
expect(response.parsed_body[0]["id"]).to eq("promo_123")
|
||||||
end
|
end
|
||||||
@ -40,7 +40,7 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||||||
.with({ limit: 100 })
|
.with({ limit: 100 })
|
||||||
.returns({ data: [{ id: "promo_123", coupon: { valid: false } }] })
|
.returns({ data: [{ id: "promo_123", coupon: { valid: false } }] })
|
||||||
|
|
||||||
get "/s/admin/coupons.json"
|
get "/subscriptions/admin/coupons.json"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.parsed_body).to be_blank
|
expect(response.parsed_body).to be_blank
|
||||||
end
|
end
|
||||||
@ -53,7 +53,7 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||||||
{ code: "p123", coupon: { amount_off: 2000 } },
|
{ code: "p123", coupon: { amount_off: 2000 } },
|
||||||
)
|
)
|
||||||
|
|
||||||
post "/s/admin/coupons.json",
|
post "/subscriptions/admin/coupons.json",
|
||||||
params: {
|
params: {
|
||||||
promo: "p123",
|
promo: "p123",
|
||||||
discount_type: "amount",
|
discount_type: "amount",
|
||||||
@ -71,7 +71,7 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||||||
{ code: "p123", coupon: { percent_off: 20 } },
|
{ code: "p123", coupon: { percent_off: 20 } },
|
||||||
)
|
)
|
||||||
|
|
||||||
post "/s/admin/coupons.json",
|
post "/subscriptions/admin/coupons.json",
|
||||||
params: {
|
params: {
|
||||||
promo: "p123",
|
promo: "p123",
|
||||||
discount_type: "percent",
|
discount_type: "percent",
|
||||||
@ -84,4 +84,4 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -13,11 +13,11 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
describe "index" do
|
describe "index" do
|
||||||
it "does not get the plans" do
|
it "does not get the plans" do
|
||||||
::Stripe::Price.expects(:list).never
|
::Stripe::Price.expects(:list).never
|
||||||
get "/s/admin/plans.json"
|
get "/subscriptions/admin/plans.json"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "not ok" do
|
it "not ok" do
|
||||||
get "/s/admin/plans.json"
|
get "/subscriptions/admin/plans.json"
|
||||||
expect(response.status).to eq 404
|
expect(response.status).to eq 404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -25,11 +25,11 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
describe "create" do
|
describe "create" do
|
||||||
it "does not create a plan" do
|
it "does not create a plan" do
|
||||||
::Stripe::Price.expects(:create).never
|
::Stripe::Price.expects(:create).never
|
||||||
post "/s/admin/plans.json", params: { name: "Rick Astley", amount: 1, interval: "week" }
|
post "/subscriptions/admin/plans.json", params: { name: "Rick Astley", amount: 1, interval: "week" }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is not ok" do
|
it "is not ok" do
|
||||||
post "/s/admin/plans.json", params: { name: "Rick Astley", amount: 1, interval: "week" }
|
post "/subscriptions/admin/plans.json", params: { name: "Rick Astley", amount: 1, interval: "week" }
|
||||||
expect(response.status).to eq 404
|
expect(response.status).to eq 404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -37,11 +37,11 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
describe "show" do
|
describe "show" do
|
||||||
it "does not show the plan" do
|
it "does not show the plan" do
|
||||||
::Stripe::Price.expects(:retrieve).never
|
::Stripe::Price.expects(:retrieve).never
|
||||||
get "/s/admin/plans/plan_12345.json"
|
get "/subscriptions/admin/plans/plan_12345.json"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is not ok" do
|
it "is not ok" do
|
||||||
get "/s/admin/plans/plan_12345.json"
|
get "/subscriptions/admin/plans/plan_12345.json"
|
||||||
expect(response.status).to eq 404
|
expect(response.status).to eq 404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -49,7 +49,7 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
describe "update" do
|
describe "update" do
|
||||||
it "does not update a plan" do
|
it "does not update a plan" do
|
||||||
::Stripe::Price.expects(:update).never
|
::Stripe::Price.expects(:update).never
|
||||||
delete "/s/admin/plans/plan_12345.json"
|
delete "/subscriptions/admin/plans/plan_12345.json"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -62,19 +62,19 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
describe "index" do
|
describe "index" do
|
||||||
it "lists the plans" do
|
it "lists the plans" do
|
||||||
::Stripe::Price.expects(:list).with(nil)
|
::Stripe::Price.expects(:list).with(nil)
|
||||||
get "/s/admin/plans.json"
|
get "/subscriptions/admin/plans.json"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "lists the plans for the product" do
|
it "lists the plans for the product" do
|
||||||
::Stripe::Price.expects(:list).with({ product: "prod_id123" })
|
::Stripe::Price.expects(:list).with({ product: "prod_id123" })
|
||||||
get "/s/admin/plans.json", params: { product_id: "prod_id123" }
|
get "/subscriptions/admin/plans.json", params: { product_id: "prod_id123" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "show" do
|
describe "show" do
|
||||||
it "shows a plan" do
|
it "shows a plan" do
|
||||||
::Stripe::Price.expects(:retrieve).with("plan_12345").returns(currency: "aud")
|
::Stripe::Price.expects(:retrieve).with("plan_12345").returns(currency: "aud")
|
||||||
get "/s/admin/plans/plan_12345.json"
|
get "/subscriptions/admin/plans/plan_12345.json"
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
.expects(:retrieve)
|
.expects(:retrieve)
|
||||||
.with("plan_12345")
|
.with("plan_12345")
|
||||||
.returns(currency: "aud", recurring: { interval: "year" })
|
.returns(currency: "aud", recurring: { interval: "year" })
|
||||||
get "/s/admin/plans/plan_12345.json"
|
get "/subscriptions/admin/plans/plan_12345.json"
|
||||||
|
|
||||||
plan = response.parsed_body
|
plan = response.parsed_body
|
||||||
expect(plan["currency"]).to eq "AUD"
|
expect(plan["currency"]).to eq "AUD"
|
||||||
@ -94,17 +94,17 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
describe "create" do
|
describe "create" do
|
||||||
it "creates a plan with a nickname" do
|
it "creates a plan with a nickname" do
|
||||||
::Stripe::Price.expects(:create).with(has_entry(:nickname, "Veg"))
|
::Stripe::Price.expects(:create).with(has_entry(:nickname, "Veg"))
|
||||||
post "/s/admin/plans.json", params: { nickname: "Veg", metadata: { group_name: "" } }
|
post "/subscriptions/admin/plans.json", params: { nickname: "Veg", metadata: { group_name: "" } }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a plan with a currency" do
|
it "creates a plan with a currency" do
|
||||||
::Stripe::Price.expects(:create).with(has_entry(:currency, "AUD"))
|
::Stripe::Price.expects(:create).with(has_entry(:currency, "AUD"))
|
||||||
post "/s/admin/plans.json", params: { currency: "AUD", metadata: { group_name: "" } }
|
post "/subscriptions/admin/plans.json", params: { currency: "AUD", metadata: { group_name: "" } }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a plan with an interval" do
|
it "creates a plan with an interval" do
|
||||||
::Stripe::Price.expects(:create).with(has_entry(recurring: { interval: "week" }))
|
::Stripe::Price.expects(:create).with(has_entry(recurring: { interval: "week" }))
|
||||||
post "/s/admin/plans.json",
|
post "/subscriptions/admin/plans.json",
|
||||||
params: {
|
params: {
|
||||||
type: "recurring",
|
type: "recurring",
|
||||||
interval: "week",
|
interval: "week",
|
||||||
@ -116,17 +116,17 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
|
|
||||||
it "creates a plan as a one-time purchase" do
|
it "creates a plan as a one-time purchase" do
|
||||||
::Stripe::Price.expects(:create).with(Not(has_key(:recurring)))
|
::Stripe::Price.expects(:create).with(Not(has_key(:recurring)))
|
||||||
post "/s/admin/plans.json", params: { metadata: { group_name: "" } }
|
post "/subscriptions/admin/plans.json", params: { metadata: { group_name: "" } }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a plan with an amount" do
|
it "creates a plan with an amount" do
|
||||||
::Stripe::Price.expects(:create).with(has_entry(:unit_amount, "102"))
|
::Stripe::Price.expects(:create).with(has_entry(:unit_amount, "102"))
|
||||||
post "/s/admin/plans.json", params: { amount: "102", metadata: { group_name: "" } }
|
post "/subscriptions/admin/plans.json", params: { amount: "102", metadata: { group_name: "" } }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates a plan with a product" do
|
it "creates a plan with a product" do
|
||||||
::Stripe::Price.expects(:create).with(has_entry(product: "prod_walterwhite"))
|
::Stripe::Price.expects(:create).with(has_entry(product: "prod_walterwhite"))
|
||||||
post "/s/admin/plans.json",
|
post "/subscriptions/admin/plans.json",
|
||||||
params: {
|
params: {
|
||||||
product: "prod_walterwhite",
|
product: "prod_walterwhite",
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -137,7 +137,7 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
|
|
||||||
it "creates a plan with an active status" do
|
it "creates a plan with an active status" do
|
||||||
::Stripe::Price.expects(:create).with(has_entry(:active, "false"))
|
::Stripe::Price.expects(:create).with(has_entry(:active, "false"))
|
||||||
post "/s/admin/plans.json", params: { active: "false", metadata: { group_name: "" } }
|
post "/subscriptions/admin/plans.json", params: { active: "false", metadata: { group_name: "" } }
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Need to fix the metadata tests
|
# TODO: Need to fix the metadata tests
|
||||||
@ -145,19 +145,19 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
|
|
||||||
#it 'has metadata' do
|
#it 'has metadata' do
|
||||||
# ::Stripe::Price.expects(:create).with(has_entry(:group_name, "discourse-user-group-name"))
|
# ::Stripe::Price.expects(:create).with(has_entry(:group_name, "discourse-user-group-name"))
|
||||||
# post "/s/admin/plans.json", params: { amount: "100", metadata: { group_name: 'discourse-user-group-name' } }
|
# post "/subscriptions/admin/plans.json", params: { amount: "100", metadata: { group_name: 'discourse-user-group-name' } }
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#it "creates a plan with a trial period" do
|
#it "creates a plan with a trial period" do
|
||||||
# ::Stripe::Price.expects(:create).with(has_entry(trial_period_days: '14'))
|
# ::Stripe::Price.expects(:create).with(has_entry(trial_period_days: '14'))
|
||||||
# post "/s/admin/plans.json", params: { trial_period_days: '14' }
|
# post "/subscriptions/admin/plans.json", params: { trial_period_days: '14' }
|
||||||
#end
|
#end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "update" do
|
describe "update" do
|
||||||
it "updates a plan" do
|
it "updates a plan" do
|
||||||
::Stripe::Price.expects(:update)
|
::Stripe::Price.expects(:update)
|
||||||
patch "/s/admin/plans/plan_12345.json",
|
patch "/subscriptions/admin/plans/plan_12345.json",
|
||||||
params: {
|
params: {
|
||||||
trial_period_days: "14",
|
trial_period_days: "14",
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -167,4 +167,4 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -12,31 +12,31 @@ RSpec.describe DiscourseSubscriptions::Admin::ProductsController do
|
|||||||
context "when unauthenticated" do
|
context "when unauthenticated" do
|
||||||
it "does not list the products" do
|
it "does not list the products" do
|
||||||
::Stripe::Product.expects(:list).never
|
::Stripe::Product.expects(:list).never
|
||||||
get "/s/admin/products.json"
|
get "/subscriptions/admin/products.json"
|
||||||
expect(response.status).to eq(404)
|
expect(response.status).to eq(404)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not create the product" do
|
it "does not create the product" do
|
||||||
::Stripe::Product.expects(:create).never
|
::Stripe::Product.expects(:create).never
|
||||||
post "/s/admin/products.json"
|
post "/subscriptions/admin/products.json"
|
||||||
expect(response.status).to eq(404)
|
expect(response.status).to eq(404)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not show the product" do
|
it "does not show the product" do
|
||||||
::Stripe::Product.expects(:retrieve).never
|
::Stripe::Product.expects(:retrieve).never
|
||||||
get "/s/admin/products/prod_qwerty123.json"
|
get "/subscriptions/admin/products/prod_qwerty123.json"
|
||||||
expect(response.status).to eq(404)
|
expect(response.status).to eq(404)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not update the product" do
|
it "does not update the product" do
|
||||||
::Stripe::Product.expects(:update).never
|
::Stripe::Product.expects(:update).never
|
||||||
put "/s/admin/products/prod_qwerty123.json"
|
put "/subscriptions/admin/products/prod_qwerty123.json"
|
||||||
expect(response.status).to eq(404)
|
expect(response.status).to eq(404)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not delete the product" do
|
it "does not delete the product" do
|
||||||
::Stripe::Product.expects(:delete).never
|
::Stripe::Product.expects(:delete).never
|
||||||
delete "/s/admin/products/u2.json"
|
delete "/subscriptions/admin/products/u2.json"
|
||||||
expect(response.status).to eq(404)
|
expect(response.status).to eq(404)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -50,7 +50,7 @@ RSpec.describe DiscourseSubscriptions::Admin::ProductsController do
|
|||||||
it "gets the empty products" do
|
it "gets the empty products" do
|
||||||
SiteSetting.discourse_subscriptions_public_key = "public-key"
|
SiteSetting.discourse_subscriptions_public_key = "public-key"
|
||||||
SiteSetting.discourse_subscriptions_secret_key = "secret-key"
|
SiteSetting.discourse_subscriptions_secret_key = "secret-key"
|
||||||
get "/s/admin/products.json"
|
get "/subscriptions/admin/products.json"
|
||||||
expect(response.parsed_body).to be_empty
|
expect(response.parsed_body).to be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -58,24 +58,24 @@ RSpec.describe DiscourseSubscriptions::Admin::ProductsController do
|
|||||||
describe "create" do
|
describe "create" do
|
||||||
it "is of product type service" do
|
it "is of product type service" do
|
||||||
::Stripe::Product.expects(:create).with(has_entry(:type, "service"))
|
::Stripe::Product.expects(:create).with(has_entry(:type, "service"))
|
||||||
post "/s/admin/products.json", params: {}
|
post "/subscriptions/admin/products.json", params: {}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has a name" do
|
it "has a name" do
|
||||||
::Stripe::Product.expects(:create).with(has_entry(:name, "Jesse Pinkman"))
|
::Stripe::Product.expects(:create).with(has_entry(:name, "Jesse Pinkman"))
|
||||||
post "/s/admin/products.json", params: { name: "Jesse Pinkman" }
|
post "/subscriptions/admin/products.json", params: { name: "Jesse Pinkman" }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has an active attribute" do
|
it "has an active attribute" do
|
||||||
::Stripe::Product.expects(:create).with(has_entry(active: "false"))
|
::Stripe::Product.expects(:create).with(has_entry(active: "false"))
|
||||||
post "/s/admin/products.json", params: { active: "false" }
|
post "/subscriptions/admin/products.json", params: { active: "false" }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has a statement descriptor" do
|
it "has a statement descriptor" do
|
||||||
::Stripe::Product.expects(:create).with(
|
::Stripe::Product.expects(:create).with(
|
||||||
has_entry(statement_descriptor: "Blessed are the cheesemakers"),
|
has_entry(statement_descriptor: "Blessed are the cheesemakers"),
|
||||||
)
|
)
|
||||||
post "/s/admin/products.json",
|
post "/subscriptions/admin/products.json",
|
||||||
params: {
|
params: {
|
||||||
statement_descriptor: "Blessed are the cheesemakers",
|
statement_descriptor: "Blessed are the cheesemakers",
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ RSpec.describe DiscourseSubscriptions::Admin::ProductsController do
|
|||||||
|
|
||||||
it "has no statement descriptor if empty" do
|
it "has no statement descriptor if empty" do
|
||||||
::Stripe::Product.expects(:create).with(has_key(:statement_descriptor)).never
|
::Stripe::Product.expects(:create).with(has_key(:statement_descriptor)).never
|
||||||
post "/s/admin/products.json", params: { statement_descriptor: "" }
|
post "/subscriptions/admin/products.json", params: { statement_descriptor: "" }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has metadata" do
|
it "has metadata" do
|
||||||
@ -96,7 +96,7 @@ RSpec.describe DiscourseSubscriptions::Admin::ProductsController do
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
post "/s/admin/products.json",
|
post "/subscriptions/admin/products.json",
|
||||||
params: {
|
params: {
|
||||||
metadata: {
|
metadata: {
|
||||||
description: "Oi, I think he just said bless be all the bignoses!",
|
description: "Oi, I think he just said bless be all the bignoses!",
|
||||||
@ -109,22 +109,22 @@ RSpec.describe DiscourseSubscriptions::Admin::ProductsController do
|
|||||||
describe "show" do
|
describe "show" do
|
||||||
it "retrieves the product" do
|
it "retrieves the product" do
|
||||||
::Stripe::Product.expects(:retrieve).with("prod_walterwhite")
|
::Stripe::Product.expects(:retrieve).with("prod_walterwhite")
|
||||||
get "/s/admin/products/prod_walterwhite.json"
|
get "/subscriptions/admin/products/prod_walterwhite.json"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "update" do
|
describe "update" do
|
||||||
it "updates the product" do
|
it "updates the product" do
|
||||||
::Stripe::Product.expects(:update)
|
::Stripe::Product.expects(:update)
|
||||||
patch "/s/admin/products/prod_walterwhite.json", params: {}
|
patch "/subscriptions/admin/products/prod_walterwhite.json", params: {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "delete" do
|
describe "delete" do
|
||||||
it "deletes the product" do
|
it "deletes the product" do
|
||||||
::Stripe::Product.expects(:delete).with("prod_walterwhite")
|
::Stripe::Product.expects(:delete).with("prod_walterwhite")
|
||||||
delete "/s/admin/products/prod_walterwhite.json"
|
delete "/subscriptions/admin/products/prod_walterwhite.json"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -24,13 +24,13 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||||||
context "when unauthenticated" do
|
context "when unauthenticated" do
|
||||||
it "does nothing" do
|
it "does nothing" do
|
||||||
::Stripe::Subscription.expects(:list).never
|
::Stripe::Subscription.expects(:list).never
|
||||||
get "/s/admin/subscriptions.json"
|
get "/subscriptions/admin/subscriptions.json"
|
||||||
expect(response.status).to eq(404)
|
expect(response.status).to eq(404)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not destroy a subscription" do
|
it "does not destroy a subscription" do
|
||||||
::Stripe::Subscription.expects(:delete).never
|
::Stripe::Subscription.expects(:delete).never
|
||||||
patch "/s/admin/subscriptions/sub_12345.json"
|
patch "/subscriptions/admin/subscriptions/sub_12345.json"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||||||
.expects(:list)
|
.expects(:list)
|
||||||
.with(expand: ["data.plan.product"], limit: 10, starting_after: nil)
|
.with(expand: ["data.plan.product"], limit: 10, starting_after: nil)
|
||||||
.returns(has_more: false, data: [{ id: "sub_12345" }, { id: "sub_nope" }])
|
.returns(has_more: false, data: [{ id: "sub_12345" }, { id: "sub_nope" }])
|
||||||
get "/s/admin/subscriptions.json"
|
get "/subscriptions/admin/subscriptions.json"
|
||||||
subscriptions = response.parsed_body["data"][0]["id"]
|
subscriptions = response.parsed_body["data"][0]["id"]
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
@ -62,7 +62,7 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||||||
.expects(:list)
|
.expects(:list)
|
||||||
.with(expand: ["data.plan.product"], limit: 10, starting_after: "sub_nope")
|
.with(expand: ["data.plan.product"], limit: 10, starting_after: "sub_nope")
|
||||||
.returns(has_more: false, data: [{ id: "sub_77777" }, { id: "sub_yepnoep" }])
|
.returns(has_more: false, data: [{ id: "sub_77777" }, { id: "sub_yepnoep" }])
|
||||||
get "/s/admin/subscriptions.json", params: { last_record: "sub_nope" }
|
get "/subscriptions/admin/subscriptions.json", params: { last_record: "sub_nope" }
|
||||||
subscriptions = response.parsed_body["data"][0]["id"]
|
subscriptions = response.parsed_body["data"][0]["id"]
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
@ -81,7 +81,7 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||||||
.with("sub_12345")
|
.with("sub_12345")
|
||||||
.returns(plan: { product: "pr_34578" }, customer: "c_123")
|
.returns(plan: { product: "pr_34578" }, customer: "c_123")
|
||||||
|
|
||||||
expect { delete "/s/admin/subscriptions/sub_12345.json" }.to change {
|
expect { delete "/subscriptions/admin/subscriptions/sub_12345.json" }.to change {
|
||||||
DiscourseSubscriptions::Customer.count
|
DiscourseSubscriptions::Customer.count
|
||||||
}.by(-1)
|
}.by(-1)
|
||||||
end
|
end
|
||||||
@ -100,7 +100,7 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||||||
customer: "c_123",
|
customer: "c_123",
|
||||||
)
|
)
|
||||||
|
|
||||||
expect { delete "/s/admin/subscriptions/sub_12345.json" }.to change {
|
expect { delete "/subscriptions/admin/subscriptions/sub_12345.json" }.to change {
|
||||||
user.groups.count
|
user.groups.count
|
||||||
}.by(-1)
|
}.by(-1)
|
||||||
end
|
end
|
||||||
@ -119,7 +119,7 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||||||
customer: "c_123",
|
customer: "c_123",
|
||||||
)
|
)
|
||||||
|
|
||||||
expect { delete "/s/admin/subscriptions/sub_12345.json" }.not_to change {
|
expect { delete "/subscriptions/admin/subscriptions/sub_12345.json" }.not_to change {
|
||||||
user.groups.count
|
user.groups.count
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -136,8 +136,8 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||||||
::Stripe::Invoice.expects(:retrieve).with("in_123").returns(payment_intent: "pi_123")
|
::Stripe::Invoice.expects(:retrieve).with("in_123").returns(payment_intent: "pi_123")
|
||||||
::Stripe::Refund.expects(:create).with({ payment_intent: "pi_123" })
|
::Stripe::Refund.expects(:create).with({ payment_intent: "pi_123" })
|
||||||
|
|
||||||
delete "/s/admin/subscriptions/sub_12345.json", params: { refund: true }
|
delete "/subscriptions/admin/subscriptions/sub_12345.json", params: { refund: true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -15,7 +15,7 @@ RSpec.describe DiscourseSubscriptions::AdminController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "is ok" do
|
it "is ok" do
|
||||||
get "/s/admin.json"
|
get "/subscriptions/admin.json"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||||||
.with("we-want-a-shrubbery", "stripe-webhook-signature", "zascharoo")
|
.with("we-want-a-shrubbery", "stripe-webhook-signature", "zascharoo")
|
||||||
.returns(type: "something")
|
.returns(type: "something")
|
||||||
|
|
||||||
post "/s/hooks.json", params: payload, headers: headers
|
post "/subscriptions/hooks.json", params: payload, headers: headers
|
||||||
|
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
@ -51,7 +51,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "is successfull" do
|
it "is successfull" do
|
||||||
post "/s/hooks.json"
|
post "/subscriptions/hooks.json"
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||||||
event_data[:object][:status] = "incomplete"
|
event_data[:object][:status] = "incomplete"
|
||||||
event_data[:previous_attributes] = { status: "incomplete" }
|
event_data[:previous_attributes] = { status: "incomplete" }
|
||||||
|
|
||||||
expect { post "/s/hooks.json" }.not_to change { user.groups.count }
|
expect { post "/subscriptions/hooks.json" }.not_to change { user.groups.count }
|
||||||
|
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
@ -69,7 +69,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||||||
event_data[:object][:status] = "incomplete"
|
event_data[:object][:status] = "incomplete"
|
||||||
event_data[:previous_attributes] = { status: "something-else" }
|
event_data[:previous_attributes] = { status: "something-else" }
|
||||||
|
|
||||||
expect { post "/s/hooks.json" }.not_to change { user.groups.count }
|
expect { post "/subscriptions/hooks.json" }.not_to change { user.groups.count }
|
||||||
|
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
@ -78,7 +78,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||||||
event_data[:object][:status] = "complete"
|
event_data[:object][:status] = "complete"
|
||||||
event_data[:previous_attributes] = { status: "incomplete" }
|
event_data[:previous_attributes] = { status: "incomplete" }
|
||||||
|
|
||||||
expect { post "/s/hooks.json" }.to change { user.groups.count }.by(1)
|
expect { post "/subscriptions/hooks.json" }.to change { user.groups.count }.by(1)
|
||||||
|
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
@ -95,16 +95,16 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "deletes the customer" do
|
it "deletes the customer" do
|
||||||
expect { post "/s/hooks.json" }.to change { DiscourseSubscriptions::Customer.count }.by(-1)
|
expect { post "/subscriptions/hooks.json" }.to change { DiscourseSubscriptions::Customer.count }.by(-1)
|
||||||
|
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
|
|
||||||
it "removes the user from the group" do
|
it "removes the user from the group" do
|
||||||
expect { post "/s/hooks.json" }.to change { user.groups.count }.by(-1)
|
expect { post "/subscriptions/hooks.json" }.to change { user.groups.count }.by(-1)
|
||||||
|
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -68,56 +68,6 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
SiteSetting.discourse_subscriptions_secret_key = "secret-key"
|
SiteSetting.discourse_subscriptions_secret_key = "secret-key"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#index" do
|
|
||||||
it "gets products" do
|
|
||||||
::Stripe::Product
|
|
||||||
.expects(:list)
|
|
||||||
.with({ ids: product_ids, active: true })
|
|
||||||
.returns(data: [product])
|
|
||||||
|
|
||||||
get "/s.json"
|
|
||||||
|
|
||||||
expect(response.parsed_body).to eq(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"id" => "prodct_23456",
|
|
||||||
"name" => "Very Special Product",
|
|
||||||
"description" =>
|
|
||||||
PrettyText.cook(
|
|
||||||
"Many people listened to my phone call with the Ukrainian President while it was being made",
|
|
||||||
),
|
|
||||||
"subscribed" => false,
|
|
||||||
"repurchaseable" => false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is subscribed" do
|
|
||||||
Fabricate(:customer, product_id: product[:id], user_id: user.id, customer_id: "x")
|
|
||||||
::Stripe::Product
|
|
||||||
.expects(:list)
|
|
||||||
.with({ ids: product_ids, active: true })
|
|
||||||
.returns(data: [product])
|
|
||||||
|
|
||||||
get "/s.json"
|
|
||||||
data = response.parsed_body
|
|
||||||
expect(data.first["subscribed"]).to eq true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is not subscribed" do
|
|
||||||
::DiscourseSubscriptions::Customer.delete_all
|
|
||||||
::Stripe::Product
|
|
||||||
.expects(:list)
|
|
||||||
.with({ ids: product_ids, active: true })
|
|
||||||
.returns(data: [product])
|
|
||||||
|
|
||||||
get "/s.json"
|
|
||||||
data = response.parsed_body
|
|
||||||
expect(data.first["subscribed"]).to eq false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#get_contributors" do
|
describe "#get_contributors" do
|
||||||
before do
|
before do
|
||||||
Fabricate(:product, external_id: "prod_campaign")
|
Fabricate(:product, external_id: "prod_campaign")
|
||||||
@ -132,7 +82,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
context "when not showing contributors" do
|
context "when not showing contributors" do
|
||||||
it "returns nothing if not set to show contributors" do
|
it "returns nothing if not set to show contributors" do
|
||||||
SiteSetting.discourse_subscriptions_campaign_show_contributors = false
|
SiteSetting.discourse_subscriptions_campaign_show_contributors = false
|
||||||
get "/s/contributors.json"
|
get "/subscriptions/contributors.json"
|
||||||
|
|
||||||
data = response.parsed_body
|
data = response.parsed_body
|
||||||
expect(data).to be_empty
|
expect(data).to be_empty
|
||||||
@ -145,7 +95,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
it "filters users by campaign product if set" do
|
it "filters users by campaign product if set" do
|
||||||
SiteSetting.discourse_subscriptions_campaign_product = "prod_campaign"
|
SiteSetting.discourse_subscriptions_campaign_product = "prod_campaign"
|
||||||
|
|
||||||
get "/s/contributors.json"
|
get "/subscriptions/contributors.json"
|
||||||
|
|
||||||
data = response.parsed_body
|
data = response.parsed_body
|
||||||
expect(data.first["id"]).to eq campaign_user.id
|
expect(data.first["id"]).to eq campaign_user.id
|
||||||
@ -155,7 +105,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
it "shows all purchases if campaign product not set" do
|
it "shows all purchases if campaign product not set" do
|
||||||
SiteSetting.discourse_subscriptions_campaign_product = nil
|
SiteSetting.discourse_subscriptions_campaign_product = nil
|
||||||
|
|
||||||
get "/s/contributors.json"
|
get "/subscriptions/contributors.json"
|
||||||
|
|
||||||
data = response.parsed_body
|
data = response.parsed_body
|
||||||
expect(data.length).to eq 2
|
expect(data.length).to eq 2
|
||||||
@ -170,7 +120,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
.expects(:list)
|
.expects(:list)
|
||||||
.with(active: true, product: "prod_walterwhite")
|
.with(active: true, product: "prod_walterwhite")
|
||||||
.returns(prices)
|
.returns(prices)
|
||||||
get "/s/prod_walterwhite.json"
|
get "/subscriptions/prod_walterwhite.json"
|
||||||
|
|
||||||
expect(response.parsed_body).to eq(
|
expect(response.parsed_body).to eq(
|
||||||
{
|
{
|
||||||
@ -222,7 +172,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
::Stripe::Customer.expects(:create).never
|
::Stripe::Customer.expects(:create).never
|
||||||
::Stripe::Price.expects(:retrieve).never
|
::Stripe::Price.expects(:retrieve).never
|
||||||
::Stripe::Subscription.expects(:create).never
|
::Stripe::Subscription.expects(:create).never
|
||||||
post "/s/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
post "/subscriptions/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -257,7 +207,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
.returns(status: "active", customer: "cus_1234")
|
.returns(status: "active", customer: "cus_1234")
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
post "/subscriptions/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
||||||
}.to change { DiscourseSubscriptions::Customer.count }
|
}.to change { DiscourseSubscriptions::Customer.count }
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -291,7 +241,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
::Stripe::Invoice.expects(:pay).returns(status: "paid", customer: "cus_1234")
|
::Stripe::Invoice.expects(:pay).returns(status: "paid", customer: "cus_1234")
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
post "/subscriptions/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
||||||
}.to change { DiscourseSubscriptions::Customer.count }
|
}.to change { DiscourseSubscriptions::Customer.count }
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -300,13 +250,13 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
::Stripe::Subscription.expects(:create).returns(status: "active", customer: "cus_1234")
|
::Stripe::Subscription.expects(:create).returns(status: "active", customer: "cus_1234")
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
post "/subscriptions/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
||||||
}.to change { DiscourseSubscriptions::Customer.count }
|
}.to change { DiscourseSubscriptions::Customer.count }
|
||||||
|
|
||||||
::Stripe::Customer.expects(:retrieve).with("cus_1234")
|
::Stripe::Customer.expects(:retrieve).with("cus_1234")
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/create.json", params: { plan: "plan_5678", source: "tok_5678" }
|
post "/subscriptions/create.json", params: { plan: "plan_5678", source: "tok_5678" }
|
||||||
}.not_to change { DiscourseSubscriptions::Customer.count }
|
}.not_to change { DiscourseSubscriptions::Customer.count }
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -315,7 +265,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
::Stripe::Price.expects(:retrieve).returns(type: "recurring", metadata: {})
|
::Stripe::Price.expects(:retrieve).returns(type: "recurring", metadata: {})
|
||||||
::Stripe::Subscription.expects(:create).returns(status: "active", customer: "cus_1234")
|
::Stripe::Subscription.expects(:create).returns(status: "active", customer: "cus_1234")
|
||||||
expect {
|
expect {
|
||||||
post "/s/create.json",
|
post "/subscriptions/create.json",
|
||||||
params: {
|
params: {
|
||||||
plan: "plan_1234",
|
plan: "plan_1234",
|
||||||
source: "tok_1234",
|
source: "tok_1234",
|
||||||
@ -346,7 +296,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
|
|
||||||
::Stripe::PromotionCode.expects(:list).with({ code: "invalid" }).returns(data: [])
|
::Stripe::PromotionCode.expects(:list).with({ code: "invalid" }).returns(data: [])
|
||||||
|
|
||||||
post "/s/create.json",
|
post "/subscriptions/create.json",
|
||||||
params: {
|
params: {
|
||||||
plan: "plan_1234",
|
plan: "plan_1234",
|
||||||
source: "tok_1234",
|
source: "tok_1234",
|
||||||
@ -391,7 +341,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
.returns(status: "active", customer: "cus_1234")
|
.returns(status: "active", customer: "cus_1234")
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/create.json",
|
post "/subscriptions/create.json",
|
||||||
params: {
|
params: {
|
||||||
plan: "plan_1234",
|
plan: "plan_1234",
|
||||||
source: "tok_1234",
|
source: "tok_1234",
|
||||||
@ -434,7 +384,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
::Stripe::Invoice.expects(:pay).returns(status: "paid", customer: "cus_1234")
|
::Stripe::Invoice.expects(:pay).returns(status: "paid", customer: "cus_1234")
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/create.json",
|
post "/subscriptions/create.json",
|
||||||
params: {
|
params: {
|
||||||
plan: "plan_1234",
|
plan: "plan_1234",
|
||||||
source: "tok_1234",
|
source: "tok_1234",
|
||||||
@ -462,7 +412,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/finalize.json", params: { plan: "plan_1234", transaction: "sub_1234" }
|
post "/subscriptions/finalize.json", params: { plan: "plan_1234", transaction: "sub_1234" }
|
||||||
}.to change { DiscourseSubscriptions::Customer.count }
|
}.to change { DiscourseSubscriptions::Customer.count }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -482,7 +432,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/finalize.json", params: { plan: "plan_1234", transaction: "in_1234" }
|
post "/subscriptions/finalize.json", params: { plan: "plan_1234", transaction: "in_1234" }
|
||||||
}.to change { DiscourseSubscriptions::Customer.count }
|
}.to change { DiscourseSubscriptions::Customer.count }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -505,7 +455,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
group_name: "admins",
|
group_name: "admins",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
post "/s/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
post "/subscriptions/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
||||||
expect(user.admin).to eq false
|
expect(user.admin).to eq false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -516,7 +466,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
group_name: "other",
|
group_name: "other",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
post "/s/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
post "/subscriptions/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
||||||
expect(user.groups).to be_empty
|
expect(user.groups).to be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -536,7 +486,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
::Stripe::Subscription.expects(:create).returns(status: "failed")
|
::Stripe::Subscription.expects(:create).returns(status: "failed")
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
post "/subscriptions/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
||||||
}.not_to change { group.users.count }
|
}.not_to change { group.users.count }
|
||||||
|
|
||||||
expect(user.groups).to be_empty
|
expect(user.groups).to be_empty
|
||||||
@ -546,7 +496,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
::Stripe::Subscription.expects(:create).returns(status: "active")
|
::Stripe::Subscription.expects(:create).returns(status: "active")
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
post "/subscriptions/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
||||||
}.to change { group.users.count }
|
}.to change { group.users.count }
|
||||||
|
|
||||||
expect(user.groups).not_to be_empty
|
expect(user.groups).not_to be_empty
|
||||||
@ -556,7 +506,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
::Stripe::Subscription.expects(:create).returns(status: "trialing")
|
::Stripe::Subscription.expects(:create).returns(status: "trialing")
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
post "/s/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
post "/subscriptions/create.json", params: { plan: "plan_1234", source: "tok_1234" }
|
||||||
}.to change { group.users.count }
|
}.to change { group.users.count }
|
||||||
|
|
||||||
expect(user.groups).not_to be_empty
|
expect(user.groups).not_to be_empty
|
||||||
@ -565,4 +515,4 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -12,7 +12,7 @@ RSpec.describe DiscourseSubscriptions::User::PaymentsController do
|
|||||||
context "when not authenticated" do
|
context "when not authenticated" do
|
||||||
it "does not get the payment intents" do
|
it "does not get the payment intents" do
|
||||||
::Stripe::PaymentIntent.expects(:list).never
|
::Stripe::PaymentIntent.expects(:list).never
|
||||||
get "/s/user/payments.json"
|
get "/subscriptions/user/payments.json"
|
||||||
expect(response.status).to eq(403)
|
expect(response.status).to eq(403)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -52,7 +52,7 @@ RSpec.describe DiscourseSubscriptions::User::PaymentsController do
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
get "/s/user/payments.json"
|
get "/subscriptions/user/payments.json"
|
||||||
|
|
||||||
parsed_body = response.parsed_body
|
parsed_body = response.parsed_body
|
||||||
invoice = parsed_body[0]["invoice"]
|
invoice = parsed_body[0]["invoice"]
|
||||||
@ -61,4 +61,4 @@ RSpec.describe DiscourseSubscriptions::User::PaymentsController do
|
|||||||
expect(parsed_body.count).to eq(2)
|
expect(parsed_body.count).to eq(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -14,18 +14,18 @@ RSpec.describe DiscourseSubscriptions::User::SubscriptionsController do
|
|||||||
context "when not authenticated" do
|
context "when not authenticated" do
|
||||||
it "does not get the subscriptions" do
|
it "does not get the subscriptions" do
|
||||||
::Stripe::Customer.expects(:list).never
|
::Stripe::Customer.expects(:list).never
|
||||||
get "/s/user/subscriptions.json"
|
get "/subscriptions/user/subscriptions.json"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not destroy a subscription" do
|
it "does not destroy a subscription" do
|
||||||
::Stripe::Subscription.expects(:delete).never
|
::Stripe::Subscription.expects(:delete).never
|
||||||
patch "/s/user/subscriptions/sub_12345.json"
|
patch "/subscriptions/user/subscriptions/sub_12345.json"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't update payment method for subscription" do
|
it "doesn't update payment method for subscription" do
|
||||||
::Stripe::Subscription.expects(:update).never
|
::Stripe::Subscription.expects(:update).never
|
||||||
::Stripe::PaymentMethod.expects(:attach).never
|
::Stripe::PaymentMethod.expects(:attach).never
|
||||||
put "/s/user/subscriptions/sub_12345.json", params: { payment_method: "pm_abc123abc" }
|
put "/subscriptions/user/subscriptions/sub_12345.json", params: { payment_method: "pm_abc123abc" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ RSpec.describe DiscourseSubscriptions::User::SubscriptionsController do
|
|||||||
.with(email: user.email, expand: ["data.subscriptions"])
|
.with(email: user.email, expand: ["data.subscriptions"])
|
||||||
.returns(customers)
|
.returns(customers)
|
||||||
|
|
||||||
get "/s/user/subscriptions.json"
|
get "/subscriptions/user/subscriptions.json"
|
||||||
|
|
||||||
subscription = response.parsed_body.first
|
subscription = response.parsed_body.first
|
||||||
|
|
||||||
@ -100,8 +100,8 @@ RSpec.describe DiscourseSubscriptions::User::SubscriptionsController do
|
|||||||
it "updates the payment method for subscription" do
|
it "updates the payment method for subscription" do
|
||||||
::Stripe::Subscription.expects(:update).once
|
::Stripe::Subscription.expects(:update).once
|
||||||
::Stripe::PaymentMethod.expects(:attach).once
|
::Stripe::PaymentMethod.expects(:attach).once
|
||||||
put "/s/user/subscriptions/sub_1234.json", params: { payment_method: "pm_abc123abc" }
|
put "/subscriptions/user/subscriptions/sub_1234.json", params: { payment_method: "pm_abc123abc" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user