diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /spec/graphql/types/terraform/state_version_type_spec.rb | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'spec/graphql/types/terraform/state_version_type_spec.rb')
-rw-r--r-- | spec/graphql/types/terraform/state_version_type_spec.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/graphql/types/terraform/state_version_type_spec.rb b/spec/graphql/types/terraform/state_version_type_spec.rb index 18f869e4f1f..b015a2045da 100644 --- a/spec/graphql/types/terraform/state_version_type_spec.rb +++ b/spec/graphql/types/terraform/state_version_type_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['TerraformStateVersion'] do + include GraphqlHelpers + it { expect(described_class.graphql_name).to eq('TerraformStateVersion') } it { expect(described_class).to require_graphql_authorizations(:read_terraform_state) } @@ -19,4 +21,60 @@ RSpec.describe GitlabSchema.types['TerraformStateVersion'] do it { expect(described_class.fields['createdAt'].type).to be_non_null } it { expect(described_class.fields['updatedAt'].type).to be_non_null } end + + describe 'query' do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + let_it_be(:terraform_state) { create(:terraform_state, :with_version, :locked, project: project) } + + before do + project.add_developer(user) + end + + let(:query) do + <<~GRAPHQL + query { + project(fullPath: "#{project.full_path}") { + terraformState(name: "#{terraform_state.name}") { + latestVersion { + id + job { + name + } + } + } + } + } + GRAPHQL + end + + subject(:execute) { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + shared_examples 'returning latest version' do + it 'returns latest version of terraform state' do + expect(execute.dig('data', 'project', 'terraformState', 'latestVersion', 'id')).to eq( + global_id_of(terraform_state.latest_version) + ) + end + end + + it_behaves_like 'returning latest version' + + it 'returns job of the latest version' do + expect(execute.dig('data', 'project', 'terraformState', 'latestVersion', 'job')).to be_present + end + + context 'when user cannot read jobs' do + before do + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?).with(user, :read_commit_status, terraform_state.latest_version).and_return(false) + end + + it_behaves_like 'returning latest version' + + it 'does not return job of the latest version' do + expect(execute.dig('data', 'project', 'terraformState', 'latestVersion', 'job')).not_to be_present + end + end + end end |