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

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

require "spec_helper"
require_migration!

RSpec.describe BackfillProductAnalyticsDataCollectorHost, feature_category: :product_analytics_data_management do
  let!(:application_settings) { table(:application_settings) }

  describe '#up' do
    before do
      create_application_settings!(id: 1, jitsu_host: "https://configurator.testing.my-product-analytics.com",
        product_analytics_data_collector_host: nil)
      create_application_settings!(id: 2, jitsu_host: "https://config-urator_1.testing.my-product-analytics.com",
        product_analytics_data_collector_host: nil)
      create_application_settings!(id: 3, jitsu_host: "https://configurator.testing.my-product-analytics.com",
        product_analytics_data_collector_host: "https://existingcollector.my-product-analytics.com")
      create_application_settings!(id: 4, jitsu_host: nil, product_analytics_data_collector_host: nil)
      migrate!
    end

    describe 'when jitsu host is present' do
      it 'backfills missing product_analytics_data_collector_host' do
        expect(application_settings.find(1).product_analytics_data_collector_host).to eq("https://collector.testing.my-product-analytics.com")
        expect(application_settings.find(2).product_analytics_data_collector_host).to eq("https://collector.testing.my-product-analytics.com")
      end

      it 'does not modify existing product_analytics_data_collector_host' do
        expect(application_settings.find(3).product_analytics_data_collector_host).to eq("https://existingcollector.my-product-analytics.com")
      end
    end

    describe 'when jitsu host is not present' do
      it 'does not backfill product_analytics_data_collector_host' do
        expect(application_settings.find(4).product_analytics_data_collector_host).to be_nil
      end
    end
  end

  def create_application_settings!(id:, jitsu_host:, product_analytics_data_collector_host:)
    params = {
      id: id,
      jitsu_host: jitsu_host,
      product_analytics_data_collector_host: product_analytics_data_collector_host
    }
    application_settings.create!(params)
  end
end