Remove I18n keys from Pay/Stripe/Chkout Ctrllers spec

This commit is contained in:
cyrillefr
2023-02-15 10:16:01 +01:00
parent f9f6abf740
commit 7c24f6b26f
10 changed files with 45 additions and 38 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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