Sha256: 1f2812540480b4db71c5f73b5ad2ed31f1dc6498617c9d557a1eff2a326081ca

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

module DutyCalculator
  describe Configuration do
    describe ".transform_params" do
      context "for a single product" do
        let(:params) do
          {
            from: "US",
            to: "CA",
            shipping_mode: "USPS",
            insurance: 0.0,
            currency: "USD",
            cat: [ "1234.00" ],
            hs: [ "CA" ],
            sku: [ "300101" ],
            qty: [ 1 ]
          }
        end

        it "makes a hash with numerical index keys for array values" do
          transformed = DutyCalculator::Calculation.transform_params(params)

          expect(transformed["from"]).to eq(params[:from])
          expect(transformed["cat"]).to eq({ 0 => params[:cat].first })
        end
      end

      context "for multiple products" do
        let(:params) do
          {
            from: "US",
            to: "CA",
            shipping_mode: "USPS",
            insurance: 0.0,
            currency: "USD",
            cat: [ "1234.00", "5678.00" ],
            hs: [ "CA", "CA" ],
            sku: [ "300101", "300102" ],
            qty: [ 1, 2 ]
          }
        end

        it "makes a hash with numerical index keys for array values" do
          transformed = DutyCalculator::Calculation.transform_params(params)

          expect(transformed["from"]).to eq(params[:from])
          expect(transformed["cat"]).to eq({ 0 => params[:cat].first, 1 => params[:cat].last })
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duty_calculator-0.0.5 spec/duty_calculator/calculation_spec.rb