summaryrefslogtreecommitdiff
path: root/spec/lib/product_analytics/event_params_spec.rb
blob: d6c098599d6e346734ea43cae5df15aa44896a80 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ProductAnalytics::EventParams do
  describe '.parse_event_params' do
    subject { described_class.parse_event_params(raw_event) }

    let(:raw_event) { Gitlab::Json.parse(fixture_file('product_analytics/event.json')) }

    it 'extracts all params from raw event' do
      expected_params = {
        project_id: '1',
        platform: 'web',
        name_tracker: 'sp',
        v_tracker: 'js-2.14.0',
        event_id: 'fbf14096-74ee-47e4-883c-8a0d6cb72e37',
        domain_userid: '79543c31-cfc3-4479-a737-fafb9333c8ba',
        domain_sessionid: '54f6d3f3-f4f9-4fdc-87e0-a2c775234c1b',
        domain_sessionidx: 4,
        page_url: 'http://example.com/products/1',
        page_referrer: 'http://example.com/products/1',
        br_lang: 'en-US',
        br_cookies: true,
        os_timezone: 'America/Los_Angeles',
        doc_charset: 'UTF-8'
      }

      expect(subject).to include(expected_params)
    end
  end

  describe '.has_required_params?' do
    subject { described_class.has_required_params?(params) }

    context 'aid and eid are present' do
      let(:params) { { 'aid' => 1, 'eid' => 2 } }

      it { expect(subject).to be_truthy }
    end

    context 'aid and eid are missing' do
      let(:params) { {} }

      it { expect(subject).to be_falsey }
    end

    context 'eid is missing' do
      let(:params) { { 'aid' => 1 } }

      it { expect(subject).to be_falsey }
    end
  end
end