* Enable Rails cops * Fix Rails/DynamicFindBy * Fix Rails/HttpStatus * Fix Rails/Blank * Fix Rails/RequestReferer * Fix Rails/ActiveRecordAliases * Fix Rails/FindBy * Fix Rails/Presence * Fix Rails/Delegate * Fix Rails/Validation * Fix Rails/PluralizationGrammar * Fix Rails/Present * Fix Rails/Output * Fix Rails/Blank * Fix Rails/FilePath * Fix Rails/InverseOf * Fix Rails/LexicallyScopedActionFilter * Add Rails/OutputSafety to TODO * Add Rails/HasManyOrHasOneDependent to TODO * Add Rails/SkipsModelValidations to TODO
34 lines
1 KiB
Ruby
34 lines
1 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "StripeCancellations", type: :request do
|
|
let(:user) { create(:user) }
|
|
let(:stripe_helper) { StripeMock.create_test_helper }
|
|
|
|
before do
|
|
StripeMock.start
|
|
allow_any_instance_of(StripeCancellationsController).to receive(:verify_stripe_signature).and_return(true)
|
|
end
|
|
|
|
after { StripeMock.stop }
|
|
|
|
# rubocop:disable RSpec/ExampleLength
|
|
it "mocks a stripe cancellation webhook" do
|
|
customer = Stripe::Customer.create(
|
|
email: user.email,
|
|
source: stripe_helper.generate_card_token,
|
|
)
|
|
MembershipService.new(customer, user, 12).subscribe_customer
|
|
user.reload
|
|
expect(user.monthly_dues).not_to eq(0)
|
|
|
|
event = StripeMock.mock_webhook_event(
|
|
"customer.subscription.deleted",
|
|
customer: user.stripe_id_code, total_count: 1,
|
|
)
|
|
post "/stripe_cancellations", params: event.as_json
|
|
user.reload
|
|
expect(user.monthly_dues).to eq(0)
|
|
expect(response).to have_http_status(:ok)
|
|
end
|
|
# rubocop:enable RSpec/ExampleLength
|
|
end
|