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

todo_type_spec.rb « types « graphql « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: af1981e804c8d2ce05b77aef0a397b0ab5c123df (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe GitlabSchema.types['Todo'] do
  let_it_be(:current_user) { create(:user) }
  let_it_be(:author) { create(:user) }

  let(:issue) { create(:issue, project: project) }

  it 'has the correct fields' do
    expected_fields = [
      :id,
      :project,
      :group,
      :author,
      :action,
      :target,
      :target_type,
      :body,
      :state,
      :created_at,
      :note
    ]

    expect(described_class).to have_graphql_fields(*expected_fields)
  end

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

  subject { GitlabSchema.execute(query, context: { current_user: current_user }).as_json }

  describe 'project field' do
    let(:todo) do
      create(
        :todo,
        user: current_user,
        project: project,
        state: :done,
        action: Todo::ASSIGNED,
        author: author,
        target: issue
      )
    end

    let(:query) do
      %(
        query {
          todo(id: "#{todo.to_global_id}") {
            project {
              id
            }
          }
        }
      )
    end

    context 'when the project is public' do
      let_it_be(:project) { create(:project, :public) }

      context 'when the user does not have access' do
        it 'returns the project' do
          expect(subject.dig('data', 'todo', 'project', 'id')).to eq(project.to_global_id.to_s)
        end
      end
    end

    context 'when the project is not public' do
      let_it_be(:project) { create(:project) }

      context 'when the user does not have access' do
        it 'returns null' do
          expect(subject.dig('data', 'todo', 'project')).to be_nil
        end
      end

      context 'when the user does have access' do
        before do
          project.add_guest(current_user)
        end

        it 'returns the project' do
          expect(subject.dig('data', 'todo', 'project', 'id')).to eq(project.to_global_id.to_s)
        end
      end
    end
  end

  describe 'group field' do
    let(:todo) do
      create(
        :todo,
        user: current_user,
        group: group,
        state: :done,
        action: Todo::MENTIONED,
        author: author,
        target: issue
      )
    end

    let(:query) do
      %(
        query {
          todo(id: "#{todo.to_global_id}") {
            group {
              id
            }
          }
        }
      )
    end

    context 'when the group is public' do
      let_it_be(:group) { create(:group, :public) }
      let_it_be(:project) { create(:project, :public, group: group) }

      context 'when the user does not have access' do
        it 'returns the group' do
          expect(subject.dig('data', 'todo', 'group', 'id')).to eq(group.to_global_id.to_s)
        end
      end
    end

    context 'when the group is not public' do
      let_it_be(:group) { create(:group) }
      let_it_be(:project) { create(:project, group: group) }

      context 'when the user does not have access' do
        it 'returns null' do
          expect(subject.dig('data', 'todo', 'group')).to be_nil
        end
      end

      context 'when the user does have access' do
        before do
          group.add_guest(current_user)
        end

        it 'returns the group' do
          expect(subject.dig('data', 'todo', 'group', 'id')).to eq(group.to_global_id.to_s)
        end
      end
    end
  end
end