summaryrefslogtreecommitdiff
path: root/spec/lib/bulk_imports/common/transformers/hash_key_digger_spec.rb
blob: 2b33701653e1250cf147e02df5ecf893607afe9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BulkImports::Common::Transformers::HashKeyDigger do
  describe '#transform' do
    it 'when the key_path is an array' do
      data = { foo: { bar: :value } }
      key_path = %i[foo bar]
      transformed = described_class.new(key_path: key_path).transform(nil, data)

      expect(transformed).to eq(:value)
    end

    it 'when the key_path is not an array' do
      data = { foo: { bar: :value } }
      key_path = :foo
      transformed = described_class.new(key_path: key_path).transform(nil, data)

      expect(transformed).to eq({ bar: :value })
    end

    it "when the data is not a hash" do
      expect { described_class.new(key_path: nil).transform(nil, nil) }
        .to raise_error(ArgumentError, "Given data must be a Hash")
    end
  end
end