debian-mirror-gitlab/spec/requests/api/graphql/ci/config_variables_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
2.6 KiB
Ruby
Raw Permalink Normal View History

2022-10-11 01:57:18 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-06-20 00:43:36 +05:30
RSpec.describe 'Query.project(fullPath).ciConfigVariables(ref)', feature_category: :secrets_management do
2022-10-11 01:57:18 +05:30
include GraphqlHelpers
include ReactiveCachingHelpers
let_it_be(:content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end
let_it_be(:project) { create(:project, :custom_repo, :public, files: { '.gitlab-ci.yml' => content }) }
let_it_be(:user) { create(:user) }
let(:service) { Ci::ListConfigVariablesService.new(project, user) }
2023-04-23 21:23:45 +05:30
let(:ref) { project.default_branch }
2022-10-11 01:57:18 +05:30
let(:query) do
%(
query {
project(fullPath: "#{project.full_path}") {
2023-06-20 00:43:36 +05:30
ciConfigVariables(ref: "#{ref}") {
2022-10-11 01:57:18 +05:30
key
value
2022-11-25 23:54:43 +05:30
valueOptions
2022-10-11 01:57:18 +05:30
description
}
}
}
)
end
context 'when the user has the correct permissions' do
before do
project.add_maintainer(user)
allow(Ci::ListConfigVariablesService)
.to receive(:new)
.and_return(service)
end
context 'when the cache is not empty' do
before do
synchronous_reactive_cache(service)
end
it 'returns the CI variables for the config' do
expect(service)
.to receive(:execute)
2023-04-23 21:23:45 +05:30
.with(ref)
2022-10-11 01:57:18 +05:30
.and_call_original
post_graphql(query, current_user: user)
expect(graphql_data.dig('project', 'ciConfigVariables')).to contain_exactly(
2022-11-25 23:54:43 +05:30
{
'key' => 'KEY_VALUE_VAR',
'value' => 'value x',
'valueOptions' => nil,
'description' => 'value of KEY_VALUE_VAR'
},
2022-10-11 01:57:18 +05:30
{
'key' => 'DB_NAME',
'value' => 'postgres',
2022-11-25 23:54:43 +05:30
'valueOptions' => nil,
2022-10-11 01:57:18 +05:30
'description' => nil
},
{
'key' => 'ENVIRONMENT_VAR',
'value' => 'env var value',
2022-11-25 23:54:43 +05:30
'valueOptions' => ['env var value', 'env var value2'],
2022-10-11 01:57:18 +05:30
'description' => 'env var description'
}
)
end
end
context 'when the cache is empty' do
it 'returns nothing' do
post_graphql(query, current_user: user)
expect(graphql_data.dig('project', 'ciConfigVariables')).to be_nil
end
end
end
context 'when the user is not authorized' do
before do
project.add_guest(user)
allow(Ci::ListConfigVariablesService)
.to receive(:new)
.and_return(service)
synchronous_reactive_cache(service)
end
it 'returns nothing' do
post_graphql(query, current_user: user)
expect(graphql_data.dig('project', 'ciConfigVariables')).to be_nil
end
end
end