feat: remove redact contact job
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
class Channels::Facebook::RedactContactDataJob < ApplicationJob
|
||||
queue_as :low
|
||||
|
||||
def perform(id_to_process)
|
||||
@id_to_process = id_to_process
|
||||
redact_contact_if_present
|
||||
|
||||
unset_processing
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unset_processing
|
||||
key = format(::Redis::Alfred::META_DELETE_PROCESSING, id: @id_to_process)
|
||||
::Redis::Alfred.delete(key)
|
||||
end
|
||||
|
||||
def redact_contact_if_present
|
||||
contact_inbox = ContactInbox.find_by(source_id: @id_to_process)
|
||||
return unless contact_inbox
|
||||
|
||||
contact = contact_inbox.contact
|
||||
contact.update!(
|
||||
name: 'Deleted User',
|
||||
email: nil,
|
||||
phone_number: nil,
|
||||
identifier: nil,
|
||||
additional_attributes: {},
|
||||
custom_attributes: {}
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -1,48 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Channels::Facebook::RedactContactDataJob do
|
||||
let(:facebook_id) { '1234567890' }
|
||||
let(:account) { create(:account) }
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
let(:redis_key) { format(Redis::Alfred::META_DELETE_PROCESSING, id: facebook_id) }
|
||||
|
||||
describe '#perform' do
|
||||
context 'when contact with facebook_id exists' do
|
||||
let(:contact) { create(:contact, :with_email, name: 'John Doe') }
|
||||
let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: inbox, source_id: facebook_id) }
|
||||
|
||||
before do
|
||||
allow(Redis::Alfred).to receive(:delete)
|
||||
# Create the contact_inbox before running the test to ensure it exists
|
||||
# this is to get around the fact that `let!` is not permitted by our rubocop rules
|
||||
contact_inbox
|
||||
end
|
||||
|
||||
it 'anonymizes contact data and removes processing flag' do
|
||||
described_class.perform_now(facebook_id)
|
||||
contact.reload
|
||||
|
||||
expect(contact.name).to eq('Deleted User')
|
||||
expect(contact.email).to be_nil
|
||||
expect(contact.phone_number).to be_nil
|
||||
expect(contact.identifier).to be_nil
|
||||
expect(contact.additional_attributes).to eq({})
|
||||
expect(contact.custom_attributes).to eq({})
|
||||
|
||||
expect(Redis::Alfred).to have_received(:delete).with(redis_key)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when contact with facebook_id does not exist' do
|
||||
before do
|
||||
allow(Redis::Alfred).to receive(:delete)
|
||||
end
|
||||
|
||||
it 'still removes the processing flag from Redis' do
|
||||
described_class.perform_now(facebook_id)
|
||||
|
||||
expect(Redis::Alfred).to have_received(:delete).with(redis_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user