From bae128738bf4ee0781b6cef0f8d7bd4bc6dde9b9 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 16 May 2020 16:25:18 +0100 Subject: [PATCH] Add spec for return authorizations controller --- .../return_authorizations_controller_spec.rb | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 spec/controllers/spree/admin/return_authorizations_controller_spec.rb diff --git a/spec/controllers/spree/admin/return_authorizations_controller_spec.rb b/spec/controllers/spree/admin/return_authorizations_controller_spec.rb new file mode 100644 index 0000000000..6c28642da5 --- /dev/null +++ b/spec/controllers/spree/admin/return_authorizations_controller_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' + +module Spree + module Admin + describe ReturnAuthorizationsController, type: :controller do + include AuthenticationWorkflow + + let(:order) do + create(:order, :with_line_item, :completed, + distributor: create(:distributor_enterprise) ) + end + + before do + login_as_admin + + # Pay the order + order.payments.first.complete + order.updater.update_payment_state + + # Ship the order + order.reload.shipment.ship! + end + + it "creates and updates a return authorization" do + # Create return authorization + spree_post :create, order_id: order.number, + return_authorization: { amount: "20.2", reason: "broken" } + + expect(response).to redirect_to spree.admin_order_return_authorizations_url(order.number) + return_authorization = order.return_authorizations.first + expect(return_authorization.amount.to_s).to eq "20.2" + expect(return_authorization.reason.to_s).to eq "broken" + + # Update return authorization + spree_put :update, id: return_authorization.id, + return_authorization: { amount: "10.2", reason: "half broken" } + + expect(response).to redirect_to spree.admin_order_return_authorizations_url(order.number) + return_authorization.reload + expect(return_authorization.amount.to_s).to eq "10.2" + expect(return_authorization.reason.to_s).to eq "half broken" + end + end + end +end