Welcome to mirror list, hosted at ThFree Co, Russian Federation.

settings_finder_spec.rb « settings « vs_code « finders « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b7b4308bbbd1544db29b50c56ea6b6aecaf1a693 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe VsCode::Settings::SettingsFinder, feature_category: :web_ide do
  let_it_be(:user) { create(:user) }

  describe '#execute' do
    context 'when nil is passed in as the list of settings' do
      let(:finder) { described_class.new(user, nil) }

      subject { finder.execute }

      context 'when user has no settings' do
        it 'returns an empty array' do
          expect(subject).to eq([])
        end
      end

      context 'when user has settings' do
        before do
          create(:vscode_setting, user: user)
        end

        it 'returns an array of settings' do
          expect(subject.length).to eq(1)
          expect(subject[0].user_id).to eq(user.id)
          expect(subject[0].setting_type).to eq('settings')
        end
      end
    end

    context 'when a list of settings is passed, filters by the setting' do
      let_it_be(:setting) { create(:vscode_setting, user: user) }

      context 'when user has no settings with that type' do
        subject { finder.execute }

        it 'returns an empty array' do
          finder = described_class.new(user, ['profile'])
          expect(finder.execute).to eq([])
        end
      end

      context 'when user does have settings with the type' do
        subject { finder.execute }

        it 'returns the record when a single setting exists' do
          result = described_class.new(user, ['settings']).execute
          expect(result.length).to eq(1)
          expect(result[0].user_id).to eq(user.id)
          expect(result[0].setting_type).to eq('settings')
        end

        it 'returns multiple records when more than one setting exists' do
          create(:vscode_setting, user: user, setting_type: 'profile')

          result = described_class.new(user, %w[settings profile]).execute
          expect(result.length).to eq(2)
        end
      end
    end
  end
end