require 'spec_helper'

describe Spree::Api::OrdersController, type: :controller do
  let(:user) { create(:admin_user) }

  before do
    allow(controller).to receive(:load_user)
    controller.instance_variable_set(:@current_api_user, user)
  end

  describe '#update' do
    subject do
      spree_put :update, {
        'id' => order.number,
        'format' => 'json',
        'order' => order_attributes,
      }
    end

    let(:order_attributes) do
      {
        "payments_attributes" => [
          {'source_attributes' => {'encrypted_attributes' => encrypted_attributes}},
        ],
      }
    end

    let(:encrypted_attributes) do
      {
        'number' => 'asdf',
        'month' => 'asdf',
        'year' => 'asdf',
        'verification_value' => 'asdf',
      }
    end

    let(:order) { create(:order, user: user) }

    it 'permits all the attributes' do
      expect_any_instance_of(Spree::Order).to receive(:update_attributes).with(order_attributes)
      subject
    end
  end
end
