File: custom_emoji_query_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 (56 lines) | stat: -rw-r--r-- 1,988 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'getting custom emoji within namespace', feature_category: :shared do
  include GraphqlHelpers

  let_it_be(:current_user) { create(:user) }
  let_it_be(:group) { create(:group, :private, developers: current_user) }
  let_it_be(:custom_emoji) { create(:custom_emoji, group: group, file: 'http://example.com/test.png') }

  describe "Query CustomEmoji on Group" do
    def custom_emoji_query(group)
      fields = all_graphql_fields_for('Group')
      # TODO: Set required timelogs args elsewhere https://gitlab.com/gitlab-org/gitlab/-/issues/325499
      fields.selection['timelogs(startDate: "2021-03-01" endDate: "2021-03-30")'] = fields.selection.delete('timelogs')

      graphql_query_for(
        'group',
        { fullPath: group.full_path },
        fields
      )
    end

    it 'returns emojis when authorised' do
      post_graphql(custom_emoji_query(group), current_user: current_user)

      expect(response).to have_gitlab_http_status(:ok)
      expect(graphql_data['group']['customEmoji']['nodes'].count).to eq(1)
      expect(graphql_data['group']['customEmoji']['nodes'].first['name']).to eq(custom_emoji.name)
      expect(graphql_data['group']['customEmoji']['nodes'].first['url']).to eq(custom_emoji.file)
    end

    it 'returns nil group when unauthorised' do
      user = create(:user)
      post_graphql(custom_emoji_query(group), current_user: user)

      expect(graphql_data['group']).to be_nil
    end

    context 'when asset proxy is configured' do
      before do
        stub_asset_proxy_setting(
          enabled: true,
          secret_key: 'shared-secret',
          url: 'https://assets.example.com'
        )
      end

      it 'uses the proxied url' do
        post_graphql(custom_emoji_query(group), current_user: current_user)
        expect(graphql_data['group']['customEmoji']['nodes'].first['url']).to start_with('https://assets.example.com')
      end
    end
  end
end