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
|
||||
it "does nothing" do
|
||||
::Stripe::PromotionCode.expects(:list).never
|
||||
get "/s/admin/coupons.json"
|
||||
get "/subscriptions/admin/coupons.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
end
|
||||
|
@ -29,7 +29,7 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||
.with({ limit: 100 })
|
||||
.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.parsed_body[0]["id"]).to eq("promo_123")
|
||||
end
|
||||
|
@ -40,7 +40,7 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||
.with({ limit: 100 })
|
||||
.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.parsed_body).to be_blank
|
||||
end
|
||||
|
@ -53,7 +53,7 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||
{ code: "p123", coupon: { amount_off: 2000 } },
|
||||
)
|
||||
|
||||
post "/s/admin/coupons.json",
|
||||
post "/subscriptions/admin/coupons.json",
|
||||
params: {
|
||||
promo: "p123",
|
||||
discount_type: "amount",
|
||||
|
@ -71,7 +71,7 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||
{ code: "p123", coupon: { percent_off: 20 } },
|
||||
)
|
||||
|
||||
post "/s/admin/coupons.json",
|
||||
post "/subscriptions/admin/coupons.json",
|
||||
params: {
|
||||
promo: "p123",
|
||||
discount_type: "percent",
|
||||
|
@ -84,4 +84,4 @@ RSpec.describe DiscourseSubscriptions::Admin::CouponsController do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -13,11 +13,11 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
describe "index" do
|
||||
it "does not get the plans" do
|
||||
::Stripe::Price.expects(:list).never
|
||||
get "/s/admin/plans.json"
|
||||
get "/subscriptions/admin/plans.json"
|
||||
end
|
||||
|
||||
it "not ok" do
|
||||
get "/s/admin/plans.json"
|
||||
get "/subscriptions/admin/plans.json"
|
||||
expect(response.status).to eq 404
|
||||
end
|
||||
end
|
||||
|
@ -25,11 +25,11 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
describe "create" do
|
||||
it "does not create a plan" do
|
||||
::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
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -37,11 +37,11 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
describe "show" do
|
||||
it "does not show the plan" do
|
||||
::Stripe::Price.expects(:retrieve).never
|
||||
get "/s/admin/plans/plan_12345.json"
|
||||
get "/subscriptions/admin/plans/plan_12345.json"
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -49,7 +49,7 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
describe "update" do
|
||||
it "does not update a plan" do
|
||||
::Stripe::Price.expects(:update).never
|
||||
delete "/s/admin/plans/plan_12345.json"
|
||||
delete "/subscriptions/admin/plans/plan_12345.json"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -62,19 +62,19 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
describe "index" do
|
||||
it "lists the plans" do
|
||||
::Stripe::Price.expects(:list).with(nil)
|
||||
get "/s/admin/plans.json"
|
||||
get "/subscriptions/admin/plans.json"
|
||||
end
|
||||
|
||||
it "lists the plans for the product" do
|
||||
::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
|
||||
|
||||
describe "show" do
|
||||
it "shows a plan" do
|
||||
::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
|
||||
end
|
||||
|
||||
|
@ -83,7 +83,7 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
.expects(:retrieve)
|
||||
.with("plan_12345")
|
||||
.returns(currency: "aud", recurring: { interval: "year" })
|
||||
get "/s/admin/plans/plan_12345.json"
|
||||
get "/subscriptions/admin/plans/plan_12345.json"
|
||||
|
||||
plan = response.parsed_body
|
||||
expect(plan["currency"]).to eq "AUD"
|
||||
|
@ -94,17 +94,17 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
describe "create" do
|
||||
it "creates a plan with a nickname" do
|
||||
::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
|
||||
|
||||
it "creates a plan with a currency" do
|
||||
::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
|
||||
|
||||
it "creates a plan with an interval" do
|
||||
::Stripe::Price.expects(:create).with(has_entry(recurring: { interval: "week" }))
|
||||
post "/s/admin/plans.json",
|
||||
post "/subscriptions/admin/plans.json",
|
||||
params: {
|
||||
type: "recurring",
|
||||
interval: "week",
|
||||
|
@ -116,17 +116,17 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
|
||||
it "creates a plan as a one-time purchase" do
|
||||
::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
|
||||
|
||||
it "creates a plan with an amount" do
|
||||
::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
|
||||
|
||||
it "creates a plan with a product" do
|
||||
::Stripe::Price.expects(:create).with(has_entry(product: "prod_walterwhite"))
|
||||
post "/s/admin/plans.json",
|
||||
post "/subscriptions/admin/plans.json",
|
||||
params: {
|
||||
product: "prod_walterwhite",
|
||||
metadata: {
|
||||
|
@ -137,7 +137,7 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
|
||||
it "creates a plan with an active status" do
|
||||
::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
|
||||
|
||||
# TODO: Need to fix the metadata tests
|
||||
|
@ -145,19 +145,19 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
|
||||
#it 'has metadata' do
|
||||
# ::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
|
||||
|
||||
#it "creates a plan with a trial period" do
|
||||
# ::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
|
||||
|
||||
describe "update" do
|
||||
it "updates a plan" do
|
||||
::Stripe::Price.expects(:update)
|
||||
patch "/s/admin/plans/plan_12345.json",
|
||||
patch "/subscriptions/admin/plans/plan_12345.json",
|
||||
params: {
|
||||
trial_period_days: "14",
|
||||
metadata: {
|
||||
|
@ -167,4 +167,4 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,31 +12,31 @@ RSpec.describe DiscourseSubscriptions::Admin::ProductsController do
|
|||
context "when unauthenticated" do
|
||||
it "does not list the products" do
|
||||
::Stripe::Product.expects(:list).never
|
||||
get "/s/admin/products.json"
|
||||
get "/subscriptions/admin/products.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it "does not create the product" do
|
||||
::Stripe::Product.expects(:create).never
|
||||
post "/s/admin/products.json"
|
||||
post "/subscriptions/admin/products.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it "does not show the product" do
|
||||
::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)
|
||||
end
|
||||
|
||||
it "does not update the product" do
|
||||
::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)
|
||||
end
|
||||
|
||||
it "does not delete the product" do
|
||||
::Stripe::Product.expects(:delete).never
|
||||
delete "/s/admin/products/u2.json"
|
||||
delete "/subscriptions/admin/products/u2.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
end
|
||||
|
@ -50,7 +50,7 @@ RSpec.describe DiscourseSubscriptions::Admin::ProductsController do
|
|||
it "gets the empty products" do
|
||||
SiteSetting.discourse_subscriptions_public_key = "public-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
|
||||
end
|
||||
end
|
||||
|
@ -58,24 +58,24 @@ RSpec.describe DiscourseSubscriptions::Admin::ProductsController do
|
|||
describe "create" do
|
||||
it "is of product type service" do
|
||||
::Stripe::Product.expects(:create).with(has_entry(:type, "service"))
|
||||
post "/s/admin/products.json", params: {}
|
||||
post "/subscriptions/admin/products.json", params: {}
|
||||
end
|
||||
|
||||
it "has a name" do
|
||||
::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
|
||||
|
||||
it "has an active attribute" do
|
||||
::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
|
||||
|
||||
it "has a statement descriptor" do
|
||||
::Stripe::Product.expects(:create).with(
|
||||
has_entry(statement_descriptor: "Blessed are the cheesemakers"),
|
||||
)
|
||||
post "/s/admin/products.json",
|
||||
post "/subscriptions/admin/products.json",
|
||||
params: {
|
||||
statement_descriptor: "Blessed are the cheesemakers",
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ RSpec.describe DiscourseSubscriptions::Admin::ProductsController do
|
|||
|
||||
it "has no statement descriptor if empty" do
|
||||
::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
|
||||
|
||||
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: {
|
||||
metadata: {
|
||||
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
|
||||
it "retrieves the product" do
|
||||
::Stripe::Product.expects(:retrieve).with("prod_walterwhite")
|
||||
get "/s/admin/products/prod_walterwhite.json"
|
||||
get "/subscriptions/admin/products/prod_walterwhite.json"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
it "updates the product" do
|
||||
::Stripe::Product.expects(:update)
|
||||
patch "/s/admin/products/prod_walterwhite.json", params: {}
|
||||
patch "/subscriptions/admin/products/prod_walterwhite.json", params: {}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete" do
|
||||
it "deletes the product" do
|
||||
::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
|
|
@ -24,13 +24,13 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||
context "when unauthenticated" do
|
||||
it "does nothing" do
|
||||
::Stripe::Subscription.expects(:list).never
|
||||
get "/s/admin/subscriptions.json"
|
||||
get "/subscriptions/admin/subscriptions.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
it "does not destroy a subscription" do
|
||||
::Stripe::Subscription.expects(:delete).never
|
||||
patch "/s/admin/subscriptions/sub_12345.json"
|
||||
patch "/subscriptions/admin/subscriptions/sub_12345.json"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -50,7 +50,7 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||
.expects(:list)
|
||||
.with(expand: ["data.plan.product"], limit: 10, starting_after: nil)
|
||||
.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"]
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
@ -62,7 +62,7 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||
.expects(:list)
|
||||
.with(expand: ["data.plan.product"], limit: 10, starting_after: "sub_nope")
|
||||
.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"]
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
@ -81,7 +81,7 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||
.with("sub_12345")
|
||||
.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
|
||||
}.by(-1)
|
||||
end
|
||||
|
@ -100,7 +100,7 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||
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
|
||||
}.by(-1)
|
||||
end
|
||||
|
@ -119,7 +119,7 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||
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
|
||||
}
|
||||
end
|
||||
|
@ -136,8 +136,8 @@ RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do
|
|||
::Stripe::Invoice.expects(:retrieve).with("in_123").returns(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
|
|
@ -15,7 +15,7 @@ RSpec.describe DiscourseSubscriptions::AdminController do
|
|||
end
|
||||
|
||||
it "is ok" do
|
||||
get "/s/admin.json"
|
||||
get "/subscriptions/admin.json"
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||
.with("we-want-a-shrubbery", "stripe-webhook-signature", "zascharoo")
|
||||
.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
|
||||
end
|
||||
|
@ -51,7 +51,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||
end
|
||||
|
||||
it "is successfull" do
|
||||
post "/s/hooks.json"
|
||||
post "/subscriptions/hooks.json"
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
|
||||
|
@ -60,7 +60,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||
event_data[:object][: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
|
||||
end
|
||||
|
@ -69,7 +69,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||
event_data[:object][:status] = "incomplete"
|
||||
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
|
||||
end
|
||||
|
@ -78,7 +78,7 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||
event_data[:object][:status] = "complete"
|
||||
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
|
||||
end
|
||||
|
@ -95,16 +95,16 @@ RSpec.describe DiscourseSubscriptions::HooksController do
|
|||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -68,56 +68,6 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
SiteSetting.discourse_subscriptions_secret_key = "secret-key"
|
||||
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
|
||||
before do
|
||||
Fabricate(:product, external_id: "prod_campaign")
|
||||
|
@ -132,7 +82,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
context "when not showing contributors" do
|
||||
it "returns nothing if not set to show contributors" do
|
||||
SiteSetting.discourse_subscriptions_campaign_show_contributors = false
|
||||
get "/s/contributors.json"
|
||||
get "/subscriptions/contributors.json"
|
||||
|
||||
data = response.parsed_body
|
||||
expect(data).to be_empty
|
||||
|
@ -145,7 +95,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
it "filters users by campaign product if set" do
|
||||
SiteSetting.discourse_subscriptions_campaign_product = "prod_campaign"
|
||||
|
||||
get "/s/contributors.json"
|
||||
get "/subscriptions/contributors.json"
|
||||
|
||||
data = response.parsed_body
|
||||
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
|
||||
SiteSetting.discourse_subscriptions_campaign_product = nil
|
||||
|
||||
get "/s/contributors.json"
|
||||
get "/subscriptions/contributors.json"
|
||||
|
||||
data = response.parsed_body
|
||||
expect(data.length).to eq 2
|
||||
|
@ -170,7 +120,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
.expects(:list)
|
||||
.with(active: true, product: "prod_walterwhite")
|
||||
.returns(prices)
|
||||
get "/s/prod_walterwhite.json"
|
||||
get "/subscriptions/prod_walterwhite.json"
|
||||
|
||||
expect(response.parsed_body).to eq(
|
||||
{
|
||||
|
@ -222,7 +172,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
::Stripe::Customer.expects(:create).never
|
||||
::Stripe::Price.expects(:retrieve).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
|
||||
|
||||
|
@ -257,7 +207,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
.returns(status: "active", customer: "cus_1234")
|
||||
|
||||
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 }
|
||||
end
|
||||
|
||||
|
@ -291,7 +241,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
::Stripe::Invoice.expects(:pay).returns(status: "paid", customer: "cus_1234")
|
||||
|
||||
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 }
|
||||
end
|
||||
|
||||
|
@ -300,13 +250,13 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
::Stripe::Subscription.expects(:create).returns(status: "active", customer: "cus_1234")
|
||||
|
||||
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 }
|
||||
|
||||
::Stripe::Customer.expects(:retrieve).with("cus_1234")
|
||||
|
||||
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 }
|
||||
end
|
||||
|
||||
|
@ -315,7 +265,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
::Stripe::Price.expects(:retrieve).returns(type: "recurring", metadata: {})
|
||||
::Stripe::Subscription.expects(:create).returns(status: "active", customer: "cus_1234")
|
||||
expect {
|
||||
post "/s/create.json",
|
||||
post "/subscriptions/create.json",
|
||||
params: {
|
||||
plan: "plan_1234",
|
||||
source: "tok_1234",
|
||||
|
@ -346,7 +296,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
|
||||
::Stripe::PromotionCode.expects(:list).with({ code: "invalid" }).returns(data: [])
|
||||
|
||||
post "/s/create.json",
|
||||
post "/subscriptions/create.json",
|
||||
params: {
|
||||
plan: "plan_1234",
|
||||
source: "tok_1234",
|
||||
|
@ -391,7 +341,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
.returns(status: "active", customer: "cus_1234")
|
||||
|
||||
expect {
|
||||
post "/s/create.json",
|
||||
post "/subscriptions/create.json",
|
||||
params: {
|
||||
plan: "plan_1234",
|
||||
source: "tok_1234",
|
||||
|
@ -434,7 +384,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
::Stripe::Invoice.expects(:pay).returns(status: "paid", customer: "cus_1234")
|
||||
|
||||
expect {
|
||||
post "/s/create.json",
|
||||
post "/subscriptions/create.json",
|
||||
params: {
|
||||
plan: "plan_1234",
|
||||
source: "tok_1234",
|
||||
|
@ -462,7 +412,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
)
|
||||
|
||||
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 }
|
||||
end
|
||||
end
|
||||
|
@ -482,7 +432,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
)
|
||||
|
||||
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 }
|
||||
end
|
||||
end
|
||||
|
@ -505,7 +455,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
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
|
||||
end
|
||||
|
||||
|
@ -516,7 +466,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
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
|
||||
end
|
||||
end
|
||||
|
@ -536,7 +486,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
::Stripe::Subscription.expects(:create).returns(status: "failed")
|
||||
|
||||
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 }
|
||||
|
||||
expect(user.groups).to be_empty
|
||||
|
@ -546,7 +496,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
::Stripe::Subscription.expects(:create).returns(status: "active")
|
||||
|
||||
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 }
|
||||
|
||||
expect(user.groups).not_to be_empty
|
||||
|
@ -556,7 +506,7 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
::Stripe::Subscription.expects(:create).returns(status: "trialing")
|
||||
|
||||
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 }
|
||||
|
||||
expect(user.groups).not_to be_empty
|
||||
|
@ -565,4 +515,4 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -12,7 +12,7 @@ RSpec.describe DiscourseSubscriptions::User::PaymentsController do
|
|||
context "when not authenticated" do
|
||||
it "does not get the payment intents" do
|
||||
::Stripe::PaymentIntent.expects(:list).never
|
||||
get "/s/user/payments.json"
|
||||
get "/subscriptions/user/payments.json"
|
||||
expect(response.status).to eq(403)
|
||||
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
|
||||
invoice = parsed_body[0]["invoice"]
|
||||
|
@ -61,4 +61,4 @@ RSpec.describe DiscourseSubscriptions::User::PaymentsController do
|
|||
expect(parsed_body.count).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -14,18 +14,18 @@ RSpec.describe DiscourseSubscriptions::User::SubscriptionsController do
|
|||
context "when not authenticated" do
|
||||
it "does not get the subscriptions" do
|
||||
::Stripe::Customer.expects(:list).never
|
||||
get "/s/user/subscriptions.json"
|
||||
get "/subscriptions/user/subscriptions.json"
|
||||
end
|
||||
|
||||
it "does not destroy a subscription" do
|
||||
::Stripe::Subscription.expects(:delete).never
|
||||
patch "/s/user/subscriptions/sub_12345.json"
|
||||
patch "/subscriptions/user/subscriptions/sub_12345.json"
|
||||
end
|
||||
|
||||
it "doesn't update payment method for subscription" do
|
||||
::Stripe::Subscription.expects(:update).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
|
||||
|
||||
|
@ -74,7 +74,7 @@ RSpec.describe DiscourseSubscriptions::User::SubscriptionsController do
|
|||
.with(email: user.email, expand: ["data.subscriptions"])
|
||||
.returns(customers)
|
||||
|
||||
get "/s/user/subscriptions.json"
|
||||
get "/subscriptions/user/subscriptions.json"
|
||||
|
||||
subscription = response.parsed_body.first
|
||||
|
||||
|
@ -100,8 +100,8 @@ RSpec.describe DiscourseSubscriptions::User::SubscriptionsController do
|
|||
it "updates the payment method for subscription" do
|
||||
::Stripe::Subscription.expects(:update).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
|
Loading…
Reference in New Issue