File: pins_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 (76 lines) | stat: -rw-r--r-- 2,316 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Pinning navigation menu items', feature_category: :navigation do
  let(:user) { create(:user) }
  let(:menu_item_ids) { %w[item4 item7] }
  let(:other_panel_data) { { 'group' => ['some_item_id'] } }

  before do
    user.update!(pinned_nav_items: other_panel_data)
    sign_in(user)
  end

  describe 'PUT /-/users/pins' do
    before do
      put pins_path, params: params, headers: { 'ACCEPT' => 'application/json' }
    end

    context 'with valid params' do
      let(:panel) { 'project' }
      let(:params) { { menu_item_ids: menu_item_ids, panel: panel } }

      it 'saves the menu_item_ids for the correct panel' do
        expect(user.pinned_nav_items).to include(panel => menu_item_ids)
      end

      it 'does not change menu_item_ids of other panels' do
        expect(user.pinned_nav_items).to include(other_panel_data)
      end

      it 'responds OK' do
        expect(response).to have_gitlab_http_status(:ok)
      end
    end

    context 'with invalid params' do
      shared_examples 'unchanged data and error response' do
        it 'does not modify existing panel data' do
          expect(user.reload.pinned_nav_items).to eq(other_panel_data)
        end

        it 'responds with error' do
          expect(response).to have_gitlab_http_status(:bad_request)
        end
      end

      context 'when panel name is unknown' do
        let(:params) { { menu_item_ids: menu_item_ids, panel: 'something_else' } }

        it_behaves_like 'unchanged data and error response'
      end

      context 'when menu_item_ids is not array of strings' do
        let(:params) { { menu_item_ids: 'not_an_array', panel: 'project' } }

        it_behaves_like 'unchanged data and error response'
      end

      context 'when params are not permitted' do
        let(:params) { { random_param: 'random_value' } }

        it_behaves_like 'unchanged data and error response'
      end
    end

    context 'when request size exceeds 100 kilobyte' do
      let(:too_large_string) { 'a' * 200.kilobytes }
      let(:params) { { menu_item_ids: [too_large_string], panel: 'project' } }

      it 'responds with :payload_too_large' do
        expect(response).to have_gitlab_http_status(:payload_too_large)
      end
    end
  end
end