Spec for delete_lead WIP

This commit is contained in:
Ziyi 2021-03-23 13:45:05 -07:00 committed by CactusPuppy
parent 58f130c132
commit c2b9275e02
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
3 changed files with 65 additions and 3 deletions

View file

@ -39,8 +39,6 @@ module External
body: { body: {
'email' => user.email, 'email' => user.email,
'firstName' => user.name, 'firstName' => user.name,
'overrideExisting' => true,
'subscribed' => true,
'addTags' => add_tags, 'addTags' => add_tags,
'removeTags' => remove_tags 'removeTags' => remove_tags
}.to_json }.to_json

View file

@ -81,6 +81,7 @@ class User < ApplicationRecord
after_save :touch_events after_save :touch_events
after_commit :mailbluster_create_lead, on: :create after_commit :mailbluster_create_lead, on: :create
after_commit :mailbluster_delete_lead, on: :destroy
# add scope # add scope
scope :comment_notifiable, ->(conference) {joins(:roles).where('roles.name IN (?)', [:organizer, :cfp]).where('roles.resource_type = ? AND roles.resource_id = ?', 'Conference', conference.id)} scope :comment_notifiable, ->(conference) {joins(:roles).where('roles.name IN (?)', [:organizer, :cfp]).where('roles.resource_type = ? AND roles.resource_id = ?', 'Conference', conference.id)}
@ -378,6 +379,10 @@ class User < ApplicationRecord
ApplicationController.helpers.create_lead(self) ApplicationController.helpers.create_lead(self)
end end
def mailbluster_delete_lead
ApplicationController.helpers.delete_lead(self)
end
def touch_events def touch_events
event_users.each(&:touch) event_users.each(&:touch)
end end

View file

@ -44,7 +44,66 @@ describe External::MailblusterHelper, type: :helper do
end end
describe 'edit_lead' do describe 'edit_lead' do
pending it 'makes a put request to Mailbluster\'s API to change the email and gets the correct response' do
response_body = "{
\"message\": \"Lead updated\",
\"lead\": {
\"id\": 329395,
\"firstName\": \"#{user.name}\",
\"lastName\": \"\",
\"fullName\": \"#{user.name}\",
\"email\": \"#{user.email}\",
\"subscribed\": true,
\"tags\": [
#{ENV['OSEM_NAME'] || 'snapcon'}
],
}
}"
stub_request(:put, url)
.to_return(body: response_body, status: 200)
add_tags = ['2021']
old_email = user.email
user.email = "new@new.org"
user.save
response = edit_lead(user, old_email: old_email)
expect(WebMock).to have_requested(:put, url + Digest::MD5.hexdigest(old_email)).with(body: {
'email': user.email,
'firstName': user.name,
'addTags': add_tags,
'removeTags': []
}.to_json)
expect(response).to eq(response_body)
end
it 'makes a put request to Mailbluster\'s API to add a tag and gets the correct response' do
response_body = "{
\"message\": \"Lead updated\",
\"lead\": {
\"id\": 329395,
\"firstName\": \"#{user.name}\",
\"lastName\": \"\",
\"fullName\": \"#{user.name}\",
\"email\": \"#{user.email}\",
\"subscribed\": true,
\"tags\": [
#{ENV['OSEM_NAME'] || 'snapcon'}, '2021'
],
}
}"
stub_request(:put, url + Digest::MD5.hexdigest(user.email))
.to_return(body: response_body, status: 200)
add_tags = ['2021']
response = edit_lead(user, add_tags: add_tags)
expect(WebMock).to have_requested(:put, url).with(body: {
'email': user.email,
'firstName': user.name,
'addTags': add_tags,
'removeTags': []
}.to_json)
expect(response).to eq(response_body)
end
end end
describe 'delete_lead' do describe 'delete_lead' do