Skip to content

Commit

Permalink
improve tests and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LucienMLD committed Nov 28, 2023
1 parent 93612d0 commit 5027346
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 66 deletions.
1 change: 0 additions & 1 deletion app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
extend JobExtensions::RemoveDelayedJobs
end
2 changes: 1 addition & 1 deletion app/jobs/company/not_yet_taken_care_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Company::NotYetTakenCareJob < ApplicationJob

def perform
retrieve_solicitations.each do |solicitation|
CompanyMailer.not_yet_taken_care(solicitation).deliver_later(queue: 'low_priority')
CompanyMailer.not_yet_taken_care(solicitation).deliver_later
end
end

Expand Down
32 changes: 0 additions & 32 deletions app/jobs/job_extensions/remove_delayed_jobs.rb

This file was deleted.

16 changes: 3 additions & 13 deletions app/services/antenne_coverage/deduplicated_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,12 @@ def update_antenne_coverage(antenne)
end

def delete_jobs_already_in_queue(antenne)
scheduled = if Rails.env == 'test'
Sidekiq::Job.jobs
else
Sidekiq::ScheduledSet.new
end
scheduled = Sidekiq::ScheduledSet.new

scheduled.each do |job|
return if job['queue'] != QUEUE_NAME
if Rails.env == 'test'
# Seule methode que j'ai trouvé pour vider Sidekiq::Job.jobs qui est accessible dans les tests,
# Sidekiq::ScheduledSet ne l'est pas
Sidekiq::Job.clear_all
else
if job['class'] == UpdateAntenneCoverageJob.to_s && job['args'].first == antenne.id
job.delete
end
if job['class'] == UpdateAntenneCoverageJob.to_s && job['args'].first == antenne.id
job.delete
end
end
end
Expand Down
1 change: 0 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Application < Rails::Application
config.action_mailer.default_url_options = { host: ENV['HOST_NAME'] }

config.active_job.queue_adapter = :sidekiq
config.action_mailer.deliver_later_queue_name = 'default'

config.middleware.insert_after ActionDispatch::RemoteIp, IpAnonymizer::MaskIp
config.action_view.form_with_generates_remote_forms = true
Expand Down
1 change: 0 additions & 1 deletion config/cable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ development:

test:
adapter: test
url: redis://localhost:6379/1

production:
adapter: redis
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/reminders/needs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

it 'send email and set abandoned_email_sent' do
assert_enqueued_with(job: ActionMailer::MailDeliveryJob)
expect(enqueued_jobs.count).to eq 1
expect(need.reload.is_abandoned?).to be false
end
end
Expand Down Expand Up @@ -53,7 +54,7 @@

it 'send email only for quo match and add a feedback' do
assert_enqueued_with(job: ActionMailer::MailDeliveryJob)
assert_enqueued_with(job: ActionMailer::MailDeliveryJob)
expect(enqueued_jobs.count).to eq 1
expect(Feedback.where(feedbackable_id: match1.need.id).count).to eq 1
end
end
Expand Down
5 changes: 4 additions & 1 deletion spec/jobs/company/not_yet_taken_care_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
describe 'perform_now' do
before { described_class.perform_now }

it { assert_enqueued_with(job: ActionMailer::MailDeliveryJob) }
it do
assert_enqueued_with(job: ActionMailer::MailDeliveryJob)
expect(enqueued_jobs.count).to eq 1
end
end

describe 'enqueue a job' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
expect(need_without_help.reload.retention_sent_at).to be_nil
expect(need_all_wrong.reload.retention_sent_at).to be_nil
assert_enqueued_with(job: ActionMailer::MailDeliveryJob)
expect(enqueued_jobs.count).to eq 2
end
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/jobs/company/solicitations_relaunch_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
it 'send emails to solicitations not completed' do
described_class.perform_now
assert_enqueued_with(job: ActionMailer::MailDeliveryJob, args: ["CompanyMailer", "solicitation_relaunch_company", "deliver_now", { args: [solicitation] }])

end
end
end
2 changes: 1 addition & 1 deletion spec/jobs/send_status_notification_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

