spec unsubscribe webhook
This commit is contained in:
parent
dca6c7ddc9
commit
83e7ae2711
|
@ -31,12 +31,10 @@ module DiscourseSubscriptions
|
|||
|
||||
if customer
|
||||
customer.delete
|
||||
#
|
||||
# binding.pry
|
||||
#
|
||||
# user = ::User.find(customer.user_id)
|
||||
# group = plan_group(event[:plan])
|
||||
# group.remove(user) if group
|
||||
|
||||
user = ::User.find(customer.user_id)
|
||||
group = plan_group(event[:plan])
|
||||
group.remove(user) if group
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,17 +22,12 @@ module DiscourseSubscriptions
|
|||
expect(response.status).to eq 200
|
||||
end
|
||||
|
||||
it "cancels a subscription" do
|
||||
user = Fabricate(:user)
|
||||
group = Fabricate(:group, name: 'subscribers-group')
|
||||
|
||||
customer = Fabricate(
|
||||
:customer,
|
||||
customer_id: 'c_575768',
|
||||
product_id: 'p_8654',
|
||||
user_id: user.id
|
||||
)
|
||||
describe "canceling a subscription" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:group) { Fabricate(:group, name: 'subscribers-group') }
|
||||
let(:customer) { Fabricate(:customer, customer_id: 'c_575768', product_id: 'p_8654', user_id: user.id) }
|
||||
|
||||
before do
|
||||
event = {
|
||||
type: 'customer.subscription.deleted',
|
||||
customer: customer.customer_id,
|
||||
|
@ -40,14 +35,27 @@ module DiscourseSubscriptions
|
|||
}
|
||||
|
||||
::Stripe::Webhook
|
||||
.expects(:construct_event)
|
||||
.stubs(:construct_event)
|
||||
.returns(event)
|
||||
|
||||
group.add(user)
|
||||
end
|
||||
|
||||
it "deletes the customer" do
|
||||
expect {
|
||||
post "/s/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(response.status).to eq 200
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue