This commit is contained in:
Blake Erickson 2024-04-24 10:09:53 -06:00
parent fcc414dbbe
commit e46693b94e
10 changed files with 72 additions and 22 deletions

View File

@ -1,5 +1,5 @@
import Controller from "@ember/controller";
import Ember from "ember";
import { computed } from "@ember/object";
import { htmlSafe } from "@ember/template";
import I18n from "I18n";
@ -14,7 +14,7 @@ export default Controller.extend({
.then(() => this.set("email", this.currentUser.email));
}
},
pricingTable: Ember.computed("email", function () {
pricingTable: computed("email", function () {
try {
const pricing_table_info = JSON.parse(
this.siteSettings.discourse_subscriptions_pricing_table

View File

@ -25,11 +25,21 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
describe "create" do
it "does not create a plan" do
::Stripe::Price.expects(:create).never
post "/subscriptions/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 "/subscriptions/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
@ -94,12 +104,24 @@ 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 "/subscriptions/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 "/subscriptions/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
@ -121,7 +143,13 @@ RSpec.describe DiscourseSubscriptions::Admin::PlansController do
it "creates a plan with an amount" do
::Stripe::Price.expects(:create).with(has_entry(:unit_amount, "102"))
post "/subscriptions/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
@ -137,7 +165,13 @@ 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 "/subscriptions/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

View File

@ -95,7 +95,9 @@ RSpec.describe DiscourseSubscriptions::HooksController do
end
it "deletes the customer" do
expect { post "/subscriptions/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

View File

@ -412,7 +412,11 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
)
expect {
post "/subscriptions/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
@ -432,7 +436,11 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do
)
expect {
post "/subscriptions/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

View File

@ -25,7 +25,10 @@ RSpec.describe DiscourseSubscriptions::User::SubscriptionsController do
it "doesn't update payment method for subscription" do
::Stripe::Subscription.expects(:update).never
::Stripe::PaymentMethod.expects(:attach).never
put "/subscriptions/user/subscriptions/sub_12345.json", params: { payment_method: "pm_abc123abc" }
put "/subscriptions/user/subscriptions/sub_12345.json",
params: {
payment_method: "pm_abc123abc",
}
end
end
@ -100,7 +103,10 @@ 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 "/subscriptions/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

View File

@ -1,6 +1,6 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Discourse Subscriptions", function (needs) {
needs.user();