context "others status" do
# Les combinaisons de `should_notify_everyone` notifient tout le monde
# Les combinaisons de `should_notify_everyone` qui notifient tout le monde
%w[taking_care done].each do |new_status|
%w[quo not_for_me].each do |previous_status|
it 'notifies everyone' do
Expand Down
18 changes: 11 additions & 7 deletions spec/services/antenne_coverage/deduplicated_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require 'rails_helper'
describe AntenneCoverage::DeduplicatedJob do
Sidekiq::Testing.disable!
before { Sidekiq::ScheduledSet.new.clear }

describe '#call' do
let(:institution) { create(:institution) }
Expand All @@ -10,17 +12,19 @@
let!(:antenne) { create(:antenne, :local, institution: institution, communes: communes) }

it do
expect(Sidekiq::Job.jobs.count).to eq 0
scheduled = Sidekiq::ScheduledSet.new

expect(scheduled.size).to eq 0
antenne.update(communes: [])
expect(Sidekiq::Job.jobs.count).to eq 1
expect(Sidekiq::Job.jobs.last['args']).to eq [antenne.id]
first_job = Sidekiq::Job.jobs.first
expect(scheduled.size).to eq 1
expect(scheduled.first.args).to eq [antenne.id]
first_job = scheduled.first

# Pas de nouveau job rajouté si on modifie la même antenne
antenne.update(communes: [beaufay])
expect(Sidekiq::Job.jobs.count).to eq 1
expect(Sidekiq::Job.jobs.last['args']).to eq [antenne.id]
second_job = Sidekiq::Job.jobs.first
expect(scheduled.size).to eq 1
expect(scheduled.first.args).to eq [antenne.id]
second_job = scheduled.first
expect(first_job['args']).to eq second_job['args']
expect(first_job['class']).to eq second_job['class']
expect(first_job['queue']).to eq second_job['queue']
Expand Down
1 change: 1 addition & 0 deletions spec/services/cancel_solicitation_with_email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
expect(solicitation.badges.first.title).to eq I18n.t(email_type, scope: 'solicitations.solicitation_actions.emails')
expect(solicitation.status).to eq 'canceled'
assert_enqueued_with(job: ActionMailer::MailDeliveryJob)
expect(enqueued_jobs.count).to eq 1
end
end

Expand Down
11 changes: 5 additions & 6 deletions spec/services/match_mailer_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

require 'rails_helper'
describe MatchMailerService do
before do
ENV['APPLICATION_EMAIL'] = '[email protected]'
Sidekiq::ScheduledSet.new.clear
end

Sidekiq::Testing.disable!

before do
ENV['APPLICATION_EMAIL'] = '[email protected]'
Sidekiq::ScheduledSet.new.clear
end

describe '#deduplicated_notify_status' do
def notify_change(new_status)
previous_status = a_match.status
Expand Down Expand Up @@ -44,7 +44,6 @@ def notify_change(new_status)
expect(scheduled.size).to eq 0
expect(a_match.status).to eq 'quo'
end

end

context 'match taking_care and match not reachable' do
Expand Down
2 changes: 2 additions & 0 deletions spec/services/needs_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
expect(need5.reload.is_abandoned?).to be false
expect(need6.reload.is_abandoned?).to be false
assert_enqueued_with(job: ActionMailer::MailDeliveryJob)
expect(enqueued_jobs.count).to eq 1
end
end

Expand Down Expand Up @@ -86,6 +87,7 @@
expect(need2.reload.is_abandoned?).to be true
expect(need3.reload.is_abandoned?).to be false
expect(need4.reload.is_abandoned?).to be false
assert_enqueued_with(job: ActionMailer::MailDeliveryJob)
expect(enqueued_jobs.count).to eq 1
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/services/quarterly_reports/notify_managers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
assert_enqueued_with(job: ActionMailer::MailDeliveryJob) do
subject
end
expect(enqueued_jobs.count).to eq 1
end
end
end

0 comments on commit 5027346

Please sign in to comment.