summaryrefslogtreecommitdiff
path: root/spec/requests/api/graphql/mutations/custom_emoji/create_spec.rb
blob: c91437fa355767b0167883b7a4c30a1484358e25 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Creation of a new Custom Emoji' do
  include GraphqlHelpers

  let_it_be(:current_user) { create(:user) }
  let_it_be(:group) { create(:group) }

  let(:attributes) do
    {
      name: 'my_new_emoji',
      url: 'https://example.com/image.png',
      group_path: group.full_path
    }
  end

  let(:mutation) do
    graphql_mutation(:create_custom_emoji, attributes)
  end

  context 'when the user has no permission' do
    it 'does not create custom emoji' do
      expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(CustomEmoji, :count)
    end
  end

  context 'when user has permission' do
    before do
      group.add_developer(current_user)
    end

    it 'creates custom emoji' do
      expect { post_graphql_mutation(mutation, current_user: current_user) }.to change(CustomEmoji, :count).by(1)

      gql_response = graphql_mutation_response(:create_custom_emoji)
      expect(gql_response['errors']).to eq([])
      expect(gql_response['customEmoji']['name']).to eq(attributes[:name])
      expect(gql_response['customEmoji']['url']).to eq(attributes[:url])
    end
  end
end