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

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

require 'spec_helper'

RSpec.describe 'getting CRM contacts' do
  include GraphqlHelpers

  let_it_be(:current_user) { create(:user) }
  let_it_be(:group) { create(:group, :crm_enabled) }

  let_it_be(:contact_a) do
    create(
      :contact,
      group: group,
      first_name: "PQR",
      last_name: "STU",
      email: "aaa@test.com",
      description: "YZ",
      state: "active"
    )
  end

  let_it_be(:contact_b) do
    create(
      :contact,
      group: group,
      first_name: "ABC",
      last_name: "DEF",
      email: "ghi@test.com",
      description: "LMNO",
      state: "inactive"
    )
  end

  let_it_be(:contact_c) do
    create(
      :contact,
      group: group,
      first_name: "JKL",
      last_name: "MNO",
      email: "vwx@test.com",
      description: "YZ",
      state: "active"
    )
  end

  before do
    group.add_reporter(current_user)
  end

  it_behaves_like 'sorted paginated query' do
    let(:sort_argument) { {} }
    let(:first_param) { 2 }
    let(:all_records) { [contact_b, contact_c, contact_a] }
    let(:data_path) { [:group, :contacts] }

    def pagination_query(params)
      graphql_query_for(
        :group,
        { full_path: group.full_path },
        query_graphql_field(:contacts, params, "#{page_info} nodes { id }")
      )
    end

    def pagination_results_data(nodes)
      nodes.map { |item| GlobalID::Locator.locate(item['id']) }
    end
  end
end