2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe InsertBillingSubscriptions, :skip => true do
|
|
|
|
|
|
|
|
let(:sub) do
|
|
|
|
# billing_plan = Qx.insert_into(:billing_plans).values({name: 'test_bp', amount: 0, stripe_plan_id: 'stripe_bp', created_at: Time.current, updated_at: Time.current}).returning('*').execute.last
|
|
|
|
# InsertBillingSubscriptions.trial(3624, billing_plan['stripe_plan_id'])[:json]
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.trial' do
|
|
|
|
it 'creates the record' do
|
|
|
|
sub
|
|
|
|
expect(sub["id"]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.check_trial' do
|
|
|
|
|
|
|
|
it 'marks as inactive after 10 days' do
|
|
|
|
sub
|
|
|
|
Timecop.freeze(10.days.from_now){ InsertBillingSubscriptions.check_trial(sub['id']) }
|
|
|
|
updated = Qx.fetch(:billing_subscriptions, sub['id']).last
|
|
|
|
expect(updated['status']).to eq('inactive')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change the status if not still trialing after 10 days' do
|
|
|
|
sub
|
|
|
|
Qx.update(:billing_subscriptions).set(status: 'active').where("id = $id", id: sub['id']).execute
|
|
|
|
Timecop.freeze(10.days.from_now){ InsertBillingSubscriptions.check_trial(sub['id']) }
|
|
|
|
updated = Qx.fetch(:billing_subscriptions, sub['id']).last
|
|
|
|
expect(updated['status']).to eq('active')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|