Skip to content

Commit

Permalink
Refactor renew certificate job spec
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Nov 8, 2023
1 parent 90d166c commit 4731d98
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions spec/jobs/lets_encrypt/renew_certificates_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
# frozen_string_literal: true

RSpec.describe LetsEncrypt::RenewCertificatesJob, type: :job do
before(:all) { ActiveJob::Base.queue_adapter = :test }
let(:certificate) { LetsEncrypt::Certificate.new }

it 'enqueue job' do
expect { LetsEncrypt::RenewCertificatesJob.perform_later }
.to have_enqueued_job(LetsEncrypt::RenewCertificatesJob)
end
before do
ActiveJob::Base.queue_adapter = :test

describe 'starting rnew' do
before(:each) do
expect(LetsEncrypt::Certificate).to receive(:renewable).and_return(certificates)
end
allow(LetsEncrypt::Certificate).to receive(:renewable).and_return([certificate])
end

let(:certificates) { [LetsEncrypt::Certificate.new] }
describe 'when renew success' do
before do
allow(certificate).to receive(:renew).and_return(true)

it 'do nothing when success' do
expect_any_instance_of(LetsEncrypt::Certificate).to receive(:renew).and_return(true)
LetsEncrypt::RenewCertificatesJob.perform_now
end

it 'schedule next renew to 1 days from now' do
allow_any_instance_of(LetsEncrypt::Certificate).to receive(:renew).and_return(false)
expect_any_instance_of(LetsEncrypt::Certificate)
.to receive(:update).with(renew_after: an_instance_of(ActiveSupport::TimeWithZone))
it { expect(certificate).to have_received(:renew) }
end

describe 'renew failed' do
before do
allow(certificate).to receive(:renew).and_return(false)
allow(certificate).to receive(:update).with(renew_after: an_instance_of(ActiveSupport::TimeWithZone))

LetsEncrypt::RenewCertificatesJob.perform_now
end
it 'schedule next renew to 1 days from now' do
expect(certificate).to have_received(:update).with(renew_after: an_instance_of(ActiveSupport::TimeWithZone))
end
end
end

0 comments on commit 4731d98

Please sign in to comment.