Chatwoot/spec/jobs/avatar/avatar_from_gravatar_job_spec.rb
Sojan Jose 6a6a37a67b
chore: Ability to Disable Gravatars (#5027)
fixes: #3853

- Introduced DISABLE_GRAVATAR Global Config, which will stop chatwoot from making API requests to gravatar
- Cleaned up avatar-related logic and centralized it into the avatarable concern
- Added specs for the missing cases
- Added migration for existing installations to move the avatar to attachment, rather than making the API that results in 404.
2022-07-21 19:27:12 +02:00

29 lines
1.1 KiB
Ruby

require 'rails_helper'
RSpec.describe Avatar::AvatarFromGravatarJob, type: :job do
let(:avatarable) { create(:contact) }
let(:email) { 'test@test.com' }
let(:gravatar_url) { "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}?d=404" }
it 'enqueues the job' do
expect { described_class.perform_later(avatarable, email) }.to have_enqueued_job(described_class)
.on_queue('low')
end
it 'will call AvatarFromUrlJob with gravatar url' do
expect(Avatar::AvatarFromUrlJob).to receive(:perform_later).with(avatarable, gravatar_url)
described_class.perform_now(avatarable, email)
end
it 'will not call AvatarFromUrlJob if DISABLE_GRAVATAR is configured' do
with_modified_env DISABLE_GRAVATAR: 'true' do
expect(Avatar::AvatarFromUrlJob).not_to receive(:perform_later).with(avatarable, gravatar_url)
described_class.perform_now(avatarable, '')
end
end
it 'will not call AvatarFromUrlJob if email is blank' do
expect(Avatar::AvatarFromUrlJob).not_to receive(:perform_later).with(avatarable, gravatar_url)
described_class.perform_now(avatarable, '')
end
end