Welcome to mirror list, hosted at ThFree Co, Russian Federation.

design_at_version_resolver_spec.rb « version « design_management « resolvers « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 829227185c243747d5464b68c7aee580b17bb8d5 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Resolvers::DesignManagement::Version::DesignAtVersionResolver do
  include GraphqlHelpers

  include_context 'four designs in three versions'

  let(:current_user) { authorized_user }
  let(:gql_context) { { current_user: current_user } }

  let(:version) { third_version }
  let(:design) { design_a }

  let(:all_singular_args) do
    {
      id: global_id_of(dav(design)),
      design_id: global_id_of(design),
      filename: design.filename
    }
  end

  shared_examples 'a bad argument' do
    let(:err_class) { ::Gitlab::Graphql::Errors::ArgumentError }

    it 'generates an error' do
      expect_graphql_error_to_be_created(err_class) do
        resolve_objects
      end
    end
  end

  describe '#resolve' do
    describe 'passing combinations of arguments' do
      context 'passing no arguments' do
        let(:args) { {} }

        it_behaves_like 'a bad argument'
      end

      context 'passing all arguments' do
        let(:args) { all_singular_args }

        it_behaves_like 'a bad argument'
      end

      context 'passing any two arguments' do
        let(:args) { all_singular_args.slice(*all_singular_args.keys.sample(2)) }

        it_behaves_like 'a bad argument'
      end
    end

    %i[id design_id filename].each do |arg|
      describe "passing #{arg}" do
        let(:args) { all_singular_args.slice(arg) }

        it 'finds the design' do
          expect(resolve_objects).to eq(dav(design))
        end

        context 'when the user cannot see designs' do
          let(:current_user) { create(:user) }

          it 'returns nothing' do
            expect(resolve_objects).to be_nil
          end
        end
      end
    end

    describe 'attempting to retrieve an object not visible at this version' do
      let(:design) { design_d }

      %i[id design_id filename].each do |arg|
        describe "passing #{arg}" do
          let(:args) { all_singular_args.slice(arg) }

          it 'does not find the design' do
            expect(resolve_objects).to be_nil
          end
        end
      end
    end
  end

  def resolve_objects
    resolve(described_class, obj: version, args: args, ctx: gql_context)
  end

  def dav(design)
    build(:design_at_version, design: design, version: version)
  end
end