Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCR integration #320

Merged
merged 9 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,54 @@ Here is an example:

image:docs/make-boot.png["Booting with Make"]

=== Tooling
=== API Testing

HTTP API Specs use the VCR Gem to mock calls to external APIs using a record and replay model.
https://github.com/vcr/vcr

Usage: https://benoittgt.github.io/vcr/#/

Cassettes are stored in spec/fixtures/vcr_cassettes
If an API changes due to version, response, etc... you will need to rebuild cassettes for those specs.
Delete the directory and/or files for the specs that have changed.
It is ok to delete all cassettes and regenerate everything.
This can be done in your local development environment.

VCR is configured in spec/spec_helper.rb

You must filter any API keys before you check in cassettes to prevent keys in GitHub
https://benoittgt.github.io/vcr/#/configuration/filter_sensitive_data

To enable vcr recording on a given spec, add a vcr hook to the spec as follows

it 'does not change payment intent', :vcr do
expect { payment_intent }.not_to(change(payment, :payment_intent))
end

To turn off VCR HTTP request interception for a given spec or block, add

VCR.turned_off do
make_request "In VCR.turned_off block"
end

make_request "Outside of VCR.turned_off block"

VCR.turn_off!
make_request "After calling VCR.turn_off!"

VCR.turned_on do
make_request "In VCR.turned_on block"
end

VCR.turn_on!
make_request "After calling VCR.turn_on!"

https://benoittgt.github.io/vcr/#/cassettes/no_cassette


To turn off VCR by default for http requests see:
https://benoittgt.github.io/vcr/#/configuration/allow_http_connections_when_no_cassette


==== Adding Site Admin

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def sent
private

def mark_payment_completed
Payment.transaction do
kigster marked this conversation as resolved.
Show resolved Hide resolved
begin
@payment.request_completed
flash.now[:notice] = 'Payment has been received and marked as completed.'
rescue StandardError => e
Expand Down
14 changes: 7 additions & 7 deletions app/models/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,17 @@ def mark_received
status_received!
end

# In transaction,
# mark payment received and ticket request completed
# Send off PaymentMailer for payment received
def request_completed
mark_received
ticket_request.mark_complete
Payment.transaction do
# set payment and ticket request status
mark_received
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

ticket_request.mark_complete

# Deliver the email asynchronously
PaymentMailer.payment_received(self).deliver_later

self.reload
# Deliver the email asynchronously
PaymentMailer.payment_received(self).deliver_later
end
end

private
Expand Down