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

mark_as_spam_spec.rb « snippets « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 77fd6cddc095921c98488221a5cb102a5cea51e0 (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
65
66
67
68
69
70
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Mark snippet as spam' do
  include GraphqlHelpers
  include AfterNextHelpers

  let_it_be(:admin) { create(:admin) }
  let_it_be(:other_user) { create(:user) }
  let_it_be(:snippet) { create(:personal_snippet) }
  let_it_be(:user_agent_detail) { create(:user_agent_detail, subject: snippet) }

  let(:current_user) { snippet.author }

  let(:snippet_gid) { snippet.to_global_id.to_s }
  let(:mutation) do
    variables = {
      id: snippet_gid
    }

    graphql_mutation(:mark_as_spam_snippet, variables)
  end

  def mutation_response
    graphql_mutation_response(:mark_as_spam_snippet)
  end

  shared_examples 'does not mark the snippet as spam' do
    specify do
      expect do
        post_graphql_mutation(mutation, current_user: current_user)
      end.not_to change { snippet.reload.user_agent_detail.submitted }
    end
  end

  it_behaves_like 'when the snippet is not found'

  context 'when the user does not have permission' do
    let(:current_user) { other_user }

    it_behaves_like 'a mutation that returns top-level errors',
                    errors: [Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR]

    it_behaves_like 'does not mark the snippet as spam'
  end

  context 'when the user has permission' do
    context 'when user can not mark snippet as spam' do
      it_behaves_like 'does not mark the snippet as spam'
    end

    context 'when user can mark snippet as spam' do
      let(:current_user) { admin }

      before do
        stub_application_setting(akismet_enabled: true)
      end

      it 'marks snippet as spam' do
        expect_next(Spam::AkismetMarkAsSpamService, target: snippet)
          .to receive(:execute).and_return(true)

        post_graphql_mutation(mutation, current_user: current_user)

        expect(graphql_errors).to be_blank
      end
    end
  end
end