summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/import_export/project_tree_loader_spec.rb
blob: b22de5a3f7be670a02cbc59f36601b9f5f9a1d63 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::ImportExport::ProjectTreeLoader do
  let(:fixture) { 'spec/fixtures/lib/gitlab/import_export/with_duplicates.json' }
  let(:project_tree) { JSON.parse(File.read(fixture)) }

  context 'without de-duplicating entries' do
    let(:parsed_tree) do
      subject.load(fixture)
    end

    it 'parses the JSON into the expected tree' do
      expect(parsed_tree).to eq(project_tree)
    end

    it 'does not de-duplicate entries' do
      expect(parsed_tree['duped_hash_with_id']).not_to be(parsed_tree['array'][0]['duped_hash_with_id'])
    end
  end

  context 'with de-duplicating entries' do
    let(:parsed_tree) do
      subject.load(fixture, dedup_entries: true)
    end

    it 'parses the JSON into the expected tree' do
      expect(parsed_tree).to eq(project_tree)
    end

    it 'de-duplicates equal values' do
      expect(parsed_tree['duped_hash_with_id']).to be(parsed_tree['array'][0]['duped_hash_with_id'])
      expect(parsed_tree['duped_hash_with_id']).to be(parsed_tree['nested']['duped_hash_with_id'])
      expect(parsed_tree['duped_array']).to be(parsed_tree['array'][1]['duped_array'])
      expect(parsed_tree['duped_array']).to be(parsed_tree['nested']['duped_array'])
    end

    it 'does not de-duplicate hashes without IDs' do
      expect(parsed_tree['duped_hash_no_id']).to eq(parsed_tree['array'][2]['duped_hash_no_id'])
      expect(parsed_tree['duped_hash_no_id']).not_to be(parsed_tree['array'][2]['duped_hash_no_id'])
    end

    it 'keeps single entries intact' do
      expect(parsed_tree['simple']).to eq(42)
      expect(parsed_tree['nested']['array']).to eq(["don't touch"])
    end
  end
end