summaryrefslogtreecommitdiff
path: root/spec/graphql/mutations/design_management/move_spec.rb
blob: d17483e69b33affb46be2d0445392b443dabb5f0 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Mutations::DesignManagement::Move do
  include DesignManagementTestHelpers

  let_it_be(:issue) { create(:issue) }
  let_it_be(:designs) { create_list(:design, 3, issue: issue) }
  let_it_be(:developer) { create(:user, developer_projects: [issue.project]) }

  let(:user) { developer }

  let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }

  let(:current_design) { designs.first }
  let(:previous_design) { designs.second }
  let(:next_design) { designs.third }

  before do
    enable_design_management
  end

  describe "#resolve" do
    subject(:resolve) do
      args = {
        current_design: current_design.to_global_id,
        previous_design: previous_design&.to_global_id,
        next_design: next_design&.to_global_id
      }.compact

      mutation.resolve(**args)
    end

    shared_examples "resource not available" do
      it "raises an error" do
        expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
      end
    end

    context 'when the feature is not available' do
      before do
        enable_design_management(false)
      end

      it_behaves_like 'resource not available'
    end

    %i[current_design previous_design next_design].each do |binding|
      context "When #{binding} cannot be found" do
        let(binding) { build_stubbed(:design) }

        it_behaves_like 'resource not available'
      end
    end

    context 'the service runs' do
      before do
        expect_next_instance_of(::DesignManagement::MoveDesignsService) do |service|
          expect(service).to receive(:execute).and_return(service_result)
        end
      end

      context 'raising an error' do
        let(:service_result) { ServiceResponse.error(message: 'bang!') }

        it 'reports the service-level error' do
          expect(resolve).to include(errors: ['bang!'], design_collection: eq(issue.design_collection))
        end
      end

      context 'successfully' do
        let(:service_result) { ServiceResponse.success }

        it 'reports the service-level error' do
          expect(resolve).to include(errors: be_empty, design_collection: eq(issue.design_collection))
        end
      end
    end
  end
end