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

issuable_updated_spec.rb « subscriptions « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bc640e9e3c447851524c5f3eacb0ea69d12cb116 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Subscriptions::IssuableUpdated do
  include GraphqlHelpers

  it { expect(described_class).to have_graphql_arguments(:issuable_id) }
  it { expect(described_class.payload_type).to eq(Types::IssuableType) }

  describe '#resolve' do
    let_it_be(:unauthorized_user) { create(:user) }
    let_it_be(:issue) { create(:issue) }

    let(:current_user) { issue.author }
    let(:issuable_id) { issue.to_gid }

    subject { resolver.resolve_with_support(issuable_id: issuable_id) }

    context 'initial subscription' do
      let(:resolver) { resolver_instance(described_class, ctx: { current_user: current_user }, subscription_update: false) }

      it 'returns nil' do
        expect(subject).to eq(nil)
      end

      context 'when user is unauthorized' do
        let(:current_user) { unauthorized_user }

        it 'raises an exception' do
          expect { subject }.to raise_error(GraphQL::ExecutionError)
        end
      end

      context 'when issue does not exist' do
        let(:issuable_id) { GlobalID.parse("gid://gitlab/Issue/#{non_existing_record_id}") }

        it 'raises an exception' do
          expect { subject }.to raise_error(GraphQL::ExecutionError)
        end
      end
    end

    context 'subscription updates' do
      let(:resolver) { resolver_instance(described_class, obj: issue, ctx: { current_user: current_user }, subscription_update: true) }

      it 'returns the resolved object' do
        expect(subject).to eq(issue)
      end

      context 'when user is unauthorized' do
        let(:current_user) { unauthorized_user }

        it 'unsubscribes the user' do
          # GraphQL::Execution::Execute::Skip is returned when unsubscribed
          expect(subject).to be_an(GraphQL::Execution::Execute::Skip)
        end
      end
    end
  end
end