我正在尝试模拟订阅到期日期,我需要执行 Stripe 请求并检查
current_period_end
在 stripe 订阅中,但我不知道该怎么做。
我有我的订阅模型:
class Subscription < ApplicationRecord
def current_period_end
Time.zone.at(Stripe::Subscription.retrieve(processor_subscription_id).current_period_end)
end
end
还有我的 subscription_test.rb
test '#current_period_end' do
subscription = subscriptions(:silver)
mock = MiniTest::Mock.new
mock.expect :retrieve, stripe_subscription_hash, ['proccesor_subs_id']
subscription.stub :current_period_end, mock do
assert (Time.zone.now + 1.months).to_i
end
end
def stripe_subscription_hash
{
'id': 'sub_1MYVd6LjxsKwlheySI3ixpiO',
'object': 'subscription',
'application': nil,
'application_fee_percent': nil,
'collection_method': 'charge_automatically',
'created': 1675693512,
'currency': 'eur',
'current_period_end': (Time.zone.now + 1.month).to_i,
'current_period_start': 1675693512,
'start_date': 1675693512,
}
end
有人能帮我吗?