summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/email/message/in_product_marketing/experience_spec.rb
blob: 8cd2345822e343a41354889e0daaa417830d76f6 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Email::Message::InProductMarketing::Experience do
  let_it_be(:group) { build(:group) }
  let_it_be(:user) { build(:user) }

  subject(:message) { described_class.new(group: group, user: user, series: series)}

  describe 'public methods' do
    context 'with series 0' do
      let(:series) { 0 }

      it 'returns value for series', :aggregate_failures do
        expect(message.subject_line).to be_present
        expect(message.tagline).to be_nil
        expect(message.title).to be_present
        expect(message.subtitle).to be_present
        expect(message.body_line1).to be_present
        expect(message.body_line2).to be_present
        expect(message.cta_text).to be_nil
      end

      describe 'feedback URL' do
        before do
          allow(message).to receive(:onboarding_progress).and_return(1)
          allow(message).to receive(:show_invite_link).and_return(true)
        end

        subject do
          message.feedback_link(1)
        end

        it { is_expected.to start_with(Gitlab::Saas.com_url) }

        context 'when in development' do
          let(:root_url) { 'http://example.com' }

          before do
            allow(message).to receive(:root_url).and_return(root_url)
            stub_rails_env('development')
          end

          it { is_expected.to start_with(root_url) }
        end
      end

      describe 'feedback URL show_invite_link query param' do
        let(:user_access) { GroupMember::DEVELOPER }
        let(:preferred_language) { 'en' }

        before do
          allow(message).to receive(:onboarding_progress).and_return(1)
          allow(group).to receive(:max_member_access_for_user).and_return(user_access)
          allow(user).to receive(:preferred_language).and_return(preferred_language)
        end

        subject do
          uri = URI.parse(message.feedback_link(1))
          Rack::Utils.parse_query(uri.query).with_indifferent_access[:show_invite_link]
        end

        it { is_expected.to eq('true') }

        context 'with less than developer access' do
          let(:user_access) { GroupMember::GUEST }

          it { is_expected.to eq('false') }
        end

        context 'with preferred language other than English' do
          let(:preferred_language) { 'nl' }

          it { is_expected.to eq('false') }
        end
      end

      describe 'feedback URL show_incentive query param' do
        let(:show_invite_link) { true }
        let(:member_count) { 2 }
        let(:query) do
          uri = URI.parse(message.feedback_link(1))
          Rack::Utils.parse_query(uri.query).with_indifferent_access
        end

        before do
          allow(message).to receive(:onboarding_progress).and_return(1)
          allow(message).to receive(:show_invite_link).and_return(show_invite_link)
          allow(group).to receive(:member_count).and_return(member_count)
        end

        subject { query[:show_incentive] }

        it { is_expected.to eq('true') }

        context 'with only one member' do
          let(:member_count) { 1 }

          it "is not present" do
            expect(query).not_to have_key(:show_incentive)
          end
        end

        context 'show_invite_link is false' do
          let(:show_invite_link) { false }

          it "is not present" do
            expect(query).not_to have_key(:show_incentive)
          end
        end
      end
    end
  end
end