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

in_product_marketing_email_records_spec.rb « users « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d214560b2a6931dae8c0b95fd4d7b0860dfc86b5 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Users::InProductMarketingEmailRecords, feature_category: :onboarding do
  let_it_be(:user) { create :user }

  subject(:records) { described_class.new }

  it 'initializes records' do
    expect(subject.records).to match_array []
  end

  describe '#save!' do
    before do
      allow(Users::InProductMarketingEmail).to receive(:bulk_insert!)

      records.add(user, track: :team_short, series: 0)
      records.add(user, track: :create, series: 1)
    end

    it 'bulk inserts added records' do
      expect(Users::InProductMarketingEmail).to receive(:bulk_insert!).with(records.records)
      records.save!
    end

    it 'resets its records' do
      records.save!
      expect(records.records).to match_array []
    end
  end

  describe '#add' do
    it 'adds a Users::InProductMarketingEmail record to its records', :aggregate_failures do
      freeze_time do
        records.add(user, track: :team_short, series: 0)
        records.add(user, track: :create, series: 1)

        first, second = records.records

        expect(first).to be_a Users::InProductMarketingEmail
        expect(first.track.to_sym).to eq :team_short
        expect(first.series).to eq 0
        expect(first.created_at).to eq Time.zone.now
        expect(first.updated_at).to eq Time.zone.now

        expect(second).to be_a Users::InProductMarketingEmail
        expect(second.track.to_sym).to eq :create
        expect(second.series).to eq 1
        expect(second.created_at).to eq Time.zone.now
        expect(second.updated_at).to eq Time.zone.now
      end
    end
  end
end