Skip to content

Commit f542959

Browse files
Merge pull request #18 from GetUp/handle_null_campaign_ids
Handle messages received by Spoke that aren't associated with a campaign
2 parents 2afe74c + f7897d5 commit f542959

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/identity_spoke.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ def self.handle_new_message(sync_id, message)
133133
Rails.logger.info "#{SYSTEM_NAME.titleize} #{sync_id}: Handling message: #{message.id}/#{message.created_at.utc.to_s(:inspect)}"
134134

135135
## Find who is the campaign contact for the message
136-
unless campaign_contact = IdentitySpoke::CampaignContact.find(message.campaign_contact_id)
137-
Notify.warning "Spoke: CampaignContact Find Failed", "campaign_id: #{message.campaign_contact_id}, cell: #{message.contact_number}"
136+
campaign_contact_id = message.campaign_contact_id
137+
campaign_contact = IdentitySpoke::CampaignContact.find(campaign_contact_id) if campaign_contact_id
138+
if !campaign_contact
139+
Rails.logger.warn "#{SYSTEM_NAME.titleize} #{sync_id}: No campaign contact for message #{message.id}"
138140
return
139141
end
140142

spec/lib/identity_spoke_pull_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@
161161
expect(Contact.where(notes: 'outbound').count).to eq(3)
162162
end
163163

164+
context('message without a campaign contact and assignment') do
165+
before(:each) do
166+
@message = FactoryBot.create(
167+
:spoke_message_delivered,
168+
id: 10000,
169+
created_at: Time.now,
170+
assignment: nil,
171+
campaign_contact_id: nil,
172+
user_id: nil,
173+
user_number: '+61555123456',
174+
contact_number: '+61555654321'
175+
)
176+
end
177+
178+
it 'should gracefully handle processing the message' do
179+
IdentitySpoke.handle_new_message(@sync_id, @message)
180+
end
181+
end
182+
164183
context('with force=true passed as parameter') do
165184
ContactResponse.all.destroy_all
166185
Contact.all.destroy_all

0 commit comments

Comments
 (0)