2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Resolvers::Clusters::AgentTokensResolver do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
it { expect(described_class.type).to eq(Types::Clusters::AgentTokenType) }
|
|
|
|
it { expect(described_class.null).to be_truthy }
|
2023-07-09 08:55:56 +05:30
|
|
|
it { expect(described_class.arguments.keys).to be_empty }
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
describe '#resolve' do
|
|
|
|
let(:agent) { create(:cluster_agent) }
|
2022-04-04 11:22:00 +05:30
|
|
|
let(:user) { create(:user, developer_projects: [agent.project]) }
|
2021-11-18 22:05:49 +05:30
|
|
|
let(:ctx) { Hash(current_user: user) }
|
|
|
|
|
|
|
|
let!(:matching_token1) { create(:cluster_agent_token, agent: agent, last_used_at: 5.days.ago) }
|
|
|
|
let!(:matching_token2) { create(:cluster_agent_token, agent: agent, last_used_at: 2.days.ago) }
|
2023-07-09 08:55:56 +05:30
|
|
|
let!(:revoked_token) { create(:cluster_agent_token, :revoked, agent: agent) }
|
2021-11-18 22:05:49 +05:30
|
|
|
let!(:other_token) { create(:cluster_agent_token) }
|
|
|
|
|
|
|
|
subject { resolve(described_class, obj: agent, ctx: ctx) }
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
it 'returns active tokens associated with the agent, ordered by last_used_at' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(subject).to eq([matching_token2, matching_token1])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user does not have permission' do
|
2022-04-04 11:22:00 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
agent.project.add_reporter(user)
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|