diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 09:10:14 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 09:10:14 +0000 |
commit | 919f0e86ba5997120d02601e648543d1682e8260 (patch) | |
tree | a19cd58b0d82a56f46e6c02535253461149b1c6b /spec/graphql/types/project_type_spec.rb | |
parent | 866b1f8ed7db9b29b1188ffcba309b92572f354b (diff) | |
download | gitlab-ce-919f0e86ba5997120d02601e648543d1682e8260.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql/types/project_type_spec.rb')
-rw-r--r-- | spec/graphql/types/project_type_spec.rb | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index b435f3ed5ff..9ae9536fcc4 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -36,7 +36,7 @@ RSpec.describe GitlabSchema.types['Project'] do cluster_agent cluster_agents agent_configurations ci_template timelogs merge_commit_template squash_commit_template work_item_types recent_issue_boards ci_config_path_or_default packages_cleanup_policy ci_variables - timelog_categories fork_targets branch_rules ci_config_variables pipeline_schedules + timelog_categories fork_targets branch_rules ci_config_variables pipeline_schedules languages ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -731,4 +731,60 @@ RSpec.describe GitlabSchema.types['Project'] do end end end + + describe 'languages' do + let_it_be(:user) { create(:user) } + let_it_be(:project) do + create(:project, + :private, + :repository, + creator_id: user.id, + namespace: user.namespace) + end + + let(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + languages { + name + share + color + } + } + } + ) + end + + let(:mock_languages) { [] } + + before do + allow_next_instance_of(::Projects::RepositoryLanguagesService) do |service| + allow(service).to receive(:execute).and_return(mock_languages) + end + end + + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + let(:languages) { subject.dig('data', 'project', 'languages') } + + context "when the languages haven't been detected yet" do + it 'returns an empty array' do + expect(languages).to eq([]) + end + end + + context 'when the languages were detected before' do + let(:mock_languages) do + [{ share: 66.69, name: "Ruby", color: "#701516" }, + { share: 22.98, name: "JavaScript", color: "#f1e05a" }, + { share: 7.91, name: "HTML", color: "#e34c26" }, + { share: 2.42, name: "CoffeeScript", color: "#244776" }] + end + + it 'returns the repository languages' do + expect(languages).to eq(mock_languages.map(&:stringify_keys)) + end + end + end end |