From 315e89954038439e22af4dfdb08ad0a437499288 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 14 Oct 2021 18:20:10 +0200 Subject: [PATCH] [WIP] fix tests --- app/controllers/api/stripe_controller.rb | 2 + .../subscriptions/free-extend-modal.tsx | 4 + .../components/subscriptions/renew-modal.tsx | 14 +- .../src/javascript/models/subscription.ts | 3 +- app/models/cart_item/payment_schedule.rb | 6 +- app/models/cart_item/subscription.rb | 8 +- app/models/shopping_cart.rb | 2 +- app/services/cart_service.rb | 13 +- app/services/payment_schedule_service.rb | 14 +- app/services/subscriptions/subscribe.rb | 1 + ...5151_add_start_at_again_to_subscription.rb | 9 + db/schema.rb | 154 +- lib/integrity/checksum.rb | 33 +- lib/stripe/service.rb | 34 +- test/integration/reservations/create_test.rb | 83 +- .../subscriptions/create_as_admin_test.rb | 23 +- .../subscriptions/create_as_user_test.rb | 85 +- test/test_helper.rb | 2 + ...on_with_payment_schedule_coupon_wallet.yml | 5653 ++++++----------- ...ions_user_create_with_payment_schedule.yml | 1754 ++--- ...s_user_create_without_3ds_confirmation.yml | 2125 +++++++ 21 files changed, 4951 insertions(+), 5071 deletions(-) create mode 100644 db/migrate/20211014135151_add_start_at_again_to_subscription.rb create mode 100644 test/vcr_cassettes/subscriptions_user_create_without_3ds_confirmation.yml diff --git a/app/controllers/api/stripe_controller.rb b/app/controllers/api/stripe_controller.rb index c46f20e6d..1f6cc29a3 100644 --- a/app/controllers/api/stripe_controller.rb +++ b/app/controllers/api/stripe_controller.rb @@ -99,6 +99,8 @@ class API::StripeController < API::PaymentsController if subscription&.status == 'active' res = on_payment_success(subscription.latest_invoice.payment_intent, cart) render generate_payment_response(subscription.latest_invoice.payment_intent, 'subscription', res) + else + render generate_payment_response(subscription.latest_invoice.payment_intent, 'subscription', nil, subscription.id) end rescue Stripe::InvalidRequestError => e render json: e, status: :unprocessable_entity diff --git a/app/frontend/src/javascript/components/subscriptions/free-extend-modal.tsx b/app/frontend/src/javascript/components/subscriptions/free-extend-modal.tsx index 67d39a69c..595d0ac8c 100644 --- a/app/frontend/src/javascript/components/subscriptions/free-extend-modal.tsx +++ b/app/frontend/src/javascript/components/subscriptions/free-extend-modal.tsx @@ -26,6 +26,10 @@ interface FreeExtendModalProps { * Modal dialog shown to extend the current subscription of a customer, for free */ const FreeExtendModal: React.FC = ({ isOpen, toggleModal, subscription, customerId, onError, onSuccess }) => { + + // we do not render the modal if the subscription was not provided + if (!subscription) return null; + const { t } = useTranslation('admin'); const [expirationDate, setExpirationDate] = useState(new Date(subscription.expired_at)); diff --git a/app/frontend/src/javascript/components/subscriptions/renew-modal.tsx b/app/frontend/src/javascript/components/subscriptions/renew-modal.tsx index 03d6b3f32..1d9ec595e 100644 --- a/app/frontend/src/javascript/components/subscriptions/renew-modal.tsx +++ b/app/frontend/src/javascript/components/subscriptions/renew-modal.tsx @@ -35,6 +35,10 @@ interface RenewModalProps { * Modal dialog shown to renew the current subscription of a customer, for free */ const RenewModal: React.FC = ({ isOpen, toggleModal, subscription, customer, operator, onError, onSuccess }) => { + + // we do not render the modal if the subscription was not provided + if (!subscription) return null; + const { t } = useTranslation('admin'); const [expirationDate, setExpirationDate] = useState(new Date()); @@ -45,8 +49,6 @@ const RenewModal: React.FC = ({ isOpen, toggleModal, subscripti // on init, we compute the new expiration date useEffect(() => { - if (!subscription) return; - setExpirationDate(moment(subscription.expired_at) .add(subscription.plan.interval_count, subscription.plan.interval) .toDate()); @@ -57,13 +59,12 @@ const RenewModal: React.FC = ({ isOpen, toggleModal, subscripti // when the payment schedule is toggled (requested/ignored), we update the cart accordingly useEffect(() => { - if (!subscription) return; - setCart({ customer_id: customer.id, items: [{ subscription: { - plan_id: subscription.plan.id + plan_id: subscription.plan.id, + start_at: subscription.expired_at } }], payment_method: PaymentMethod.Other, @@ -102,9 +103,6 @@ const RenewModal: React.FC = ({ isOpen, toggleModal, subscripti setLocalPaymentModal(!localPaymentModal); }; - // we do not render the modal if the subscription was not provided - if (!subscription) return null; - return (