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

abuse_report_details_entity_spec.rb « admin « serializers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bed9775ac8cde8b1213fa4b2dd0cbe1a8b65c689 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Admin::AbuseReportDetailsEntity, feature_category: :insider_threat do
  include Gitlab::Routing

  let_it_be(:report) { build_stubbed(:abuse_report) }
  let_it_be(:user) { report.user }
  let_it_be(:reporter) { report.reporter }
  let_it_be(:past_report) { create_default(:abuse_report, :closed, user: user) }
  let_it_be(:similar_open_report) { create_default(:abuse_report, user: user, category: report.category) }

  let(:entity) do
    described_class.new(report)
  end

  describe '#as_json' do
    subject(:entity_hash) { entity.as_json }

    it 'exposes correct attributes' do
      expect(entity_hash.keys).to match_array([
        :user,
        :report
      ])
    end

    it 'correctly exposes `user`', :aggregate_failures do
      user_hash = entity_hash[:user]

      expect(user_hash.keys).to match_array([
        :name,
        :username,
        :avatar_url,
        :email,
        :created_at,
        :last_activity_on,
        :path,
        :admin_path,
        :plan,
        :verification_state,
        :past_closed_reports,
        :similar_open_reports,
        :most_used_ip,
        :last_sign_in_ip,
        :snippets_count,
        :groups_count,
        :notes_count
      ])

      expect(user_hash[:verification_state].keys).to match_array([
        :email,
        :phone,
        :credit_card
      ])

      expect(user_hash[:past_closed_reports][0].keys).to match_array([
        :created_at,
        :category,
        :report_path
      ])

      similar_open_report_hash = user_hash[:similar_open_reports][0]
      expect(similar_open_report_hash.keys).to match_array([
        :id,
        :global_id,
        :status,
        :message,
        :reported_at,
        :category,
        :type,
        :content,
        :url,
        :screenshot,
        :update_path,
        :moderate_user_path,
        :reporter
      ])

      similar_reporter_hash = similar_open_report_hash[:reporter]
      expect(similar_reporter_hash.keys).to match_array([
        :name,
        :username,
        :avatar_url,
        :path
      ])
    end

    context 'when report is closed' do
      let(:report) { build_stubbed(:abuse_report, :closed) }

      it 'does not expose `user.similar_open_reports`' do
        user_hash = entity_hash[:user]

        expect(user_hash).not_to include(:similar_open_reports)
      end
    end

    it 'correctly exposes `report`', :aggregate_failures do
      report_hash = entity_hash[:report]

      expect(report_hash.keys).to match_array([
        :id,
        :global_id,
        :status,
        :message,
        :reported_at,
        :category,
        :type,
        :content,
        :url,
        :screenshot,
        :update_path,
        :moderate_user_path,
        :reporter
      ])
    end

    it 'correctly exposes `reporter`' do
      reporter_hash = entity_hash[:report][:reporter]

      expect(reporter_hash.keys).to match_array([
        :name,
        :username,
        :avatar_url,
        :path
      ])
    end

    describe 'users plan' do
      it 'does not include the plan' do
        expect(entity_hash[:user][:plan]).to be_nil
      end

      context 'when on .com', :saas, if: Gitlab.ee? do
        before do
          stub_ee_application_setting(should_check_namespace_plan: true)
          create(:namespace_with_plan, plan: :bronze_plan, owner: user)  # rubocop:disable RSpec/FactoryBot/AvoidCreate
        end

        it 'includes the plan' do
          expect(entity_hash[:user][:plan]).to eq('Bronze')
        end
      end
    end

    describe 'users credit card' do
      let(:credit_card_hash) { entity_hash[:user][:credit_card] }

      context 'when the user has no verified credit card' do
        it 'does not expose the credit card' do
          expect(credit_card_hash).to be_nil
        end
      end

      context 'when the user does have a verified credit card' do
        let!(:credit_card) { build_stubbed(:credit_card_validation, user: user) }

        it 'exposes the credit card' do
          expect(credit_card_hash.keys).to match_array([
            :name,
            :similar_records_count,
            :card_matches_link
          ])
        end

        context 'when not on ee', unless: Gitlab.ee? do
          it 'does not include the path to the admin card matches page' do
            expect(credit_card_hash[:card_matches_link]).to be_nil
          end
        end

        context 'when on ee', if: Gitlab.ee? do
          it 'includes the path to the admin card matches page' do
            expect(credit_card_hash[:card_matches_link]).not_to be_nil
          end
        end
      end
    end
  end
end