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

subscribe_spec.rb « work_items « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 00672332082da6408ec64ae1cbb82b36d9a49fc5 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Subscribe to a work item', feature_category: :team_planning do
  include GraphqlHelpers

  let_it_be(:project) { create(:project, :private) }
  let_it_be(:guest) { create(:user).tap { |user| project.add_guest(user) } }
  let_it_be(:work_item) { create(:work_item, project: project) }

  let(:subscribed_state) { true }
  let(:mutation_input) { { 'id' => work_item.to_global_id.to_s, 'subscribed' => subscribed_state } }
  let(:mutation) { graphql_mutation(:workItemSubscribe, mutation_input, fields) }
  let(:mutation_response) { graphql_mutation_response(:work_item_subscribe) }
  let(:fields) do
    <<~FIELDS
      workItem {
        widgets {
          type
          ... on WorkItemWidgetNotifications {
            subscribed
          }
        }
      }
      errors
    FIELDS
  end

  context 'when user is not allowed to update subscription work items' do
    let(:current_user) { create(:user) }

    it_behaves_like 'a mutation that returns a top-level access error'
  end

  context

  context 'when user has permissions to update its subscription to the work items' do
    let(:current_user) { guest }

    it "subscribe the user to the work item's notifications" do
      expect do
        post_graphql_mutation(mutation, current_user: current_user)
      end.to change { work_item.subscribed?(current_user, project) }.to(true)

      expect(response).to have_gitlab_http_status(:success)
      expect(mutation_response['workItem']['widgets']).to include({
        'type' => 'NOTIFICATIONS',
        'subscribed' => true
      })
    end

    context 'when unsunscribing' do
      let(:subscribed_state) { false }

      before do
        create(:subscription, project: project, user: current_user, subscribable: work_item, subscribed: true)
      end

      it "unsubscribe the user from the work item's notifications" do
        expect do
          post_graphql_mutation(mutation, current_user: current_user)
        end.to change { work_item.subscribed?(current_user, project) }.to(false)

        expect(response).to have_gitlab_http_status(:success)
        expect(mutation_response['workItem']['widgets']).to include({
          'type' => 'NOTIFICATIONS',
          'subscribed' => false
        })
      end
    end
  end
end