summaryrefslogtreecommitdiff
path: root/spec/migrations/unconfirm_wrongfully_verified_emails_spec.rb
blob: 5adc866d0a5d5fe21a7a0122279e7ad9b4a703c6 (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'
require_migration!

RSpec.describe UnconfirmWrongfullyVerifiedEmails do
  before do
    user = table(:users).create!(name: 'user1', email: 'test1@test.com', projects_limit: 1)
    table(:emails).create!(email: 'test2@test.com', user_id: user.id)
  end

  context 'when email confirmation is enabled' do
    before do
      table(:application_settings).create!(send_user_confirmation_email: true)
    end

    it 'enqueues WrongullyConfirmedEmailUnconfirmer job' do
      Sidekiq::Testing.fake! do
        migrate!

        jobs = BackgroundMigrationWorker.jobs
        expect(jobs.size).to eq(1)
        expect(jobs.first["args"].first).to eq(Gitlab::BackgroundMigration::WrongfullyConfirmedEmailUnconfirmer.name.demodulize)
      end
    end
  end

  context 'when email confirmation is disabled' do
    before do
      table(:application_settings).create!(send_user_confirmation_email: false)
    end

    it 'does not enqueue WrongullyConfirmedEmailUnconfirmer job' do
      Sidekiq::Testing.fake! do
        migrate!

        expect(BackgroundMigrationWorker.jobs.size).to eq(0)
      end
    end
  end

  context 'when email application setting record does not exist' do
    before do
      table(:application_settings).delete_all
    end

    it 'does not enqueue WrongullyConfirmedEmailUnconfirmer job' do
      Sidekiq::Testing.fake! do
        migrate!

        expect(BackgroundMigrationWorker.jobs.size).to eq(0)
      end
    end
  end
end