File: settings_finder_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 (60 lines) | stat: -rw-r--r-- 1,873 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
56
57
58
59
60
# 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
        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
        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: 'globalState')

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