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

agent_tokens_finder_spec.rb « clusters « finders « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 619aca891c173a3737ddc390821c5548b6141876 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Clusters::AgentTokensFinder do
  describe '#execute' do
    let_it_be(:project) { create(:project) }
    let(:user) { create(:user, maintainer_projects: [project]) }
    let(:agent) { create(:cluster_agent, project: project) }
    let(:agent_id) { agent.id }

    let!(:matching_agent_tokens) do
      [
        create(:cluster_agent_token, agent: agent),
        create(:cluster_agent_token, :revoked, agent: agent)
      ]
    end

    subject(:execute) { described_class.new(project, user, agent_id).execute }

    it 'returns the tokens of the specified agent' do
      # creating a token in a different agent to make sure it will not be included in the result
      create(:cluster_agent_token, agent: create(:cluster_agent))

      expect(execute).to match_array(matching_agent_tokens)
    end

    context 'when user does not have permission' do
      let(:user) { create(:user) }

      before do
        project.add_reporter(user)
      end

      it 'raises an error' do
        expect { execute }.to raise_error(ActiveRecord::RecordNotFound)
      end
    end

    context 'when agent does not exist' do
      let(:agent_id) { non_existing_record_id }

      it 'raises an error' do
        expect { execute }.to raise_error(ActiveRecord::RecordNotFound)
      end
    end
  end
end