summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/requests/api/graphql/packages/group_and_project_packages_list_shared_examples.rb
blob: 66fbfa798b0491250ed306325c174dbaa1a7b001 (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
44
45
46
47
48
49
50
51
# frozen_string_literal: true

RSpec.shared_examples 'group and project packages query' do
  include GraphqlHelpers

  context 'when user has access to the resource' do
    before do
      resource.add_reporter(current_user)
      post_graphql(query, current_user: current_user)
    end

    it_behaves_like 'a working graphql query'

    it 'returns packages successfully' do
      expect(package_names).to contain_exactly(
        package.name,
        maven_package.name,
        debian_package.name,
        composer_package.name
      )
    end

    it 'deals with metadata' do
      expect(target_shas).to contain_exactly(composer_metadatum.target_sha)
    end
  end

  context 'when the user does not have access to the resource' do
    before do
      post_graphql(query, current_user: current_user)
    end

    it_behaves_like 'a working graphql query'

    it 'returns nil' do
      expect(packages).to be_nil
    end
  end

  context 'when the user is not authenticated' do
    before do
      post_graphql(query)
    end

    it_behaves_like 'a working graphql query'

    it 'returns nil' do
      expect(packages).to be_nil
    end
  end
end