summaryrefslogtreecommitdiff
path: root/spec/requests/api/graphql/project/packages_spec.rb
blob: 3c04e0caf613335456811688c7ebbf32eee4febc (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'getting a package list for a project' do
  include GraphqlHelpers

  let_it_be(:resource) { create(:project, :repository) }
  let_it_be(:current_user) { create(:user) }

  let_it_be(:package) { create(:package, project: resource) }
  let_it_be(:maven_package) { create(:maven_package, project: resource) }
  let_it_be(:debian_package) { create(:debian_package, project: resource) }
  let_it_be(:composer_package) { create(:composer_package, project: resource) }
  let_it_be(:composer_metadatum) do
    create(:composer_metadatum, package: composer_package,
           target_sha: 'afdeh',
           composer_json: { name: 'x', type: 'y', license: 'z', version: 1 })
  end

  let(:package_names) { graphql_data_at(:project, :packages, :nodes, :name) }
  let(:target_shas) { graphql_data_at(:project, :packages, :nodes, :metadata, :target_sha) }
  let(:packages) { graphql_data_at(:project, :packages, :nodes) }

  let(:fields) do
    <<~QUERY
    nodes {
      #{all_graphql_fields_for('packages'.classify, excluded: ['project'])}
      metadata { #{query_graphql_fragment('ComposerMetadata')} }
    }
    QUERY
  end

  let(:query) do
    graphql_query_for(
      'project',
      { 'fullPath' => resource.full_path },
      query_graphql_field('packages', {}, fields)
    )
  end

  it_behaves_like 'group and project packages query'
end