summaryrefslogtreecommitdiff
path: root/spec/services/pages_domains/retry_acme_order_service_spec.rb
blob: 3152e05f2f12b50ccb99f89cde6699383e6c6540 (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 PagesDomains::RetryAcmeOrderService, feature_category: :pages do
  let_it_be(:project) { create(:project) }

  let(:domain) { create(:pages_domain, project: project, auto_ssl_enabled: true, auto_ssl_failed: true) }

  let(:service) { described_class.new(domain) }

  it 'clears auto_ssl_failed' do
    expect { service.execute }
      .to change { domain.auto_ssl_failed }
      .from(true).to(false)
      .and publish_event(PagesDomains::PagesDomainUpdatedEvent)
      .with(
        project_id: project.id,
        namespace_id: project.namespace.id,
        root_namespace_id: project.root_namespace.id,
        domain: domain.domain
      )
  end

  it 'schedules renewal worker and publish PagesDomainUpdatedEvent event' do
    expect(PagesDomainSslRenewalWorker).to receive(:perform_async).with(domain.id).and_return(nil).once

    expect { service.execute }
      .to publish_event(PagesDomains::PagesDomainUpdatedEvent)
      .with(
        project_id: project.id,
        namespace_id: project.namespace.id,
        root_namespace_id: project.root_namespace.id,
        domain: domain.domain
      )
  end

  it "doesn't schedule renewal worker if Let's Encrypt integration is not enabled" do
    domain.update!(auto_ssl_enabled: false)

    expect(PagesDomainSslRenewalWorker).not_to receive(:new)

    expect { service.execute }
      .to not_publish_event(PagesDomains::PagesDomainUpdatedEvent)
  end

  it "doesn't schedule renewal worker if auto ssl has not failed yet" do
    domain.update!(auto_ssl_failed: false)

    expect(PagesDomainSslRenewalWorker).not_to receive(:new)

    expect { service.execute }
      .to not_publish_event(PagesDomains::PagesDomainUpdatedEvent)
  end
end