From 7c24f6b26fee7916216554e1c9bf0242fafea87a Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Wed, 15 Feb 2023 10:16:01 +0100 Subject: [PATCH] Remove I18n keys from Pay/Stripe/Chkout Ctrllers spec --- spec/controllers/checkout_controller_spec.rb | 8 +++---- .../enterprises_controller_spec.rb | 2 +- .../paypal_controller_spec.rb | 4 +++- .../stripe_controller_spec.rb | 21 ++++++++++++------- .../payments/payments_controller_spec.rb | 10 ++++----- .../admin/payment_methods_controller_spec.rb | 4 ++-- .../admin/shipping_methods_controller_spec.rb | 3 ++- .../spree/credit_cards_controller_spec.rb | 13 ++++++------ .../spree/orders_controller_spec.rb | 12 +++++------ .../stripe/callbacks_controller_spec.rb | 6 +++--- 10 files changed, 45 insertions(+), 38 deletions(-) diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index 342c6444ee..e0661caaf7 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -36,7 +36,7 @@ describe CheckoutController, type: :controller do get :edit expect(response).to redirect_to shop_url - expect(flash[:info]).to eq I18n.t('order_cycle_closed') + expect(flash[:info]).to eq 'The order cycle you\'ve selected has just closed. Please try again!' end it "redirects home with message if hub is not ready for checkout" do @@ -50,7 +50,7 @@ describe CheckoutController, type: :controller do get :edit expect(response).to redirect_to root_url - expect(flash[:info]).to eq(I18n.t('order_cycles_closed_for_hub')) + expect(flash[:info]).to eq('The hub you have selected is temporarily closed for orders. Please try again later.') end describe "#update" do @@ -257,7 +257,7 @@ describe CheckoutController, type: :controller do spree_post :update, format: :json, order: {} expect(response.status).to eq(400) expect(response.body).to eq({ errors: {}, - flash: { error: I18n.t("checkout.failed") } }.to_json) + flash: { error: 'The checkout failed. Please let us know so that we can process your order.' } }.to_json) end it "returns a specific error on Spree::Core::GatewayError" do @@ -265,7 +265,7 @@ describe CheckoutController, type: :controller do spree_post :update, format: :json, order: {} expect(response.status).to eq(400) - flash_message = I18n.t(:spree_gateway_error_flash_for_checkout, error: "Gateway blow up") + flash_message = "There was a problem with your payment information: %s" % 'Gateway blow up' expect(json_response["flash"]["error"]).to eq flash_message end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index c9ee7b4437..d0f0c97c55 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -185,7 +185,7 @@ describe EnterprisesController, type: :controller do end it "shows a flash message with the error" do - expect(request.flash[:error]).to eq(I18n.t(:enterprise_shop_show_error)) + expect(request.flash[:error]).to eq('The shop you are looking for doesn\'t exist or is inactive on OFN. Please check other shops.') end end end diff --git a/spec/controllers/payment_gateways/paypal_controller_spec.rb b/spec/controllers/payment_gateways/paypal_controller_spec.rb index a86d0f3773..79b26849e0 100644 --- a/spec/controllers/payment_gateways/paypal_controller_spec.rb +++ b/spec/controllers/payment_gateways/paypal_controller_spec.rb @@ -55,7 +55,9 @@ module PaymentGateways expect(post(:confirm, params: { payment_method_id: payment_method.id })). to redirect_to checkout_path - expect(flash[:error]).to eq I18n.t(:payment_processing_failed) + expect(flash[:error]).to eq( + 'Payment could not be processed, please check the details you entered' + ) end end end diff --git a/spec/controllers/payment_gateways/stripe_controller_spec.rb b/spec/controllers/payment_gateways/stripe_controller_spec.rb index 3644ccb70a..3984a4a382 100644 --- a/spec/controllers/payment_gateways/stripe_controller_spec.rb +++ b/spec/controllers/payment_gateways/stripe_controller_spec.rb @@ -55,7 +55,7 @@ module PaymentGateways expect(order.completed?).to be true expect(response).to redirect_to order_path(order, order_token: order.token) - expect(flash[:notice]).to eq I18n.t(:order_processed_successfully) + expect(flash[:notice]).to eq 'Your order has been processed successfully' end end @@ -82,7 +82,8 @@ module PaymentGateways get :confirm, params: { payment_intent: "pi_123" } expect(response).to redirect_to shop_url - expect(flash[:info]).to eq I18n.t('order_cycle_closed') + expect(flash[:info]).to eq "The order cycle you've selected has just closed. \ +Please try again!" end end @@ -107,7 +108,8 @@ module PaymentGateways expect(order.completed?).to be false expect(response).to redirect_to checkout_path - expect(flash[:error]).to eq I18n.t(:payment_processing_failed) + expect(flash[:error]).to eq "Payment could not be processed, \ +please check the details you entered" end end @@ -119,7 +121,8 @@ module PaymentGateways expect(order.completed?).to be false expect(response).to redirect_to checkout_path - expect(flash[:error]).to eq I18n.t(:payment_processing_failed) + expect(flash[:error]).to eq "Payment could not be processed, \ +please check the details you entered" end end @@ -136,7 +139,8 @@ module PaymentGateways expect(order.completed?).to be false expect(response).to redirect_to checkout_path - expect(flash[:error]).to eq I18n.t(:payment_processing_failed) + expect(flash[:error]).to eq "Payment could not be processed, \ +please check the details you entered" end end @@ -171,7 +175,8 @@ module PaymentGateways get :confirm, params: { payment_intent: "pi_123" } expect(response).to redirect_to cart_path - expect(flash[:notice]).to eq I18n.t('checkout.payment_cancelled_due_to_stock') + expect(flash[:notice]).to eq "Payment cancelled: the checkout could not be \ +completed due to stock issues." expect(order.state).to eq "cart" expect(payment.state).to eq "void" @@ -280,7 +285,7 @@ module PaymentGateways get :authorize, params: { order_number: order.number, payment_intent: payment_intent } expect(response).to redirect_to order_path(order) - expect(flash[:error]).to eq("#{I18n.t('payment_could_not_process')}. error message") + expect(flash[:error]).to eq("The payment could not be processed. error message") payment.reload expect(payment.cvv_response_message).to be nil expect(payment.state).to eq("failed") @@ -303,7 +308,7 @@ module PaymentGateways get :authorize, params: { order_number: order.number, payment_intent: payment_intent } expect(response).to redirect_to order_path(order) - expect(flash[:error]).to eq("#{I18n.t('payment_could_not_process')}. ") + expect(flash[:error]).to eq("The payment could not be processed. ") payment.reload expect(payment.cvv_response_message).to eq("https://stripe.com/redirect") expect(payment.state).to eq("requires_authorization") diff --git a/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb b/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb index 896d6f60a1..d3aa8b4aaf 100644 --- a/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb +++ b/spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb @@ -85,7 +85,7 @@ describe Spree::Admin::PaymentsController, type: :controller do it "redirects to new payment page with flash error" do spree_post :create, payment: params, order_id: order.number - redirects_to_new_payment_page_with_flash_error(I18n.t('action_required')) + redirects_to_new_payment_page_with_flash_error('Action required') end end @@ -186,7 +186,7 @@ describe Spree::Admin::PaymentsController, type: :controller do spree_put :fire, params - expect(flash[:success]).to eq(I18n.t(:payment_updated)) + expect(flash[:success]).to eq('Payment Updated') end end @@ -222,7 +222,7 @@ describe Spree::Admin::PaymentsController, type: :controller do spree_put :fire, params - expect(flash[:success]).to eq(I18n.t(:payment_updated)) + expect(flash[:success]).to eq('Payment Updated') end end @@ -241,7 +241,7 @@ describe Spree::Admin::PaymentsController, type: :controller do it "resends the authorization email" do spree_put :fire, params - expect(flash[:success]).to eq(I18n.t(:payment_updated)) + expect(flash[:success]).to eq('Payment Updated') expect(PaymentMailer).to have_received(:authorize_payment) expect(mail_mock).to have_received(:deliver_later) end @@ -259,7 +259,7 @@ describe Spree::Admin::PaymentsController, type: :controller do spree_put :fire, params expect(payment).to_not receive(:unrecognized_event) - expect(flash[:error]).to eq(I18n.t(:cannot_perform_operation)) + expect(flash[:error]).to eq('Could not update the payment') end end end diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb index f1c818b141..a966cdf630 100644 --- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -206,7 +206,7 @@ module Spree it "does not save the payment method" do spree_put :update, params expect(response).to render_template :edit - expect(assigns(:payment_method).errors.messages[:stripe_account_owner]).to include I18n.t(:error_required) + expect(assigns(:payment_method).errors.messages[:stripe_account_owner]).to include 'can\'t be blank' end end @@ -216,7 +216,7 @@ module Spree it "does not save the payment method" do spree_put :update, params expect(response).to render_template :edit - expect(assigns(:payment_method).errors.messages[:stripe_account_owner]).to include I18n.t(:error_required) + expect(assigns(:payment_method).errors.messages[:stripe_account_owner]).to include 'can\'t be blank' end end end diff --git a/spec/controllers/spree/admin/shipping_methods_controller_spec.rb b/spec/controllers/spree/admin/shipping_methods_controller_spec.rb index 4d63db79db..dcc4f1c5c0 100644 --- a/spec/controllers/spree/admin/shipping_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/shipping_methods_controller_spec.rb @@ -41,7 +41,8 @@ describe Spree::Admin::ShippingMethodsController, type: :controller do spree_post :update, params - expect(flash[:error]).to match I18n.t(:calculator_preferred_value_error) + expect(flash[:error]).to match "Invalid input. \ +Please use only numbers. For example: 10, 5.5, -20" expect(response).to redirect_to spree.edit_admin_shipping_method_path(shipping_method) end end diff --git a/spec/controllers/spree/credit_cards_controller_spec.rb b/spec/controllers/spree/credit_cards_controller_spec.rb index 451a75f4e0..8c8c92bb2c 100644 --- a/spec/controllers/spree/credit_cards_controller_spec.rb +++ b/spec/controllers/spree/credit_cards_controller_spec.rb @@ -97,7 +97,7 @@ describe Spree::CreditCardsController, type: :controller do expect{ spree_post :new_from_token, params }.to_not change(Spree::CreditCard, :count) json_response = JSON.parse(response.body) - flash_message = I18n.t(:spree_gateway_error_flash_for_checkout, error: "Bup-bow...") + flash_message = "There was a problem with your payment information: %s" % 'Bup-bow...' expect(json_response["flash"]["error"]).to eq flash_message end end @@ -111,7 +111,7 @@ describe Spree::CreditCardsController, type: :controller do it "renders a flash error" do spree_put :update, params json_response = JSON.parse(response.body) - expect(json_response['flash']['error']).to eq I18n.t(:card_could_not_be_updated) + expect(json_response['flash']['error']).to eq 'Card could not be updated' end end @@ -143,7 +143,7 @@ describe Spree::CreditCardsController, type: :controller do it "renders an error" do spree_put :update, params json_response = JSON.parse(response.body) - expect(json_response['flash']['error']).to eq I18n.t(:card_could_not_be_updated) + expect(json_response['flash']['error']).to eq 'Card could not be updated' end end @@ -174,7 +174,7 @@ describe Spree::CreditCardsController, type: :controller do it "redirects to /account with a flash error, does not request deletion with Stripe" do expect(controller).to_not receive(:destroy_at_stripe) spree_delete :destroy, params - expect(flash[:error]).to eq I18n.t(:card_could_not_be_removed) + expect(flash[:error]).to eq 'Sorry, the card could not be removed' expect(response.status).to eq 200 end end @@ -206,7 +206,7 @@ describe Spree::CreditCardsController, type: :controller do it "doesn't delete the card" do expect{ spree_delete :destroy, params }.to_not change(Spree::CreditCard, :count) - expect(flash[:error]).to eq I18n.t(:card_could_not_be_removed) + expect(flash[:error]).to eq 'Sorry, the card could not be removed' expect(response.status).to eq 422 end end @@ -219,8 +219,7 @@ describe Spree::CreditCardsController, type: :controller do it "deletes the card and redirects to account_path" do expect{ spree_delete :destroy, params }.to change(Spree::CreditCard, :count).by(-1) - expect(flash[:success]).to eq I18n.t(:card_has_been_removed, - number: "x-#{card.last_digits}") + expect(flash[:success]).to eq "Your card has been removed (number: %s)" % "x-#{card.last_digits}" expect(response.status).to eq 200 end diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 2f5722ee93..c6ce2a43e6 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -122,7 +122,7 @@ describe Spree::OrdersController, type: :controller do get :edit expect(response).to redirect_to root_url - expect(flash[:info]).to eq(I18n.t('order_cycles_closed_for_hub')) + expect(flash[:info]).to eq('The hub you have selected is temporarily closed for orders. Please try again later.') end describe "when an item is in the cart" do @@ -161,7 +161,7 @@ describe Spree::OrdersController, type: :controller do it "displays a flash message when we view the cart" do get :edit expect(response.status).to eq 200 - expect(flash[:error]).to eq I18n.t('spree.orders.error_flash_for_unavailable_items') + expect(flash[:error]).to eq 'An item in your cart has become unavailable. Please update the selected quantities.' end end @@ -173,7 +173,7 @@ describe Spree::OrdersController, type: :controller do it "displays a flash message when we view the cart" do get :edit expect(response.status).to eq 200 - expect(flash[:error]).to eq I18n.t('spree.orders.error_flash_for_unavailable_items') + expect(flash[:error]).to eq 'An item in your cart has become unavailable. Please update the selected quantities.' end end end @@ -359,7 +359,7 @@ describe Spree::OrdersController, type: :controller do it "does not remove items, flash suggests cancellation" do spree_post :update, params - expect(flash[:error]).to eq I18n.t(:orders_cannot_remove_the_final_item) + expect(flash[:error]).to eq 'Cannot remove the final item from an order, please cancel the order instead.' expect(response).to redirect_to order_path(order) expect(order.reload.line_items.count).to eq 2 end @@ -460,7 +460,7 @@ describe Spree::OrdersController, type: :controller do expect(response).to have_http_status(:found) expect(response.body).to match(order_path(order)).and match("redirect") - expect(flash[:error]).to eq I18n.t(:orders_could_not_cancel) + expect(flash[:error]).to eq 'Sorry, the order could not be cancelled' end end @@ -479,7 +479,7 @@ describe Spree::OrdersController, type: :controller do expect(response).to have_http_status(:found) expect(response.body).to match(order_path(order)).and match("redirect") - expect(flash[:success]).to eq I18n.t(:orders_your_order_has_been_cancelled) + expect(flash[:success]).to eq 'Your order has been cancelled' end end end diff --git a/spec/controllers/stripe/callbacks_controller_spec.rb b/spec/controllers/stripe/callbacks_controller_spec.rb index a744ec0d09..de37d51cc8 100644 --- a/spec/controllers/stripe/callbacks_controller_spec.rb +++ b/spec/controllers/stripe/callbacks_controller_spec.rb @@ -45,7 +45,7 @@ describe Stripe::CallbacksController, type: :controller do it "renders a failure message" do allow(connector).to receive(:enterprise) { enterprise } spree_get :index, params - expect(flash[:notice]).to eq I18n.t('admin.controllers.enterprises.stripe_connect_cancelled') + expect(flash[:notice]).to eq 'Connection to Stripe has been cancelled' expect(response).to redirect_to edit_admin_enterprise_path(enterprise, anchor: 'payment_methods') end @@ -57,7 +57,7 @@ describe Stripe::CallbacksController, type: :controller do it "renders a failure message" do allow(connector).to receive(:enterprise) { enterprise } spree_get :index, params - expect(flash[:error]).to eq I18n.t('admin.controllers.enterprises.stripe_connect_fail') + expect(flash[:error]).to eq 'Sorry, the connection of your Stripe account failed' expect(response).to redirect_to edit_admin_enterprise_path(enterprise, anchor: 'payment_methods') end @@ -70,7 +70,7 @@ describe Stripe::CallbacksController, type: :controller do it "redirects to the enterprise edit path" do allow(connector).to receive(:enterprise) { enterprise } spree_get :index, params - expect(flash[:success]).to eq I18n.t('admin.controllers.enterprises.stripe_connect_success') + expect(flash[:success]).to eq 'Stripe account connected successfully' expect(response).to redirect_to edit_admin_enterprise_path(enterprise, anchor: 'payment_methods') end