From 949b515bfb76f5d68881d3bb79f1e39766b5e51f Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 31 Jan 2024 19:05:38 +0000 Subject: [PATCH] Replaces stubs for non-existing customer test case --- .../deletes_the_credit_card_clone.yml | 106 ++++++++++++++++-- spec/lib/stripe/credit_card_remover_spec.rb | 15 ++- 2 files changed, 105 insertions(+), 16 deletions(-) diff --git a/spec/fixtures/vcr_cassettes/Stripe-v10.6.0/Stripe_CreditCardRemover/_remove/Stripe_customer_does_not_exist/deletes_the_credit_card_clone.yml b/spec/fixtures/vcr_cassettes/Stripe-v10.6.0/Stripe_CreditCardRemover/_remove/Stripe_customer_does_not_exist/deletes_the_credit_card_clone.yml index 79a0e2a60b..9404e420d1 100644 --- a/spec/fixtures/vcr_cassettes/Stripe-v10.6.0/Stripe_CreditCardRemover/_remove/Stripe_customer_does_not_exist/deletes_the_credit_card_clone.yml +++ b/spec/fixtures/vcr_cassettes/Stripe-v10.6.0/Stripe_CreditCardRemover/_remove/Stripe_customer_does_not_exist/deletes_the_credit_card_clone.yml @@ -13,8 +13,6 @@ http_interactions: - Bearer Content-Type: - application/x-www-form-urlencoded - X-Stripe-Client-Telemetry: - - '{"last_request_metrics":{"request_id":"req_nVxOB6GyIQjq2r","request_duration_ms":846}}' Stripe-Version: - '2023-10-16' X-Stripe-Client-User-Agent: @@ -34,11 +32,11 @@ http_interactions: Server: - nginx Date: - - Wed, 31 Jan 2024 18:56:27 GMT + - Wed, 31 Jan 2024 19:04:42 GMT Content-Type: - application/json Content-Length: - - '930' + - '1084' Connection: - keep-alive Access-Control-Allow-Credentials: @@ -59,11 +57,11 @@ http_interactions: default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; style-src 'self' Idempotency-Key: - - b8b37c57-b454-4fb7-b611-cb1df87378a5 + - 47d21ec0-d1bb-41dc-98de-94c985992cb1 Original-Request: - - req_gPgo73OOv0lXWh + - req_DzVgCjW9ZQ146O Request-Id: - - req_gPgo73OOv0lXWh + - req_DzVgCjW9ZQ146O Stripe-Should-Retry: - 'false' Stripe-Version: @@ -78,7 +76,7 @@ http_interactions: encoding: UTF-8 string: |- { - "id": "pm_1OeixTKuuB1fWySnH9EJcJkx", + "id": "pm_1Oej5SKuuB1fWySnd7KqZATn", "object": "payment_method", "billing_details": { "address": { @@ -101,6 +99,11 @@ http_interactions: "cvc_check": "unchecked" }, "country": "US", + "display_brand": { + "label": "Visa", + "logo_url": "https://b.stripecdn.com/cards-metadata/logos/card-visa.svg", + "type": "visa" + }, "exp_month": 8, "exp_year": 2025, "fingerprint": "6E6tgVjx6U65iHFV", @@ -118,11 +121,94 @@ http_interactions: }, "wallet": null }, - "created": 1706727387, + "created": 1706727882, "customer": null, "livemode": false, "metadata": {}, "type": "card" } - recorded_at: Wed, 31 Jan 2024 18:56:27 GMT + recorded_at: Wed, 31 Jan 2024 19:04:42 GMT +- request: + method: get + uri: https://api.stripe.com/v1/customers/non_existing_customer_id + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Stripe/v1 RubyBindings/10.6.0 + Authorization: + - Bearer + Content-Type: + - application/x-www-form-urlencoded + X-Stripe-Client-Telemetry: + - '{"last_request_metrics":{"request_id":"req_DzVgCjW9ZQ146O","request_duration_ms":719}}' + Stripe-Version: + - '2023-10-16' + X-Stripe-Client-User-Agent: + - '{"bindings_version":"10.6.0","lang":"ruby","lang_version":"3.1.4 p223 (2023-03-30)","platform":"x86_64-linux","engine":"ruby","publisher":"stripe","uname":"Linux + version 6.5.0-15-generic (buildd@bos03-amd64-040) (x86_64-linux-gnu-gcc-12 + (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38) + #15~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan 12 18:54:30 UTC 2","hostname":"ff-LAT"}' + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + response: + status: + code: 404 + message: Not Found + headers: + Server: + - nginx + Date: + - Wed, 31 Jan 2024 19:04:43 GMT + Content-Type: + - application/json + Content-Length: + - '339' + Connection: + - keep-alive + Access-Control-Allow-Credentials: + - 'true' + Access-Control-Allow-Methods: + - GET,HEAD,PUT,PATCH,POST,DELETE + Access-Control-Allow-Origin: + - "*" + Access-Control-Expose-Headers: + - Request-Id, Stripe-Manage-Version, Stripe-Should-Retry, X-Stripe-External-Auth-Required, + X-Stripe-Privileged-Session-Required + Access-Control-Max-Age: + - '300' + Cache-Control: + - no-cache, no-store + Content-Security-Policy: + - report-uri https://q.stripe.com/csp-report?p=v1%2Fcustomers%2F%3Acustomer; + block-all-mixed-content; default-src 'none'; base-uri 'none'; form-action + 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; + style-src 'self' + Request-Id: + - req_kfp8zfiuKDQeCw + Stripe-Version: + - '2023-10-16' + Vary: + - Origin + X-Stripe-Routing-Context-Priority-Tier: + - api-testmode + Strict-Transport-Security: + - max-age=63072000; includeSubDomains; preload + body: + encoding: UTF-8 + string: | + { + "error": { + "code": "resource_missing", + "doc_url": "https://stripe.com/docs/error-codes/resource-missing", + "message": "No such customer: 'non_existing_customer_id'", + "param": "id", + "request_log_url": "https://dashboard.stripe.com/test/logs/req_kfp8zfiuKDQeCw?t=1706727882", + "type": "invalid_request_error" + } + } + recorded_at: Wed, 31 Jan 2024 19:04:43 GMT recorded_with: VCR 6.2.0 diff --git a/spec/lib/stripe/credit_card_remover_spec.rb b/spec/lib/stripe/credit_card_remover_spec.rb index 4b678c5c79..7c48d0f3ec 100644 --- a/spec/lib/stripe/credit_card_remover_spec.rb +++ b/spec/lib/stripe/credit_card_remover_spec.rb @@ -89,13 +89,16 @@ describe Stripe::CreditCardRemover do end context 'Stripe customer does not exist' do - it 'deletes the credit card clone' do - allow(Stripe::Customer).to receive(:retrieve).and_return(nil) + let(:non_existing_customer_id) { 'non_existing_customer_id' } - expect_any_instance_of(Stripe::CreditCardCloneDestroyer).to receive(:destroy_clones).with( - credit_card - ) - Stripe::CreditCardRemover.new(credit_card).call + before do + credit_card.update_attribute :gateway_customer_profile_id, non_existing_customer_id + end + + it 'deletes the credit card clone' do + expect { + Stripe::CreditCardRemover.new(credit_card).call + }.to raise_error Stripe::InvalidRequestError end end end