mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 13:05:19 +02:00
Subscription tests and domain (#2209)
* Save work * Subscriptions and trials domain * Store family ID on customer * Remove indirection of stripe calls * Test simplifications * Update brakeman * Fix stripe tests in CI * Update billing page to show subscription details * Remove legacy columns * Complete billing settings page * Fix hardcoded plan name * Handle subscriptions for self hosting mode * Lint fixes
This commit is contained in:
parent
8c10e87387
commit
5da4bb6dc3
40 changed files with 1041 additions and 233 deletions
|
@ -1,6 +1,57 @@
|
|||
require "test_helper"
|
||||
require "ostruct"
|
||||
|
||||
class Provider::Stripe::SubscriptionEventProcessorTest < ActiveSupport::TestCase
|
||||
# test "process" do
|
||||
# end
|
||||
test "handles subscription event" do
|
||||
test_customer_id = "test-customer-id"
|
||||
test_subscription_id = "test-subscription-id"
|
||||
|
||||
mock_event = JSON.parse({
|
||||
type: "customer.subscription.created",
|
||||
data: {
|
||||
object: {
|
||||
id: test_subscription_id,
|
||||
status: "active",
|
||||
customer: test_customer_id,
|
||||
items: {
|
||||
data: [
|
||||
{
|
||||
current_period_end: 1.month.from_now.to_i,
|
||||
plan: {
|
||||
interval: "month",
|
||||
amount: 900,
|
||||
currency: "usd"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}.to_json, object_class: OpenStruct)
|
||||
|
||||
family = Family.create!(
|
||||
name: "Test Subscribed Family",
|
||||
stripe_customer_id: test_customer_id
|
||||
)
|
||||
|
||||
family.start_subscription!(test_subscription_id)
|
||||
|
||||
processor = Provider::Stripe::SubscriptionEventProcessor.new(mock_event)
|
||||
|
||||
assert_equal "active", family.subscription.status
|
||||
assert_equal test_subscription_id, family.subscription.stripe_id
|
||||
assert_nil family.subscription.amount
|
||||
assert_nil family.subscription.currency
|
||||
assert_nil family.subscription.current_period_ends_at
|
||||
|
||||
processor.process
|
||||
|
||||
family.reload
|
||||
|
||||
assert_equal "active", family.subscription.status
|
||||
assert_equal test_subscription_id, family.subscription.stripe_id
|
||||
assert_equal 9, family.subscription.amount
|
||||
assert_equal "USD", family.subscription.currency
|
||||
assert family.subscription.current_period_ends_at > 20.days.from_now
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue