File: map_export_fields_service_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (55 lines) | stat: -rw-r--r-- 1,716 bytes parent folder | download
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
50
51
52
53
54
55
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ExportCsv::MapExportFieldsService, feature_category: :team_planning do
  let(:selected_fields) { ['Title', 'Author username', 'state'] }
  let(:invalid_fields) { ['Title', 'Author Username', 'State', 'Invalid Field', 'Other Field'] }
  let(:data) do
    {
      'Requirement ID' => '1',
      'Title' => 'foo',
      'Description' => 'bar',
      'Author' => 'root',
      'Author Username' => 'admin',
      'Created At (UTC)' => '2023-02-01 15:16:35',
      'State' => 'opened',
      'State Updated At (UTC)' => '2023-02-01 15:16:35'
    }
  end

  describe '#execute' do
    it 'returns a hash with selected fields only' do
      result = described_class.new(selected_fields, data).execute

      expect(result).to be_a(Hash)
      expect(result.keys).to match_array(selected_fields.map(&:titleize))
    end

    context 'when the fields collection is empty' do
      it 'returns a hash with all fields' do
        result = described_class.new([], data).execute

        expect(result).to be_a(Hash)
        expect(result.keys).to match_array(data.keys)
      end
    end

    context 'when fields collection includes invalid fields' do
      it 'returns a hash with valid selected fields only' do
        result = described_class.new(invalid_fields, data).execute

        expect(result).to be_a(Hash)
        expect(result.keys).to eq(selected_fields.map(&:titleize))
      end
    end
  end

  describe '#invalid_fields' do
    it 'returns an array containing invalid fields' do
      result = described_class.new(invalid_fields, data).invalid_fields

      expect(result).to match_array(['Invalid Field', 'Other Field'])
    end
  end
end