Sha256: 4259849ff16aa25deb9de25ab6ff54ba3734f53e1ace0e6f5d154ed62e28d6a5

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

require 'spec_helper'

describe SolidusBraintree::ConfigurationsController, type: :controller do
  routes { SolidusBraintree::Engine.routes }

  let!(:store_1) { create :store }
  let!(:store_2) { create :store }

  stub_authorization!

  describe "GET #list" do
    subject { get :list }

    it "assigns all store's configurations as @configurations" do
      subject
      expect(assigns(:configurations)).
        to eq [store_1.braintree_configuration, store_2.braintree_configuration]
    end

    it "renders the correct view" do
      expect(subject).to render_template :list
    end
  end

  describe "POST #update" do
    subject { post :update, params: configurations_params }

    let(:paypal_button_color) { 'blue' }
    let(:configurations_params) do
      {
        configurations: {
          configuration_fields: {
            store_1.braintree_configuration.id.to_s => { paypal: true, apple_pay: true },
            store_2.braintree_configuration.id.to_s => {
              paypal: true,
              apple_pay: false,
              preferred_paypal_button_color: paypal_button_color
            }
          }
        }
      }
    end

    context "with valid parameters" do
      it "updates the configuration" do
        expect { subject }.to change { store_1.braintree_configuration.reload.paypal }.
          from(false).to(true)
      end

      it "displays a success message to the user" do
        subject
        expect(flash[:success]).to eq "Successfully updated Braintree configurations."
      end

      it "displays all configurations" do
        expect(subject).to redirect_to action: :list
      end
    end

    context "with invalid parameters" do
      let(:paypal_button_color) { 'invalid-color' }

      it "displays an error message to the user" do
        subject
        expect(flash[:error]).to eq "An error occurred while updating Braintree configurations."
      end

      it "returns the user to the edit page" do
        expect(subject).to redirect_to action: :list
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
solidus_paypal_braintree-2.0.0 spec/controllers/solidus_paypal_braintree/configurations_controller_spec.rb
solidus_braintree-2.0.0 spec/controllers/solidus_braintree/configurations_controller_spec.rb