summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/slash_commands/presenters/access_spec.rb
blob: 804184a7173da8244674403385ad81fc7cf48ba0 (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
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::SlashCommands::Presenters::Access do
  shared_examples_for 'displays an error message' do
    it do
      expect(subject[:text]).to match(error_message)
      expect(subject[:response_type]).to be(:ephemeral)
    end
  end

  describe '#access_denied' do
    let(:project) { build(:project) }

    subject { described_class.new.access_denied(project) }

    it { is_expected.to be_a(Hash) }

    it_behaves_like 'displays an error message' do
      let(:error_message) { 'you do not have access to the GitLab project' }
    end
  end

  describe '#generic_access_denied' do
    subject { described_class.new.generic_access_denied }

    it { is_expected.to be_a(Hash) }

    it_behaves_like 'displays an error message' do
      let(:error_message) { 'You are not allowed to perform the given chatops command.' }
    end
  end

  describe '#deactivated' do
    subject { described_class.new.deactivated }

    it { is_expected.to be_a(Hash) }

    it_behaves_like 'displays an error message' do
      let(:error_message) { 'your account has been deactivated by your administrator' }
    end
  end

  describe '#not_found' do
    subject { described_class.new.not_found }

    it { is_expected.to be_a(Hash) }

    it 'tells the user the resource was not found' do
      expect(subject[:text]).to match("not found!")
      expect(subject[:response_type]).to be(:ephemeral)
    end
  end

  describe '#authorize' do
    context 'with an authorization URL' do
      subject { described_class.new('http://authorize.me').authorize }

      it { is_expected.to be_a(Hash) }

      it 'tells the user to authorize' do
        expect(subject[:text]).to match("connect your GitLab account")
        expect(subject[:response_type]).to be(:ephemeral)
      end
    end

    context 'without authorization url' do
      subject { described_class.new.authorize }

      it { is_expected.to be_a(Hash) }

      it 'tells the user to authorize' do
        expect(subject[:text]).to match("Couldn't identify you")
        expect(subject[:response_type]).to be(:ephemeral)
      end
    end
  end
end