summaryrefslogtreecommitdiff
path: root/spec/graphql/mutations/issues/set_due_date_spec.rb
blob: a638971d9661114d5ab4f99ca15e785ae949a27c (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 Mutations::Issues::SetDueDate do
  let(:issue) { create(:issue) }
  let(:user) { create(:user) }

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

  specify { expect(described_class).to require_graphql_authorizations(:update_issue) }

  describe '#resolve' do
    let(:due_date) { 2.days.since }
    let(:mutated_issue) { subject[:issue] }

    subject { mutation.resolve(project_path: issue.project.full_path, iid: issue.iid, due_date: due_date) }

    it 'raises an error if the resource is not accessible to the user' do
      expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
    end

    context 'when the user can update the issue' do
      before do
        issue.project.add_developer(user)
      end

      it 'returns the issue with updated due date' do
        expect(mutated_issue).to eq(issue)
        expect(mutated_issue.due_date).to eq(Date.today + 2.days)
        expect(subject[:errors]).to be_empty
      end

      context 'when passing incorrect due date value' do
        let(:due_date) { 'test' }

        it 'does not update due date' do
          expect(mutated_issue.due_date).to eq(issue.due_date)
        end
      end
    end
  end
end