summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/graphql/mutations/resolves_subscription_shared_examples.rb
blob: 678bb908343f9af062f6be5d8b45ebe1e2a0c781 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.shared_examples 'a subscribeable not accessible graphql resource' do
  let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }

  subject { mutation.resolve(project_path: resource.project.full_path, iid: resource.iid, subscribed_state: true) }

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

RSpec.shared_examples 'a subscribeable graphql resource' do
  let(:mutated_resource) { subject[resource.class.name.underscore.to_sym] }
  let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
  let(:subscribe) { true }

  subject { mutation.resolve(project_path: resource.project.full_path, iid: resource.iid, subscribed_state: subscribe) }

  it 'subscribes to the resource' do
    expect(mutated_resource).to eq(resource)
    expect(mutated_resource.subscribed?(user, project)).to eq(true)
    expect(subject[:errors]).to be_empty
  end

  context 'when passing subscribe as false' do
    let(:subscribe) { false }

    it 'unsubscribes from the discussion' do
      resource.subscribe(user, project)

      expect(mutated_resource.subscribed?(user, project)).to eq(false)
      expect(subject[:errors]).to be_empty
    end
  end
end