From 3428929d88ee3b79b5c5059fd423012894036c6c Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Wed, 25 May 2022 19:02:46 -0600 Subject: [PATCH 01/24] create case contact types reminder task --- lib/tasks/case_contact_types_reminder.rb | 45 +++++++++++++++++++ .../send_case_contact_types_reminder.rake | 7 +++ 2 files changed, 52 insertions(+) create mode 100644 lib/tasks/case_contact_types_reminder.rb create mode 100644 lib/tasks/send_case_contact_types_reminder.rake diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb new file mode 100644 index 0000000000..82732d204d --- /dev/null +++ b/lib/tasks/case_contact_types_reminder.rb @@ -0,0 +1,45 @@ +class CaseContactTypesReminder + def send! + eligible_volunteers = User.where(type: Volunteer, receive_sms_notifications: true) # TODO: add condition so they are only notified one per quarter + eligible_volunteers.each do |volunteer| + uncontacted_case_contact_types = uncontacted_case_types(volunteer) + send_sms_messages(volunteer, uncontacted_case_contact_types) + end + end + + private + + def uncontacted_case_contact_types(volunteer) + contacted_types = volunteer.case_contacts.where('occured_at < ?', 2.months.ago).joins(:contact_types).pluck(:name) + ContactType.all.pluck(:name).uniq - contacted_types + end + + def send_sms_messages(volunteer, uncontacted_case_contact_types) + volunteer_casa_org = volunteer.casa_org + if !valid_casa_twilio_creds(volunteer_casa_org) + return + end + + twilio_service = TwilioService.new(volunteer_casa_org.twilio_api_key_sid, volunteer_casa_org.twilio_api_key_secret, volunteer.twilio_account_sid) + sms_params = { + From: volunteer_casa_org.twilio_phone_number, + Body: nil, + To: volunteer.phone_number, + } + + messages = [ + ["It's been 60 days or more since you've reached out to these members of your youth's network:"], + [uncontacted_case_contact_types], + ["If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]"] + ] + + messages.each do |contents| + sms_params.Body = contents.join("\n") + twilio_service.send_sms(sms_params) + end + end + + def valid_casa_twilio_creds(casa_org) + casa_org.twilio_phone_number && casa_org.twilio_account_sid && casa_org.twilio_api_key_sid && casa_org.twilio_api_key_secret + end +end \ No newline at end of file diff --git a/lib/tasks/send_case_contact_types_reminder.rake b/lib/tasks/send_case_contact_types_reminder.rake new file mode 100644 index 0000000000..70bf91f621 --- /dev/null +++ b/lib/tasks/send_case_contact_types_reminder.rake @@ -0,0 +1,7 @@ +desc "Send an SMS to volunteers reminding them to connect with the contact types they have not connected with in the past 60 or more days" +require_relative "./case_contact_types_reminder.rb" +task send_case_contact_types_reminder: :environment do + every 1.days do # TODO: figure out how often we should run this + CaseContactTypesReminder.new.send! + end +end From a5a48357d4fc0e0a627d2d4b62f1442395898581 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Wed, 25 May 2022 19:33:43 -0600 Subject: [PATCH 02/24] add table to capture reminder sent time so reminders are only sent once per quarter --- .../user_case_contact_types_reminder.rb | 22 +++++ ...reate_user_case_contact_types_reminders.rb | 10 ++ db/schema.rb | 11 ++- lib/tasks/case_contact_types_reminder.rb | 99 ++++++++++++------- .../send_case_contact_types_reminder.rake | 2 +- .../user_case_contact_types_reminders.rb | 6 ++ .../user_case_contact_types_reminder_spec.rb | 5 + 7 files changed, 117 insertions(+), 38 deletions(-) create mode 100644 app/models/user_case_contact_types_reminder.rb create mode 100644 db/migrate/20220526011848_create_user_case_contact_types_reminders.rb create mode 100644 spec/factories/user_case_contact_types_reminders.rb create mode 100644 spec/models/user_case_contact_types_reminder_spec.rb diff --git a/app/models/user_case_contact_types_reminder.rb b/app/models/user_case_contact_types_reminder.rb new file mode 100644 index 0000000000..943021eb2b --- /dev/null +++ b/app/models/user_case_contact_types_reminder.rb @@ -0,0 +1,22 @@ +class UserCaseContactTypesReminder < ApplicationRecord + belongs_to :user +end + +# == Schema Information +# +# Table name: user_case_contact_types_reminders +# +# id :bigint not null, primary key +# reminder_sent :datetime +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint not null +# +# Indexes +# +# index_user_case_contact_types_reminders_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# diff --git a/db/migrate/20220526011848_create_user_case_contact_types_reminders.rb b/db/migrate/20220526011848_create_user_case_contact_types_reminders.rb new file mode 100644 index 0000000000..a46ec55d1c --- /dev/null +++ b/db/migrate/20220526011848_create_user_case_contact_types_reminders.rb @@ -0,0 +1,10 @@ +class CreateUserCaseContactTypesReminders < ActiveRecord::Migration[7.0] + def change + create_table :user_case_contact_types_reminders do |t| + t.belongs_to :user, null: false, foreign_key: true + t.datetime :reminder_sent + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c2f2ec704d..104047f470 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_05_19_233803) do +ActiveRecord::Schema[7.0].define(version: 2022_05_26_011848) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -389,6 +389,14 @@ t.string "version", null: false end + create_table "user_case_contact_types_reminders", force: :cascade do |t| + t.bigint "user_id", null: false + t.datetime "reminder_sent" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_user_case_contact_types_reminders_on_user_id" + end + create_table "user_sms_notification_events", force: :cascade do |t| t.bigint "user_id", null: false t.bigint "sms_notification_event_id", null: false @@ -457,6 +465,7 @@ add_foreign_key "sent_emails", "users" add_foreign_key "supervisor_volunteers", "users", column: "supervisor_id" add_foreign_key "supervisor_volunteers", "users", column: "volunteer_id" + add_foreign_key "user_case_contact_types_reminders", "users" add_foreign_key "user_sms_notification_events", "sms_notification_events" add_foreign_key "user_sms_notification_events", "users" add_foreign_key "users", "casa_orgs" diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index 82732d204d..81d3e333f7 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -1,45 +1,72 @@ class CaseContactTypesReminder - def send! - eligible_volunteers = User.where(type: Volunteer, receive_sms_notifications: true) # TODO: add condition so they are only notified one per quarter - eligible_volunteers.each do |volunteer| - uncontacted_case_contact_types = uncontacted_case_types(volunteer) - send_sms_messages(volunteer, uncontacted_case_contact_types) - end + def send! + # TODO: add condition so they are only notified one per quarter + eligible_volunteers = User.where(type: Volunteer, receive_sms_notifications: true).where.not(phone_number: nil) + eligible_volunteers.each do |volunteer| + next if last_reminder_within_quarter(volunteer) + uncontacted_case_contact_types = uncontacted_case_types(volunteer) + send_sms_messages(volunteer, uncontacted_case_contact_types) + update_reminder_sent_time(volunteer) end + end - private + private - def uncontacted_case_contact_types(volunteer) - contacted_types = volunteer.case_contacts.where('occured_at < ?', 2.months.ago).joins(:contact_types).pluck(:name) - ContactType.all.pluck(:name).uniq - contacted_types + def uncontacted_case_contact_types(volunteer) + contacted_types = volunteer.case_contacts.where("occured_at < ?", 2.months.ago).joins(:contact_types).pluck(:name) + ContactType.all.pluck(:name).uniq - contacted_types + end + + def send_sms_messages(volunteer, uncontacted_case_contact_types) + volunteer_casa_org = volunteer.casa_org + if !valid_casa_twilio_creds(volunteer_casa_org) + return + end + + twilio_service = TwilioService.new(volunteer_casa_org.twilio_api_key_sid, volunteer_casa_org.twilio_api_key_secret, volunteer.twilio_account_sid) + sms_params = { + From: volunteer_casa_org.twilio_phone_number, + Body: nil, + To: volunteer.phone_number + } + + messages = [ + ["It's been 60 days or more since you've reached out to these members of your youth's network:"], + [uncontacted_case_contact_types], + ["If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]"] + ] + + messages.each do |contents| + sms_params.Body = contents.join("\n") + twilio_service.send_sms(sms_params) end - def send_sms_messages(volunteer, uncontacted_case_contact_types) - volunteer_casa_org = volunteer.casa_org - if !valid_casa_twilio_creds(volunteer_casa_org) - return - end - - twilio_service = TwilioService.new(volunteer_casa_org.twilio_api_key_sid, volunteer_casa_org.twilio_api_key_secret, volunteer.twilio_account_sid) - sms_params = { - From: volunteer_casa_org.twilio_phone_number, - Body: nil, - To: volunteer.phone_number, - } - - messages = [ - ["It's been 60 days or more since you've reached out to these members of your youth's network:"], - [uncontacted_case_contact_types], - ["If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]"] - ] - - messages.each do |contents| - sms_params.Body = contents.join("\n") - twilio_service.send_sms(sms_params) - end + + end + + def valid_casa_twilio_creds(casa_org) + casa_org.twilio_phone_number? && casa_org.twilio_account_sid? && casa_org.twilio_api_key_sid? && casa_org.twilio_api_key_secret? + end + + def last_reminder_within_quarter(volunteer) + reminder = UserCaseContactTypesReminder.find_by(user_id: volunteer.id) + + if reminder? + return reminder.reminder_sent < 3.months.ago end - def valid_casa_twilio_creds(casa_org) - casa_org.twilio_phone_number && casa_org.twilio_account_sid && casa_org.twilio_api_key_sid && casa_org.twilio_api_key_secret + false + end + + def update_reminder_sent_time(volunteer) + reminder = UserCaseContactTypesReminder.find_by(user_id: volunteer.id) + + if reminder? + reminder.reminder_sent = DateTime.now + else + reminder = UserCaseContactTypesReminder.new(user_id: volunteer.id, reminder_sent: DateTime.now) end -end \ No newline at end of file + + reminder.save + end +end diff --git a/lib/tasks/send_case_contact_types_reminder.rake b/lib/tasks/send_case_contact_types_reminder.rake index 70bf91f621..93672dad51 100644 --- a/lib/tasks/send_case_contact_types_reminder.rake +++ b/lib/tasks/send_case_contact_types_reminder.rake @@ -1,5 +1,5 @@ desc "Send an SMS to volunteers reminding them to connect with the contact types they have not connected with in the past 60 or more days" -require_relative "./case_contact_types_reminder.rb" +require_relative "./case_contact_types_reminder" task send_case_contact_types_reminder: :environment do every 1.days do # TODO: figure out how often we should run this CaseContactTypesReminder.new.send! diff --git a/spec/factories/user_case_contact_types_reminders.rb b/spec/factories/user_case_contact_types_reminders.rb new file mode 100644 index 0000000000..b7ec09aaf0 --- /dev/null +++ b/spec/factories/user_case_contact_types_reminders.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :user_case_contact_types_reminder do + user { create(:user) } + reminder_sent { "2022-05-25 19:18:48" } + end +end diff --git a/spec/models/user_case_contact_types_reminder_spec.rb b/spec/models/user_case_contact_types_reminder_spec.rb new file mode 100644 index 0000000000..15fc5ef8d2 --- /dev/null +++ b/spec/models/user_case_contact_types_reminder_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +RSpec.describe UserCaseContactTypesReminder, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 36d9e6e7d3fbbc8ca10978ddd0b7ead7d31518ca Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sat, 28 May 2022 21:35:42 -0700 Subject: [PATCH 03/24] write task tests for sms contact types reminder (wip) --- lib/tasks/case_contact_types_reminder.rb | 42 ++++++---- .../user_case_contact_types_reminders.rb | 2 +- .../tasks/case_contact_types_reminder_spec.rb | 79 +++++++++++++++++++ spec/support/webmock_helper.rb | 39 +++++++++ 4 files changed, 145 insertions(+), 17 deletions(-) create mode 100644 spec/lib/tasks/case_contact_types_reminder_spec.rb diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index 81d3e333f7..2af4327642 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -1,29 +1,38 @@ class CaseContactTypesReminder + FIRST_MESSAGE = "It's been 60 days or more since you've reached out to these members of your youth's network:" + THIRD_MESSAGE = "If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]" + def send! - # TODO: add condition so they are only notified one per quarter - eligible_volunteers = User.where(type: Volunteer, receive_sms_notifications: true).where.not(phone_number: nil) + responses = [] + eligible_volunteers = User.where(type: :Volunteer, receive_sms_notifications: true).where.not(phone_number: nil) eligible_volunteers.each do |volunteer| next if last_reminder_within_quarter(volunteer) - uncontacted_case_contact_types = uncontacted_case_types(volunteer) - send_sms_messages(volunteer, uncontacted_case_contact_types) + uncontacted_case_contact_type_names = uncontacted_case_contact_types(volunteer) + responses.push( + { + volunteer: volunteer, + messages: send_sms_messages(volunteer, uncontacted_case_contact_type_names) + } + ) update_reminder_sent_time(volunteer) end + return responses end private def uncontacted_case_contact_types(volunteer) - contacted_types = volunteer.case_contacts.where("occured_at < ?", 2.months.ago).joins(:contact_types).pluck(:name) + contacted_types = volunteer.case_contacts.where("occurred_at < ?", 2.months.ago).joins(:contact_types).pluck(:name) ContactType.all.pluck(:name).uniq - contacted_types end - def send_sms_messages(volunteer, uncontacted_case_contact_types) + def send_sms_messages(volunteer, uncontacted_case_contact_type_names) volunteer_casa_org = volunteer.casa_org if !valid_casa_twilio_creds(volunteer_casa_org) return end - twilio_service = TwilioService.new(volunteer_casa_org.twilio_api_key_sid, volunteer_casa_org.twilio_api_key_secret, volunteer.twilio_account_sid) + twilio_service = TwilioService.new(volunteer_casa_org.twilio_api_key_sid, volunteer_casa_org.twilio_api_key_secret, volunteer_casa_org.twilio_account_sid) sms_params = { From: volunteer_casa_org.twilio_phone_number, Body: nil, @@ -31,17 +40,18 @@ def send_sms_messages(volunteer, uncontacted_case_contact_types) } messages = [ - ["It's been 60 days or more since you've reached out to these members of your youth's network:"], - [uncontacted_case_contact_types], - ["If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]"] + [FIRST_MESSAGE], + [uncontacted_case_contact_type_names], + [THIRD_MESSAGE] ] + responses = [] messages.each do |contents| - sms_params.Body = contents.join("\n") - twilio_service.send_sms(sms_params) + sms_params[:Body] = contents.join("\n") + responses.push(twilio_service.send_sms(sms_params)) end - - + + responses end def valid_casa_twilio_creds(casa_org) @@ -51,7 +61,7 @@ def valid_casa_twilio_creds(casa_org) def last_reminder_within_quarter(volunteer) reminder = UserCaseContactTypesReminder.find_by(user_id: volunteer.id) - if reminder? + if reminder return reminder.reminder_sent < 3.months.ago end @@ -61,7 +71,7 @@ def last_reminder_within_quarter(volunteer) def update_reminder_sent_time(volunteer) reminder = UserCaseContactTypesReminder.find_by(user_id: volunteer.id) - if reminder? + if reminder reminder.reminder_sent = DateTime.now else reminder = UserCaseContactTypesReminder.new(user_id: volunteer.id, reminder_sent: DateTime.now) diff --git a/spec/factories/user_case_contact_types_reminders.rb b/spec/factories/user_case_contact_types_reminders.rb index b7ec09aaf0..d528b7e713 100644 --- a/spec/factories/user_case_contact_types_reminders.rb +++ b/spec/factories/user_case_contact_types_reminders.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :user_case_contact_types_reminder do user { create(:user) } - reminder_sent { "2022-05-25 19:18:48" } + reminder_sent { DateTime.now } end end diff --git a/spec/lib/tasks/case_contact_types_reminder_spec.rb b/spec/lib/tasks/case_contact_types_reminder_spec.rb new file mode 100644 index 0000000000..8d8b019833 --- /dev/null +++ b/spec/lib/tasks/case_contact_types_reminder_spec.rb @@ -0,0 +1,79 @@ +require "rails_helper" +require_relative "../../../lib/tasks/case_contact_types_reminder" +require "support/webmock_helper" + +RSpec.describe CaseContactTypesReminder do + let!(:casa_org) do + create( + :casa_org, + twilio_phone_number: "+15555555555", + twilio_account_sid: "articuno34", + twilio_api_key_sid: "Aladdin", + twilio_api_key_secret: "open sesame" + ) + end + let!(:volunteer) do + create( + :volunteer, + casa_org_id: casa_org.id, + phone_number: "+12222222222", + receive_sms_notifications: true + ) + end + let!(:contact_type) { create(:contact_type, name: "test") } + + before do + stubbed_requests + WebMock.disable_net_connect! + end + + context "volunteer with uncontacted contact types, sms notifications on, and no reminder in last quarter" do + it "should send sms reminder" do + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 1 + expect(responses[0][:messages][0].body).to match CaseContactTypesReminder::FIRST_MESSAGE + expect(responses[0][:messages][1].body).to match contact_type.name + expect(responses[0][:messages][2].body).to match CaseContactTypesReminder::THIRD_MESSAGE + end + end + + context "volunteer with uncontacted contact types, sms notifications off, and no reminder in last quarter" do + it "should not send sms reminder" do + Volunteer.update_all(receive_sms_notifications: false) + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 0 + end + end + + context "volunteer with uncontacted contact types, sms notifications on, and reminder in last quarter" do + it "should not send sms reminder" do + create(:user_case_contact_types_reminder, user_id: volunteer.id) + Volunteer.update_all(receive_sms_notifications: true) + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 0 + end + end + + context "volunteer with uncontacted contact types, sms notifications on, and reminder out of last quarter" do + it "should send sms reminder" do + UserCaseContactTypesReminder.destroy_all + Volunteer.all do |v| + create(:user_case_contact_types_reminder, user_id: v.id, reminder_sent: 4.months.ago) + end + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 1 + expect(responses[0][:messages][0].body).to match CaseContactTypesReminder::FIRST_MESSAGE + expect(responses[0][:messages][1].body).to match contact_type.name + expect(responses[0][:messages][2].body).to match CaseContactTypesReminder::THIRD_MESSAGE + end + end + + context "volunteer with uncontacted contact types, sms notifications on, no reminder in last quarter, no phone number" do + it "should not send sms reminder" do + UserCaseContactTypesReminder.destroy_all + Volunteer.update_all(phone_number: nil) + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 0 + end + end +end \ No newline at end of file diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index 55d88cb8a2..761583145e 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -1,4 +1,5 @@ def stubbed_requests + # twilio_service_spec stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") .with( body: {From: "+15555555555", Body: "Execute Order 66 - https://42ni.short.gy/jzTwdF", To: "+12222222222"}, @@ -20,4 +21,42 @@ def stubbed_requests } ) .to_return(status: 200, body: "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}", headers: {}) + # case_contact_types_reminder_spec + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). + with( + body: {"Body"=>"It's been 60 days or more since you've reached out to these members of your youth's network:", "From"=>"+15555555555", "To"=>"+12222222222"}, + headers: { + 'Accept'=>'application/json', + 'Accept-Charset'=>'utf-8', + 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', + 'Content-Type'=>'application/x-www-form-urlencoded', + 'User-Agent'=>'twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0' + }). + to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). + with( + body: {"Body"=>"test", "From"=>"+15555555555", "To"=>"+12222222222"}, + headers: { + 'Accept'=>'application/json', + 'Accept-Charset'=>'utf-8', + 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', + 'Content-Type'=>'application/x-www-form-urlencoded', + 'User-Agent'=>'twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0' + }). + to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"test\"}") + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). + with( + body: {"Body"=>"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]", "From"=>"+15555555555", "To"=>"+12222222222"}, + headers: { + 'Accept'=>'application/json', + 'Accept-Charset'=>'utf-8', + 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', + 'Content-Type'=>'application/x-www-form-urlencoded', + 'User-Agent'=>'twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0' + }). + to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]\"}") + end From 4912e00d4ee856a71dd489a75c9663760e4a8941 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 29 May 2022 11:28:05 -0700 Subject: [PATCH 04/24] complete casa contact types reminder testing --- lib/tasks/case_contact_types_reminder.rb | 10 +- .../tasks/case_contact_types_reminder_spec.rb | 128 +++++++++--------- spec/support/webmock_helper.rb | 70 +++++----- 3 files changed, 105 insertions(+), 103 deletions(-) diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index 2af4327642..258a3a622a 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -16,7 +16,7 @@ def send! ) update_reminder_sent_time(volunteer) end - return responses + responses end private @@ -50,7 +50,7 @@ def send_sms_messages(volunteer, uncontacted_case_contact_type_names) sms_params[:Body] = contents.join("\n") responses.push(twilio_service.send_sms(sms_params)) end - + responses end @@ -62,7 +62,7 @@ def last_reminder_within_quarter(volunteer) reminder = UserCaseContactTypesReminder.find_by(user_id: volunteer.id) if reminder - return reminder.reminder_sent < 3.months.ago + return reminder.reminder_sent > 3.months.ago end false @@ -72,9 +72,9 @@ def update_reminder_sent_time(volunteer) reminder = UserCaseContactTypesReminder.find_by(user_id: volunteer.id) if reminder - reminder.reminder_sent = DateTime.now + reminder.reminder_sent = DateTime.now else - reminder = UserCaseContactTypesReminder.new(user_id: volunteer.id, reminder_sent: DateTime.now) + reminder = UserCaseContactTypesReminder.new(user_id: volunteer.id, reminder_sent: DateTime.now) end reminder.save diff --git a/spec/lib/tasks/case_contact_types_reminder_spec.rb b/spec/lib/tasks/case_contact_types_reminder_spec.rb index 8d8b019833..5c1b62382d 100644 --- a/spec/lib/tasks/case_contact_types_reminder_spec.rb +++ b/spec/lib/tasks/case_contact_types_reminder_spec.rb @@ -3,77 +3,77 @@ require "support/webmock_helper" RSpec.describe CaseContactTypesReminder do - let!(:casa_org) do - create( - :casa_org, - twilio_phone_number: "+15555555555", - twilio_account_sid: "articuno34", - twilio_api_key_sid: "Aladdin", - twilio_api_key_secret: "open sesame" - ) - end - let!(:volunteer) do - create( - :volunteer, - casa_org_id: casa_org.id, - phone_number: "+12222222222", - receive_sms_notifications: true - ) - end - let!(:contact_type) { create(:contact_type, name: "test") } + let!(:casa_org) do + create( + :casa_org, + twilio_phone_number: "+15555555555", + twilio_account_sid: "articuno34", + twilio_api_key_sid: "Aladdin", + twilio_api_key_secret: "open sesame" + ) + end + let!(:volunteer) do + create( + :volunteer, + casa_org_id: casa_org.id, + phone_number: "+12222222222", + receive_sms_notifications: true + ) + end + let!(:contact_type) { create(:contact_type, name: "test") } - before do - stubbed_requests - WebMock.disable_net_connect! - end - - context "volunteer with uncontacted contact types, sms notifications on, and no reminder in last quarter" do - it "should send sms reminder" do - responses = CaseContactTypesReminder.new.send! - expect(responses.count).to match 1 - expect(responses[0][:messages][0].body).to match CaseContactTypesReminder::FIRST_MESSAGE - expect(responses[0][:messages][1].body).to match contact_type.name - expect(responses[0][:messages][2].body).to match CaseContactTypesReminder::THIRD_MESSAGE - end + before do + stubbed_requests + WebMock.disable_net_connect! + end + + context "volunteer with uncontacted contact types, sms notifications on, and no reminder in last quarter" do + it "should send sms reminder" do + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 1 + expect(responses[0][:messages][0].body).to match CaseContactTypesReminder::FIRST_MESSAGE + expect(responses[0][:messages][1].body).to match contact_type.name + expect(responses[0][:messages][2].body).to match CaseContactTypesReminder::THIRD_MESSAGE end + end - context "volunteer with uncontacted contact types, sms notifications off, and no reminder in last quarter" do - it "should not send sms reminder" do - Volunteer.update_all(receive_sms_notifications: false) - responses = CaseContactTypesReminder.new.send! - expect(responses.count).to match 0 - end + context "volunteer with uncontacted contact types, sms notifications off, and no reminder in last quarter" do + it "should not send sms reminder" do + Volunteer.update_all(receive_sms_notifications: false) + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 0 end + end - context "volunteer with uncontacted contact types, sms notifications on, and reminder in last quarter" do - it "should not send sms reminder" do - create(:user_case_contact_types_reminder, user_id: volunteer.id) - Volunteer.update_all(receive_sms_notifications: true) - responses = CaseContactTypesReminder.new.send! - expect(responses.count).to match 0 - end + context "volunteer with uncontacted contact types, sms notifications on, and reminder in last quarter" do + it "should not send sms reminder" do + create(:user_case_contact_types_reminder, user_id: volunteer.id) + Volunteer.update_all(receive_sms_notifications: true) + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 0 end + end - context "volunteer with uncontacted contact types, sms notifications on, and reminder out of last quarter" do - it "should send sms reminder" do - UserCaseContactTypesReminder.destroy_all - Volunteer.all do |v| - create(:user_case_contact_types_reminder, user_id: v.id, reminder_sent: 4.months.ago) - end - responses = CaseContactTypesReminder.new.send! - expect(responses.count).to match 1 - expect(responses[0][:messages][0].body).to match CaseContactTypesReminder::FIRST_MESSAGE - expect(responses[0][:messages][1].body).to match contact_type.name - expect(responses[0][:messages][2].body).to match CaseContactTypesReminder::THIRD_MESSAGE - end + context "volunteer with uncontacted contact types, sms notifications on, and reminder out of last quarter" do + it "should send sms reminder" do + UserCaseContactTypesReminder.destroy_all + Volunteer.all do |v| + create(:user_case_contact_types_reminder, user_id: v.id, reminder_sent: 4.months.ago) + end + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 1 + expect(responses[0][:messages][0].body).to match CaseContactTypesReminder::FIRST_MESSAGE + expect(responses[0][:messages][1].body).to match contact_type.name + expect(responses[0][:messages][2].body).to match CaseContactTypesReminder::THIRD_MESSAGE end + end - context "volunteer with uncontacted contact types, sms notifications on, no reminder in last quarter, no phone number" do - it "should not send sms reminder" do - UserCaseContactTypesReminder.destroy_all - Volunteer.update_all(phone_number: nil) - responses = CaseContactTypesReminder.new.send! - expect(responses.count).to match 0 - end + context "volunteer with uncontacted contact types, sms notifications on, no reminder in last quarter, no phone number" do + it "should not send sms reminder" do + UserCaseContactTypesReminder.destroy_all + Volunteer.update_all(phone_number: nil) + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 0 end -end \ No newline at end of file + end +end diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index 761583145e..a84a9d00db 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -22,41 +22,43 @@ def stubbed_requests ) .to_return(status: 200, body: "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}", headers: {}) # case_contact_types_reminder_spec - stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). - with( - body: {"Body"=>"It's been 60 days or more since you've reached out to these members of your youth's network:", "From"=>"+15555555555", "To"=>"+12222222222"}, + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") + .with( + body: {"Body" => "It's been 60 days or more since you've reached out to these members of your youth's network:", "From" => "+15555555555", "To" => "+12222222222"}, headers: { - 'Accept'=>'application/json', - 'Accept-Charset'=>'utf-8', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', - 'Content-Type'=>'application/x-www-form-urlencoded', - 'User-Agent'=>'twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0' - }). - to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") - stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). - with( - body: {"Body"=>"test", "From"=>"+15555555555", "To"=>"+12222222222"}, + "Accept" => "application/json", + "Accept-Charset" => "utf-8", + "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", + "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", + "Content-Type" => "application/x-www-form-urlencoded", + "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" + } + ) + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") + .with( + body: {"Body" => "test", "From" => "+15555555555", "To" => "+12222222222"}, headers: { - 'Accept'=>'application/json', - 'Accept-Charset'=>'utf-8', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', - 'Content-Type'=>'application/x-www-form-urlencoded', - 'User-Agent'=>'twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0' - }). - to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"test\"}") - stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). - with( - body: {"Body"=>"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]", "From"=>"+15555555555", "To"=>"+12222222222"}, + "Accept" => "application/json", + "Accept-Charset" => "utf-8", + "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", + "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", + "Content-Type" => "application/x-www-form-urlencoded", + "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" + } + ) + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"test\"}") + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") + .with( + body: {"Body" => "If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]", "From" => "+15555555555", "To" => "+12222222222"}, headers: { - 'Accept'=>'application/json', - 'Accept-Charset'=>'utf-8', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', - 'Content-Type'=>'application/x-www-form-urlencoded', - 'User-Agent'=>'twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0' - }). - to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]\"}") - + "Accept" => "application/json", + "Accept-Charset" => "utf-8", + "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", + "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", + "Content-Type" => "application/x-www-form-urlencoded", + "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" + } + ) + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]\"}") end From 213bf6042ce56d59e3d211eb16c56729c391c656 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 29 May 2022 11:53:02 -0700 Subject: [PATCH 05/24] add test for when case contact was made within last 60 days 9sms should not be sent) --- lib/tasks/case_contact_types_reminder.rb | 3 ++- .../tasks/case_contact_types_reminder_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index 258a3a622a..a641598c3a 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -8,6 +8,7 @@ def send! eligible_volunteers.each do |volunteer| next if last_reminder_within_quarter(volunteer) uncontacted_case_contact_type_names = uncontacted_case_contact_types(volunteer) + next if uncontacted_case_contact_type_names.count == 0 responses.push( { volunteer: volunteer, @@ -22,7 +23,7 @@ def send! private def uncontacted_case_contact_types(volunteer) - contacted_types = volunteer.case_contacts.where("occurred_at < ?", 2.months.ago).joins(:contact_types).pluck(:name) + contacted_types = volunteer.case_contacts.where("occurred_at > ?", 2.months.ago).joins(:contact_types).pluck(:name) ContactType.all.pluck(:name).uniq - contacted_types end diff --git a/spec/lib/tasks/case_contact_types_reminder_spec.rb b/spec/lib/tasks/case_contact_types_reminder_spec.rb index 5c1b62382d..5aae3e295b 100644 --- a/spec/lib/tasks/case_contact_types_reminder_spec.rb +++ b/spec/lib/tasks/case_contact_types_reminder_spec.rb @@ -21,6 +21,14 @@ ) end let!(:contact_type) { create(:contact_type, name: "test") } + let!(:case_contact) do + create( + :case_contact, + creator: volunteer, + contact_types: [contact_type], + occurred_at: 4.months.ago + ) + end before do stubbed_requests @@ -37,6 +45,14 @@ end end + context "volunteer with contacted contact types within last 60 days, sms notifications on, and no reminder in last quarter" do + it "should send not sms reminder" do + CaseContact.update_all(occurred_at: 1.months.ago) + responses = CaseContactTypesReminder.new.send! + expect(responses.count).to match 0 + end + end + context "volunteer with uncontacted contact types, sms notifications off, and no reminder in last quarter" do it "should not send sms reminder" do Volunteer.update_all(receive_sms_notifications: false) From 19fc6acaa8d8d4715abdaf6e443bed1baa36124c Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 29 May 2022 14:40:02 -0700 Subject: [PATCH 06/24] add stubs to webmock helper for linux architecture --- spec/support/webmock_helper.rb | 45 +++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index a84a9d00db..32156d502f 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -22,9 +22,21 @@ def stubbed_requests ) .to_return(status: 200, body: "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}", headers: {}) # case_contact_types_reminder_spec + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). + with( + body: {"Body"=>"It's been 60 days or more since you've reached out to these members of your youth's network:", "From"=>"+15555555555", "To"=>"+12222222222"}, + headers: { + 'Accept'=>'application/json', + 'Accept-Charset'=>'utf-8', + 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', + 'Content-Type'=>'application/x-www-form-urlencoded', + 'User-Agent'=>'twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0' + }). + to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") .with( - body: {"Body" => "It's been 60 days or more since you've reached out to these members of your youth's network:", "From" => "+15555555555", "To" => "+12222222222"}, + body: {"Body" => "test", "From" => "+15555555555", "To" => "+12222222222"}, headers: { "Accept" => "application/json", "Accept-Charset" => "utf-8", @@ -34,10 +46,10 @@ def stubbed_requests "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" } ) - .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"test\"}") stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") .with( - body: {"Body" => "test", "From" => "+15555555555", "To" => "+12222222222"}, + body: {"Body" => "If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]", "From" => "+15555555555", "To" => "+12222222222"}, headers: { "Accept" => "application/json", "Accept-Charset" => "utf-8", @@ -47,6 +59,31 @@ def stubbed_requests "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" } ) + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]\"}") + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). + with( + body: {"Body"=>"It's been 60 days or more since you've reached out to these members of your youth's network:", "From"=>"+15555555555", "To"=>"+12222222222"}, + headers: { + 'Accept'=>'application/json', + 'Accept-Charset'=>'utf-8', + 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', + 'Content-Type'=>'application/x-www-form-urlencoded', + 'User-Agent'=>'twilio-ruby/5.67.1 (linux x86_64) Ruby/3.1.0' + }). + to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") + .with( + body: {"Body" => "test", "From" => "+15555555555", "To" => "+12222222222"}, + headers: { + "Accept" => "application/json", + "Accept-Charset" => "utf-8", + "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", + "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", + "Content-Type" => "application/x-www-form-urlencoded", + "User-Agent" => "twilio-ruby/5.67.1 (linux x86_64) Ruby/3.1.0" + } + ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"test\"}") stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") .with( @@ -57,7 +94,7 @@ def stubbed_requests "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", "Content-Type" => "application/x-www-form-urlencoded", - "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" + "User-Agent" => "twilio-ruby/5.67.1 (linux x86_64) Ruby/3.1.0" } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]\"}") From e8b658d2d21bf1aaf61b176820f8c57c32659521 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 29 May 2022 14:51:34 -0700 Subject: [PATCH 07/24] improve cognitive complexity of send function --- lib/tasks/case_contact_types_reminder.rb | 24 +++++++----- spec/support/webmock_helper.rb | 50 ++++++++++++------------ 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index a641598c3a..4a5e44c5d5 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -4,19 +4,23 @@ class CaseContactTypesReminder def send! responses = [] - eligible_volunteers = User.where(type: :Volunteer, receive_sms_notifications: true).where.not(phone_number: nil) + eligible_volunteers = Volunteer.where(receive_sms_notifications: true) + .where.not(phone_number: nil) + .select { |v| !last_reminder_within_quarter(v) } + eligible_volunteers.each do |volunteer| - next if last_reminder_within_quarter(volunteer) uncontacted_case_contact_type_names = uncontacted_case_contact_types(volunteer) - next if uncontacted_case_contact_type_names.count == 0 - responses.push( - { - volunteer: volunteer, - messages: send_sms_messages(volunteer, uncontacted_case_contact_type_names) - } - ) - update_reminder_sent_time(volunteer) + if uncontacted_case_contact_type_names.count > 0 + responses.push( + { + volunteer: volunteer, + messages: send_sms_messages(volunteer, uncontacted_case_contact_type_names) + } + ) + update_reminder_sent_time(volunteer) + end end + responses end diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index 32156d502f..a4e1e10f2e 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -22,18 +22,19 @@ def stubbed_requests ) .to_return(status: 200, body: "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}", headers: {}) # case_contact_types_reminder_spec - stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). - with( - body: {"Body"=>"It's been 60 days or more since you've reached out to these members of your youth's network:", "From"=>"+15555555555", "To"=>"+12222222222"}, - headers: { - 'Accept'=>'application/json', - 'Accept-Charset'=>'utf-8', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', - 'Content-Type'=>'application/x-www-form-urlencoded', - 'User-Agent'=>'twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0' - }). - to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") + .with( + body: {"Body" => "It's been 60 days or more since you've reached out to these members of your youth's network:", "From" => "+15555555555", "To" => "+12222222222"}, + headers: { + "Accept" => "application/json", + "Accept-Charset" => "utf-8", + "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", + "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", + "Content-Type" => "application/x-www-form-urlencoded", + "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" + } + ) + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") .with( body: {"Body" => "test", "From" => "+15555555555", "To" => "+12222222222"}, @@ -60,18 +61,19 @@ def stubbed_requests } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]\"}") - stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). - with( - body: {"Body"=>"It's been 60 days or more since you've reached out to these members of your youth's network:", "From"=>"+15555555555", "To"=>"+12222222222"}, - headers: { - 'Accept'=>'application/json', - 'Accept-Charset'=>'utf-8', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', - 'Content-Type'=>'application/x-www-form-urlencoded', - 'User-Agent'=>'twilio-ruby/5.67.1 (linux x86_64) Ruby/3.1.0' - }). - to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") + .with( + body: {"Body" => "It's been 60 days or more since you've reached out to these members of your youth's network:", "From" => "+15555555555", "To" => "+12222222222"}, + headers: { + "Accept" => "application/json", + "Accept-Charset" => "utf-8", + "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", + "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", + "Content-Type" => "application/x-www-form-urlencoded", + "User-Agent" => "twilio-ruby/5.67.1 (linux x86_64) Ruby/3.1.0" + } + ) + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") .with( body: {"Body" => "test", "From" => "+15555555555", "To" => "+12222222222"}, From 7beb5dd26c410ec43d3fea97e7843b08d0b796b4 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 29 May 2022 16:49:34 -0700 Subject: [PATCH 08/24] remove excess header attributes --- spec/support/webmock_helper.rb | 45 ---------------------------------- 1 file changed, 45 deletions(-) diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index a4e1e10f2e..85b8fcbc63 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -28,10 +28,8 @@ def stubbed_requests headers: { "Accept" => "application/json", "Accept-Charset" => "utf-8", - "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", "Content-Type" => "application/x-www-form-urlencoded", - "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") @@ -41,10 +39,8 @@ def stubbed_requests headers: { "Accept" => "application/json", "Accept-Charset" => "utf-8", - "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", "Content-Type" => "application/x-www-form-urlencoded", - "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"test\"}") @@ -54,49 +50,8 @@ def stubbed_requests headers: { "Accept" => "application/json", "Accept-Charset" => "utf-8", - "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", - "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", - "Content-Type" => "application/x-www-form-urlencoded", - "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" - } - ) - .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]\"}") - stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") - .with( - body: {"Body" => "It's been 60 days or more since you've reached out to these members of your youth's network:", "From" => "+15555555555", "To" => "+12222222222"}, - headers: { - "Accept" => "application/json", - "Accept-Charset" => "utf-8", - "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", - "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", - "Content-Type" => "application/x-www-form-urlencoded", - "User-Agent" => "twilio-ruby/5.67.1 (linux x86_64) Ruby/3.1.0" - } - ) - .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") - stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") - .with( - body: {"Body" => "test", "From" => "+15555555555", "To" => "+12222222222"}, - headers: { - "Accept" => "application/json", - "Accept-Charset" => "utf-8", - "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", - "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", - "Content-Type" => "application/x-www-form-urlencoded", - "User-Agent" => "twilio-ruby/5.67.1 (linux x86_64) Ruby/3.1.0" - } - ) - .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"test\"}") - stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") - .with( - body: {"Body" => "If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]", "From" => "+15555555555", "To" => "+12222222222"}, - headers: { - "Accept" => "application/json", - "Accept-Charset" => "utf-8", - "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", "Content-Type" => "application/x-www-form-urlencoded", - "User-Agent" => "twilio-ruby/5.67.1 (linux x86_64) Ruby/3.1.0" } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]\"}") From 0c59ac1ccf34f25c55ffb13e59fb85880e3db45c Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 29 May 2022 17:05:59 -0700 Subject: [PATCH 09/24] fix linting issues --- spec/support/webmock_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index 85b8fcbc63..46c5d27ff4 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -29,7 +29,7 @@ def stubbed_requests "Accept" => "application/json", "Accept-Charset" => "utf-8", "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", - "Content-Type" => "application/x-www-form-urlencoded", + "Content-Type" => "application/x-www-form-urlencoded" } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") @@ -40,7 +40,7 @@ def stubbed_requests "Accept" => "application/json", "Accept-Charset" => "utf-8", "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", - "Content-Type" => "application/x-www-form-urlencoded", + "Content-Type" => "application/x-www-form-urlencoded" } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"test\"}") @@ -51,7 +51,7 @@ def stubbed_requests "Accept" => "application/json", "Accept-Charset" => "utf-8", "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", - "Content-Type" => "application/x-www-form-urlencoded", + "Content-Type" => "application/x-www-form-urlencoded" } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]\"}") From 515b5662263a44c5edb27ca2e67dbe96003d9b4a Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 5 Jun 2022 17:00:41 -0700 Subject: [PATCH 10/24] add short link of production url in third message --- lib/tasks/case_contact_types_reminder.rb | 23 +++++--- .../tasks/case_contact_types_reminder_spec.rb | 4 +- spec/support/webmock_helper.rb | 57 ++++++++++++------- 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index 4a5e44c5d5..8073d4b8b6 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -1,6 +1,9 @@ class CaseContactTypesReminder - FIRST_MESSAGE = "It's been 60 days or more since you've reached out to these members of your youth's network:" - THIRD_MESSAGE = "If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]" + include Rails.application.routes.url_helpers + + NEW_CASE_CONTACT_PAGE_PATH = "https://casavolunteertracking.org/case_contacts/new" + FIRST_MESSAGE = "It's been 60 days or more since you've reached out to these members of your youth's network:\n" + THIRD_MESSAGE = "If you have made contact with them in the past 60 days, remember to log it: " def send! responses = [] @@ -45,14 +48,14 @@ def send_sms_messages(volunteer, uncontacted_case_contact_type_names) } messages = [ - [FIRST_MESSAGE], - [uncontacted_case_contact_type_names], - [THIRD_MESSAGE] + FIRST_MESSAGE, + uncontacted_case_contact_type_names.map{ |name| "• #{name}" }.join("\n"), + THIRD_MESSAGE + new_case_contact_page_short_link ] responses = [] - messages.each do |contents| - sms_params[:Body] = contents.join("\n") + messages.each do |content| + sms_params[:Body] = content responses.push(twilio_service.send_sms(sms_params)) end @@ -84,4 +87,10 @@ def update_reminder_sent_time(volunteer) reminder.save end + + def new_case_contact_page_short_link + short_url_service = ShortUrlService.new("42ni.short.gy", "1337") + short_url_service.create_short_url(NEW_CASE_CONTACT_PAGE_PATH) + short_url_service.short_url + end end diff --git a/spec/lib/tasks/case_contact_types_reminder_spec.rb b/spec/lib/tasks/case_contact_types_reminder_spec.rb index 5aae3e295b..ba550cbb96 100644 --- a/spec/lib/tasks/case_contact_types_reminder_spec.rb +++ b/spec/lib/tasks/case_contact_types_reminder_spec.rb @@ -41,7 +41,7 @@ expect(responses.count).to match 1 expect(responses[0][:messages][0].body).to match CaseContactTypesReminder::FIRST_MESSAGE expect(responses[0][:messages][1].body).to match contact_type.name - expect(responses[0][:messages][2].body).to match CaseContactTypesReminder::THIRD_MESSAGE + expect(responses[0][:messages][2].body).to match CaseContactTypesReminder::THIRD_MESSAGE + "https://42ni.short.gy/jzTwdF" end end @@ -80,7 +80,7 @@ expect(responses.count).to match 1 expect(responses[0][:messages][0].body).to match CaseContactTypesReminder::FIRST_MESSAGE expect(responses[0][:messages][1].body).to match contact_type.name - expect(responses[0][:messages][2].body).to match CaseContactTypesReminder::THIRD_MESSAGE + expect(responses[0][:messages][2].body).to match CaseContactTypesReminder::THIRD_MESSAGE + "https://42ni.short.gy/jzTwdF" end end diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index 46c5d27ff4..9890ba9862 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -1,16 +1,7 @@ def stubbed_requests - # twilio_service_spec - stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") - .with( - body: {From: "+15555555555", Body: "Execute Order 66 - https://42ni.short.gy/jzTwdF", To: "+12222222222"}, - headers: { - "Content-Type" => "application/x-www-form-urlencoded", - "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" - } - ) - .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"Execute Order 66 - https://42ni.short.gy/jzTwdF\"}") + # Short IO stub_request(:post, "https://api.short.io/links") - .with( + .with( body: {originalURL: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", domain: "42ni.short.gy"}.to_json, headers: { "Accept" => "application/json", @@ -21,21 +12,31 @@ def stubbed_requests } ) .to_return(status: 200, body: "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}", headers: {}) - # case_contact_types_reminder_spec + stub_request(:post, "https://api.short.io/links"). + with( + body: "{\"originalURL\":\"https://casavolunteertracking.org/case_contacts/new\",\"domain\":\"42ni.short.gy\"}", + headers: { + 'Accept'=>'application/json', + 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization'=>'1337', + 'Content-Type'=>'application/json', + 'User-Agent'=>'Ruby' + }). + to_return(status: 200, body: "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}", headers: {}) + + # Twilio Service stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") .with( - body: {"Body" => "It's been 60 days or more since you've reached out to these members of your youth's network:", "From" => "+15555555555", "To" => "+12222222222"}, + body: {From: "+15555555555", Body: "Execute Order 66 - https://42ni.short.gy/jzTwdF", To: "+12222222222"}, headers: { - "Accept" => "application/json", - "Accept-Charset" => "utf-8", - "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", - "Content-Type" => "application/x-www-form-urlencoded" + "Content-Type" => "application/x-www-form-urlencoded", + "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" } ) - .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\"}") + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"Execute Order 66 - https://42ni.short.gy/jzTwdF\"}") stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") .with( - body: {"Body" => "test", "From" => "+15555555555", "To" => "+12222222222"}, + body: {"Body" => "It's been 60 days or more since you've reached out to these members of your youth's network:\n", "From" => "+15555555555", "To" => "+12222222222"}, headers: { "Accept" => "application/json", "Accept-Charset" => "utf-8", @@ -43,10 +44,10 @@ def stubbed_requests "Content-Type" => "application/x-www-form-urlencoded" } ) - .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"test\"}") + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"It's been 60 days or more since you've reached out to these members of your youth's network:\\n\"}") stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") .with( - body: {"Body" => "If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]", "From" => "+15555555555", "To" => "+12222222222"}, + body: {"Body" => "• test", "From" => "+15555555555", "To" => "+12222222222"}, headers: { "Accept" => "application/json", "Accept-Charset" => "utf-8", @@ -54,5 +55,17 @@ def stubbed_requests "Content-Type" => "application/x-www-form-urlencoded" } ) - .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: [link to create new case contact for assigned case]\"}") + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"• test\"}") + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). + with( + body: {"Body"=>"If you have made contact with them in the past 60 days, remember to log it: https://42ni.short.gy/jzTwdF", "From"=>"+15555555555", "To"=>"+12222222222"}, + headers: { + 'Accept'=>'application/json', + 'Accept-Charset'=>'utf-8', + 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', + 'Content-Type'=>'application/x-www-form-urlencoded', + 'User-Agent'=>'twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0' + }). + to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: https://42ni.short.gy/jzTwdF\"}") end From f05a3d0bcb948de219b276a410f81bf8783a3f80 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 5 Jun 2022 21:59:35 -0700 Subject: [PATCH 11/24] fix linting issues --- lib/tasks/case_contact_types_reminder.rb | 2 +- spec/support/webmock_helper.rb | 48 ++++++++++++------------ 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index 8073d4b8b6..011e236af7 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -49,7 +49,7 @@ def send_sms_messages(volunteer, uncontacted_case_contact_type_names) messages = [ FIRST_MESSAGE, - uncontacted_case_contact_type_names.map{ |name| "• #{name}" }.join("\n"), + uncontacted_case_contact_type_names.map { |name| "• #{name}" }.join("\n"), THIRD_MESSAGE + new_case_contact_page_short_link ] diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index 9890ba9862..6a0cd3a01c 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -1,7 +1,7 @@ def stubbed_requests # Short IO stub_request(:post, "https://api.short.io/links") - .with( + .with( body: {originalURL: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", domain: "42ni.short.gy"}.to_json, headers: { "Accept" => "application/json", @@ -12,18 +12,19 @@ def stubbed_requests } ) .to_return(status: 200, body: "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}", headers: {}) - stub_request(:post, "https://api.short.io/links"). - with( + stub_request(:post, "https://api.short.io/links") + .with( body: "{\"originalURL\":\"https://casavolunteertracking.org/case_contacts/new\",\"domain\":\"42ni.short.gy\"}", headers: { - 'Accept'=>'application/json', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Authorization'=>'1337', - 'Content-Type'=>'application/json', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}", headers: {}) - + "Accept" => "application/json", + "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", + "Authorization" => "1337", + "Content-Type" => "application/json", + "User-Agent" => "Ruby" + } + ) + .to_return(status: 200, body: "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}", headers: {}) + # Twilio Service stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") .with( @@ -56,16 +57,17 @@ def stubbed_requests } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"• test\"}") - stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json"). - with( - body: {"Body"=>"If you have made contact with them in the past 60 days, remember to log it: https://42ni.short.gy/jzTwdF", "From"=>"+15555555555", "To"=>"+12222222222"}, - headers: { - 'Accept'=>'application/json', - 'Accept-Charset'=>'utf-8', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Authorization'=>'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==', - 'Content-Type'=>'application/x-www-form-urlencoded', - 'User-Agent'=>'twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0' - }). - to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: https://42ni.short.gy/jzTwdF\"}") + stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/articuno34/Messages.json") + .with( + body: {"Body" => "If you have made contact with them in the past 60 days, remember to log it: https://42ni.short.gy/jzTwdF", "From" => "+15555555555", "To" => "+12222222222"}, + headers: { + "Accept" => "application/json", + "Accept-Charset" => "utf-8", + "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", + "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", + "Content-Type" => "application/x-www-form-urlencoded", + "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" + } + ) + .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: https://42ni.short.gy/jzTwdF\"}") end From 1332a7d6c687d55373bf951a658339d91896364f Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 5 Jun 2022 22:15:21 -0700 Subject: [PATCH 12/24] fix webmock stub --- spec/support/webmock_helper.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index 6a0cd3a01c..f23f327772 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -63,10 +63,8 @@ def stubbed_requests headers: { "Accept" => "application/json", "Accept-Charset" => "utf-8", - "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", "Content-Type" => "application/x-www-form-urlencoded", - "User-Agent" => "twilio-ruby/5.67.1 (darwin21 x86_64) Ruby/3.1.0" } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: https://42ni.short.gy/jzTwdF\"}") From 90028c5baf125641dc86fb0137d0764a0c89affb Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 5 Jun 2022 22:18:32 -0700 Subject: [PATCH 13/24] fix linting issues --- spec/support/webmock_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index f23f327772..cd2876d772 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -64,7 +64,7 @@ def stubbed_requests "Accept" => "application/json", "Accept-Charset" => "utf-8", "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", - "Content-Type" => "application/x-www-form-urlencoded", + "Content-Type" => "application/x-www-form-urlencoded" } ) .to_return(body: "{\"error_code\":null, \"status\":\"sent\", \"body\":\"If you have made contact with them in the past 60 days, remember to log it: https://42ni.short.gy/jzTwdF\"}") From 6abded83b2b51d15a4a3234e8eedf2e9efc5f793 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Mon, 6 Jun 2022 21:30:53 -0700 Subject: [PATCH 14/24] add test to UserCaseContactTypesReminder spec --- spec/models/user_case_contact_types_reminder_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/user_case_contact_types_reminder_spec.rb b/spec/models/user_case_contact_types_reminder_spec.rb index 15fc5ef8d2..63eff73a3c 100644 --- a/spec/models/user_case_contact_types_reminder_spec.rb +++ b/spec/models/user_case_contact_types_reminder_spec.rb @@ -1,5 +1,5 @@ require "rails_helper" RSpec.describe UserCaseContactTypesReminder, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + it { is_expected.to belong_to(:user) } end From e189f569948d9c8f6b64eb6dc1e870b789af49f9 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sat, 11 Jun 2022 09:52:39 -0700 Subject: [PATCH 15/24] run case contact types reminder logic every week --- lib/tasks/send_case_contact_types_reminder.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/send_case_contact_types_reminder.rake b/lib/tasks/send_case_contact_types_reminder.rake index 93672dad51..9f9ec15d3e 100644 --- a/lib/tasks/send_case_contact_types_reminder.rake +++ b/lib/tasks/send_case_contact_types_reminder.rake @@ -1,7 +1,7 @@ desc "Send an SMS to volunteers reminding them to connect with the contact types they have not connected with in the past 60 or more days" require_relative "./case_contact_types_reminder" task send_case_contact_types_reminder: :environment do - every 1.days do # TODO: figure out how often we should run this + every 1.weeks do CaseContactTypesReminder.new.send! end end From a961098eb91e3669273305064ddb4f4e65d4ef95 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sat, 11 Jun 2022 09:54:22 -0700 Subject: [PATCH 16/24] use google home page as test url for short io service --- spec/services/short_url_service_spec.rb | 2 +- spec/support/webmock_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/services/short_url_service_spec.rb b/spec/services/short_url_service_spec.rb index 99fa5eda66..7549ddbf09 100644 --- a/spec/services/short_url_service_spec.rb +++ b/spec/services/short_url_service_spec.rb @@ -6,7 +6,7 @@ before :each do stubbed_requests WebMock.disable_net_connect! - @original_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" + @original_url = "https://www.google.com/" @short_domain = "42ni.short.gy" @notification_object = ShortUrlService.new(@short_domain, "1337") end diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index cd2876d772..b7a5cf755e 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -2,7 +2,7 @@ def stubbed_requests # Short IO stub_request(:post, "https://api.short.io/links") .with( - body: {originalURL: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", domain: "42ni.short.gy"}.to_json, + body: {originalURL: "https://www.google.com/", domain: "42ni.short.gy"}.to_json, headers: { "Accept" => "application/json", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", From 5c1e058b71a03e0aee1a633d304be4b016e6088f Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sat, 11 Jun 2022 10:14:29 -0700 Subject: [PATCH 17/24] fix twilio service spec url --- spec/services/twilio_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/twilio_service_spec.rb b/spec/services/twilio_service_spec.rb index c13a8e717b..9614786227 100644 --- a/spec/services/twilio_service_spec.rb +++ b/spec/services/twilio_service_spec.rb @@ -15,7 +15,7 @@ end it "can send a SMS with a short url successfully" do - @short_url.create_short_url("https://www.youtube.com/watch?v=dQw4w9WgXcQ") + @short_url.create_short_url("https://www.google.com/") params = { From: "+15555555555", Body: "Execute Order 66 - ", From b7de75f5a92a1eda38dbf8976fa23ee965c8c9fb Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sat, 11 Jun 2022 10:50:40 -0700 Subject: [PATCH 18/24] store short io env variables --- app/services/short_url_service.rb | 18 +++++++++++++++--- config/credentials/development.yml.enc | 2 +- config/credentials/test.yml.enc | 2 +- lib/tasks/case_contact_types_reminder.rb | 2 +- spec/services/short_url_service_spec.rb | 6 +++--- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/services/short_url_service.rb b/app/services/short_url_service.rb index 1ac3634079..bc2be84cbf 100644 --- a/app/services/short_url_service.rb +++ b/app/services/short_url_service.rb @@ -8,9 +8,10 @@ class ShortUrlService headers RequestHeader::ACCEPT_JSON headers RequestHeader::CONTENT_TYPE_JSON - def initialize(short_domain = nil, api_key = nil) - @short_domain = short_domain - @short_api_key = api_key + def initialize + validate_credentials + @short_domain = Rails.application.credentials[:SHORT_IO_DOMAIN] + @short_api_key = Rails.application.credentials[:SHORT_IO_API_KEY] @short_url = nil end @@ -23,4 +24,15 @@ def create_short_url(original_url = nil) @short_url = JSON.parse(response.body)["shortURL"] response end + + private + + def validate_credentials + variables = [Rails.application.credentials[:SHORT_IO_DOMAIN], Rails.application.credentials[:SHORT_IO_API_KEY]] + variables.each do |var| + if var.blank? + raise "#{var} environment variable missing for Short IO serivce" + end + end + end end diff --git a/config/credentials/development.yml.enc b/config/credentials/development.yml.enc index e322b59642..14356d0386 100644 --- a/config/credentials/development.yml.enc +++ b/config/credentials/development.yml.enc @@ -1 +1 @@ -1Oa+HbXh12bAr8uQOAThcsDm9IZ+6QkW7XDQyKEehHicQ6r0Ujf6teoeEsoJeHqnbZCCuO1nTzlQxsFoGKTCm4pKzbMmuueq1lRAzADomODCzzJ5OPTGy0lZc9LD61PLp8YmKufNPIfoJTX1b6OhKgArVR320mH3D2HBKZ677cZvoFPcbPQujnbhlURXaZFtTi8gjOmFvgqNa+EMOz1voUUWDyFeImzwjC6fGe2/KEQQX/5e1P0wyqgjET4S--MdZnjuArDnv8aXVt--hrZS+Llnb4VJoqmuCS06og== \ No newline at end of file +O0/O8rADiEq2Kb+AJFeK98MpGEr2cYuJhYjb5kdSek9J35K3cbILdE8dWADF6/sWnD+ddBFi+UIItuS/hziHVDktA9J0L52cFM8WjvW5J9DuZwYvkXrRK0w2AydSVp5fyTnVQmgpcKkW6mJG2B3EUleKC8P0XcV66EtJ6AlJVvjUoO6Cgu++yhGLBuA2fQO6SWmQtVLJ7xcIoZI4a9Tj7yxWoHZAozyASyqhE8PFd2uu+8md7nE++G4XCwdPuyMxcXPmkwTrCG2nzRvUhGtpxgDVJ4qTXUCgFsBXG+p459FfunEg8YnyKAghSgz7UXWBH1PId6Ac--fE8GMLkZSmjb/eY3--RugLs0qvrV9nBa/WpuxbxA== \ No newline at end of file diff --git a/config/credentials/test.yml.enc b/config/credentials/test.yml.enc index 4d01e24fbc..cfaf7e0255 100644 --- a/config/credentials/test.yml.enc +++ b/config/credentials/test.yml.enc @@ -1 +1 @@ -lsnR22as6mTVDa2pPJo+EjZ+OYq92HViKKhnKj1GwMWspKIJTkndzJ3xJYVkGJbrY2tAmHr+VXNauNaDukCsovBhHry9TN2Ngr4SzCU2x+hpzMgqBHt4mdIrAZWVTr+paA1hr/rS8k7ZGnK/uUx7ifboyMwHCX2tVV+m7ZHkBciHIFaZs2rwJDB4fsI9tKk/9DkXOmELV3VuRmw6eUnFyW84gjj2vQ18mczrNx6Sbq6zakhassqcXTgJRgey--KkLl5vLri+smsHTB--By5/dkptNeOUBKDJyAfRYA== \ No newline at end of file +BN0TmzUV3EAIoB+oJxyL9ZP/u+Na3qaLFNxCZj3lQfM1fTzQTVKAFDBG5SHTAxhAbXrGVJMnLxVZRagICl8l294EJDcM0zEUUXVIac0BOCOfEXvu5igRN7uGa5w6wsTZzUNGZetHKAdpnhIb9ahHGV/sBpA0lXEQNwPSCREtkLKNJvgabIflxscoEND6mB/WQ7XCBnxWhCqewjUvHMNHGeJENcPMTLoHW2nljAPNRxzaFX3FVcXvN6slqEaNSgfJJpbbS2p/biNvrgs+N28vqKVtTqHMhPxYYFDya+hIzu5lqYluqwaztDLRnCJvKnSGo3TnyWXP--gjZGndWNysMJpQlS--SGdeyjH3b9SOuTQ3M6pwFg== \ No newline at end of file diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index 011e236af7..53551a1d12 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -89,7 +89,7 @@ def update_reminder_sent_time(volunteer) end def new_case_contact_page_short_link - short_url_service = ShortUrlService.new("42ni.short.gy", "1337") + short_url_service = ShortUrlService.new short_url_service.create_short_url(NEW_CASE_CONTACT_PAGE_PATH) short_url_service.short_url end diff --git a/spec/services/short_url_service_spec.rb b/spec/services/short_url_service_spec.rb index 7549ddbf09..23c8fbdd37 100644 --- a/spec/services/short_url_service_spec.rb +++ b/spec/services/short_url_service_spec.rb @@ -7,14 +7,14 @@ stubbed_requests WebMock.disable_net_connect! @original_url = "https://www.google.com/" - @short_domain = "42ni.short.gy" - @notification_object = ShortUrlService.new(@short_domain, "1337") + @notification_object = ShortUrlService.new + @short_io_domain = Rails.application.credentials[:SHORT_IO_DOMAIN] end it "returns a successful response with correct http request" do response = @notification_object.create_short_url(@original_url) expect(a_request(:post, "https://api.short.io/links") - .with(body: {originalURL: @original_url, domain: @short_domain}.to_json, headers: {"Accept" => "application/json", "Content-Type" => "application/json", "Authorization" => "1337"})) + .with(body: {originalURL: @original_url, domain: @short_io_domain}.to_json, headers: {"Accept" => "application/json", "Content-Type" => "application/json", "Authorization" => "1337"})) .to have_been_made.once expect(response.code).to match 200 expect(response.body).to match "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}" From 2fa774567b9d5ada6318cfe55ec2b778d9c470ea Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sat, 11 Jun 2022 11:15:13 -0700 Subject: [PATCH 19/24] clean up short io service spec --- spec/services/short_url_service_spec.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spec/services/short_url_service_spec.rb b/spec/services/short_url_service_spec.rb index 23c8fbdd37..769d477e2c 100644 --- a/spec/services/short_url_service_spec.rb +++ b/spec/services/short_url_service_spec.rb @@ -2,27 +2,28 @@ require "support/webmock_helper" RSpec.describe ShortUrlService do + let!(:original_url) { "https://www.google.com/" } + let(:notification_object) { ShortUrlService.new } + let(:short_io_domain) { Rails.application.credentials[:SHORT_IO_DOMAIN] } + describe "short.io API" do before :each do stubbed_requests WebMock.disable_net_connect! - @original_url = "https://www.google.com/" - @notification_object = ShortUrlService.new - @short_io_domain = Rails.application.credentials[:SHORT_IO_DOMAIN] end it "returns a successful response with correct http request" do - response = @notification_object.create_short_url(@original_url) + response = notification_object.create_short_url(original_url) expect(a_request(:post, "https://api.short.io/links") - .with(body: {originalURL: @original_url, domain: @short_io_domain}.to_json, headers: {"Accept" => "application/json", "Content-Type" => "application/json", "Authorization" => "1337"})) + .with(body: {originalURL: original_url, domain: short_io_domain}.to_json, headers: {"Accept" => "application/json", "Content-Type" => "application/json", "Authorization" => "1337"})) .to have_been_made.once expect(response.code).to match 200 expect(response.body).to match "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}" end it "returns a short url" do - @notification_object.create_short_url(@original_url) - short_url = @notification_object.short_url + notification_object.create_short_url(original_url) + short_url = notification_object.short_url expect(short_url).to be_an_instance_of(String) expect(short_url).to match "https://42ni.short.gy/jzTwdF" end From 41de22cd43c9458f0c9932523e9120cfc47b64f5 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sat, 11 Jun 2022 11:15:47 -0700 Subject: [PATCH 20/24] disable creation of short url service for each test --- spec/services/short_url_service_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/services/short_url_service_spec.rb b/spec/services/short_url_service_spec.rb index 769d477e2c..8284982869 100644 --- a/spec/services/short_url_service_spec.rb +++ b/spec/services/short_url_service_spec.rb @@ -3,8 +3,8 @@ RSpec.describe ShortUrlService do let!(:original_url) { "https://www.google.com/" } - let(:notification_object) { ShortUrlService.new } - let(:short_io_domain) { Rails.application.credentials[:SHORT_IO_DOMAIN] } + let!(:notification_object) { ShortUrlService.new } + let!(:short_io_domain) { Rails.application.credentials[:SHORT_IO_DOMAIN] } describe "short.io API" do before :each do From fa328dbe23b3d0a2b3ef3ff5d410f29b469d5293 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sat, 11 Jun 2022 21:27:00 -0700 Subject: [PATCH 21/24] fix twilio service spec as short url service no longer uses arguments --- spec/services/twilio_service_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/services/twilio_service_spec.rb b/spec/services/twilio_service_spec.rb index 9614786227..50a689ef8f 100644 --- a/spec/services/twilio_service_spec.rb +++ b/spec/services/twilio_service_spec.rb @@ -4,13 +4,13 @@ RSpec.describe TwilioService do describe "twilio API" do context "SMS messaging" do - before :each do + before :all do stubbed_requests WebMock.disable_net_connect! @acc_sid = "articuno34" @api_key = "Aladdin" @api_secret = "open sesame" - @short_url = ShortUrlService.new("42ni.short.gy", "1337") + @short_url = ShortUrlService.new @twilio = TwilioService.new(@api_key, @api_secret, @acc_sid) end From fa5fbfe2950e5bf4efd39f34c571c93c00a0e386 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 12 Jun 2022 10:15:43 -0700 Subject: [PATCH 22/24] use dynamic base url through environment variables --- config/credentials/development.yml.enc | 2 +- config/credentials/production.yml.enc | 2 +- config/credentials/test.yml.enc | 2 +- lib/tasks/case_contact_types_reminder.rb | 7 +++++-- spec/support/webmock_helper.rb | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config/credentials/development.yml.enc b/config/credentials/development.yml.enc index 14356d0386..4c0cc7ab67 100644 --- a/config/credentials/development.yml.enc +++ b/config/credentials/development.yml.enc @@ -1 +1 @@ -O0/O8rADiEq2Kb+AJFeK98MpGEr2cYuJhYjb5kdSek9J35K3cbILdE8dWADF6/sWnD+ddBFi+UIItuS/hziHVDktA9J0L52cFM8WjvW5J9DuZwYvkXrRK0w2AydSVp5fyTnVQmgpcKkW6mJG2B3EUleKC8P0XcV66EtJ6AlJVvjUoO6Cgu++yhGLBuA2fQO6SWmQtVLJ7xcIoZI4a9Tj7yxWoHZAozyASyqhE8PFd2uu+8md7nE++G4XCwdPuyMxcXPmkwTrCG2nzRvUhGtpxgDVJ4qTXUCgFsBXG+p459FfunEg8YnyKAghSgz7UXWBH1PId6Ac--fE8GMLkZSmjb/eY3--RugLs0qvrV9nBa/WpuxbxA== \ No newline at end of file +svCtLWmi6TUWfy4jhsNxZgGKdzBrjq5JjKkGUaDA5tlP2XFn6XY8lJDVhF+T82kGjwT4EgsBheMZqPMbytlJ6iSDBIq/bHfjl1E5Zx3DqCkd4gDYgVK0roJffesKQPuWUSQUzvJV9pZ9VQEKbh+YA/I/N6aWGbkYlKXTOPHMY7F+rfiKXb8vHodUGWxCTycsWLpe/ohBvF7zzSwxkG7sEmbnRnqYd2Tmn0ASf6vNKXOzPamQ21rrgUss427/zjCjzWHCk4iUaHnhQQYwC2zJ+m1/0Uu+sM5CkYJhddsPbeeQkd7vgPjHBylgkT6L86XTz8sBrQDZB51TbmNouygu96NzQwE472c0csFEWwjz7fepy7sZkHN5KqQ=--dx6D/QqFOeacGYGg--+r3ffqcg8wONL9oMId9u5g== \ No newline at end of file diff --git a/config/credentials/production.yml.enc b/config/credentials/production.yml.enc index e34c37400e..e7e3d7ec79 100644 --- a/config/credentials/production.yml.enc +++ b/config/credentials/production.yml.enc @@ -1 +1 @@ -AxlCeUg6T11ONc/6YWPkWk+sJi5dMmJ0KhtVbxxZb+4s/CUFi5F3dLER1vqmyu9Zt+IDrwojE2gvm+Yw3ympbeg5km40o88QJRz76FZoRrvOPRsT76iYW9Fy2qXCUJyd04HNIbW2P2onAY4OtwVCQYf65EtazDh1B5BFJneEa/cIHs/QKFAqE9hxPA05Uvzc+O1F8xmg3v7Dp0cLvRl2JpSRTr0JDBktcWRsS4g+pnQwC2la22SVgg2RYgzerEU6BJKAs0wlf0VuytXdKNw92rfCl11pAZyh3/3Ocv2mY78sgpK3FOObXfpnPHAoNI1pLL1sJveM34L1s6tDAUSQ1rAe7fQO1qDtkooZ+Ak/IyHUUTvl62C5zFafnBmjrAUvHSr11l/LrSjkWlsV9KpFXBlKQYs4rJAsDPPr3AJ4YnmyZyxgrQYrB3jNRB1IENRD87t6pg6geFlbPbnTmmbMl2oW2HwllStgDFkOUgcGRBXgdDVv1YgR9aAIP2jZBhLD1jt3a+XxqsrJBRvdGMa3rtTGj4s8+FrVG0iLibvd/hoVlMldVEj6HTQYI2lIzTQ4cI/chw==--IinvJwfP8oNrT+d2--V47XslB/SUn6I78Fb4MUYg== \ No newline at end of file +Y85/mpXDwuasGg7odbPklWamaevc8nlJJExz5YTnGBR/S5wCGTkkH7hwUBPINNTkYXpe3N1QN2ILq+NuGqTJhgtpy6Glwnk743UlxsFUChUQmSlccJfML1YQWKx3R1VSAFWjOoHiV9vnA0RcKf9tIQ5FWY5S8/IMn4SlpRbhU0zJfkHAb3Hbx5juTWmOWHh4BD+AmKYqu9lpVCCwQkitRJX/8AwLUBprbcaHm0nh9u4PL/Q/Fj0/UadHF2RCWDnpRxUAygqgMpCBxqZwpHzN3cRrATL3aDYFZt0CZzpkpnHBKQcuSs1K/oki06Jas+Z585iO00S6r4NRJtkPVkznFqu0DJ8JkUKriLDXOwbvcEHOHtCS0t2hCxYLPZvSg51qBsZbgS5No3+cfXPeGjIecq+h1c7zpg70PNieO6290IM/jpNYA9ZEt9nPXwUodAauMkvcocXlOxX4mOaYsL7fMiXhgu/JzqwK64maSXpCBaEEPcOwIkaKhTwn+w+iABnTYnhZeD2t3TMoFpzkI83w7cg9Mbetm1N9faX43dsYXRW93tFwSkJtF4b//CIxOyG9xFxruGNwnBqy8+IuoaSyBVF3WecnWjj+7TGSgmgl7FmiaUSjDDJkh27K8QDHbpevQM/Rc5U=--8GtVk0JHu3Dkz4jI--/FAbx4kRZsAKWLg9/+IWbw== \ No newline at end of file diff --git a/config/credentials/test.yml.enc b/config/credentials/test.yml.enc index cfaf7e0255..51801db2a1 100644 --- a/config/credentials/test.yml.enc +++ b/config/credentials/test.yml.enc @@ -1 +1 @@ -BN0TmzUV3EAIoB+oJxyL9ZP/u+Na3qaLFNxCZj3lQfM1fTzQTVKAFDBG5SHTAxhAbXrGVJMnLxVZRagICl8l294EJDcM0zEUUXVIac0BOCOfEXvu5igRN7uGa5w6wsTZzUNGZetHKAdpnhIb9ahHGV/sBpA0lXEQNwPSCREtkLKNJvgabIflxscoEND6mB/WQ7XCBnxWhCqewjUvHMNHGeJENcPMTLoHW2nljAPNRxzaFX3FVcXvN6slqEaNSgfJJpbbS2p/biNvrgs+N28vqKVtTqHMhPxYYFDya+hIzu5lqYluqwaztDLRnCJvKnSGo3TnyWXP--gjZGndWNysMJpQlS--SGdeyjH3b9SOuTQ3M6pwFg== \ No newline at end of file +zsvjeQzFV0vM7h3jsx7RUyA3WTQsEYWvEMreEvVbi4L0HN7sDNrP7kay2FZS5VEwrW5mJZdnu63BXa8fK/h1agvaaiOO9FhDXfyK+VT86TAfsLa1gsBK9mHjWSdXCJE9TZj9OjOtR3R/qHOI+2uPUnysh7Om4a0ckiu4Jwex3OcbgCYj2+G2JQtwHkWhlyBthGxLjuDDFfx+qxkJWkN7V9FhN0FkkPaflyj4FjR9BUf3/CB8pvHXqJ1lmxVScYsyhh50mc+CKyVptpqbLi9Jou3SiUePREX03ynV0KPR+7mT3FH9gCj4QyzzS1t3JOUfrgqeVFAzdV1TW01olinOyG2aMrZn1aA7GWfDeIr/GwnaPfUMmZNj4RQ=--KmPWCR7xHr6jUSx5--1L2S0bUzD2Bc+JFAHX7xKg== \ No newline at end of file diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index 53551a1d12..0197427d62 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -1,11 +1,14 @@ class CaseContactTypesReminder include Rails.application.routes.url_helpers - NEW_CASE_CONTACT_PAGE_PATH = "https://casavolunteertracking.org/case_contacts/new" + NEW_CASE_CONTACT_PAGE_PATH = Rails.application.credentials[:BASE_URL] FIRST_MESSAGE = "It's been 60 days or more since you've reached out to these members of your youth's network:\n" THIRD_MESSAGE = "If you have made contact with them in the past 60 days, remember to log it: " def send! + if NEW_CASE_CONTACT_PAGE_PATH.blank? + raise "NEW_CASE_CONTACT_PAGE_PATH environment variable not defined" + end responses = [] eligible_volunteers = Volunteer.where(receive_sms_notifications: true) .where.not(phone_number: nil) @@ -90,7 +93,7 @@ def update_reminder_sent_time(volunteer) def new_case_contact_page_short_link short_url_service = ShortUrlService.new - short_url_service.create_short_url(NEW_CASE_CONTACT_PAGE_PATH) + short_url_service.create_short_url(NEW_CASE_CONTACT_PAGE_PATH + "/case_contacts/new") short_url_service.short_url end end diff --git a/spec/support/webmock_helper.rb b/spec/support/webmock_helper.rb index b7a5cf755e..cbf27457b8 100644 --- a/spec/support/webmock_helper.rb +++ b/spec/support/webmock_helper.rb @@ -14,7 +14,7 @@ def stubbed_requests .to_return(status: 200, body: "{\"shortURL\":\"https://42ni.short.gy/jzTwdF\"}", headers: {}) stub_request(:post, "https://api.short.io/links") .with( - body: "{\"originalURL\":\"https://casavolunteertracking.org/case_contacts/new\",\"domain\":\"42ni.short.gy\"}", + body: "{\"originalURL\":\"#{Rails.application.credentials[:BASE_URL]}/case_contacts/new\",\"domain\":\"42ni.short.gy\"}", headers: { "Accept" => "application/json", "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", From 0aa6b5ad1e690ab17cbe54c6499c467fc6165e84 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 12 Jun 2022 10:18:53 -0700 Subject: [PATCH 23/24] fix linting issues --- lib/tasks/case_contact_types_reminder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index 0197427d62..eb32eafc5d 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -1,13 +1,13 @@ class CaseContactTypesReminder include Rails.application.routes.url_helpers - NEW_CASE_CONTACT_PAGE_PATH = Rails.application.credentials[:BASE_URL] + NEW_CASE_CONTACT_PAGE_PATH = Rails.application.credentials[:BASE_URL] FIRST_MESSAGE = "It's been 60 days or more since you've reached out to these members of your youth's network:\n" THIRD_MESSAGE = "If you have made contact with them in the past 60 days, remember to log it: " def send! if NEW_CASE_CONTACT_PAGE_PATH.blank? - raise "NEW_CASE_CONTACT_PAGE_PATH environment variable not defined" + raise "NEW_CASE_CONTACT_PAGE_PATH environment variable not defined" end responses = [] eligible_volunteers = Volunteer.where(receive_sms_notifications: true) From ea62122b007cc4dd4ed53d024d41eb22d021ded5 Mon Sep 17 00:00:00 2001 From: Harsohail Brar Date: Sun, 12 Jun 2022 23:00:31 -0700 Subject: [PATCH 24/24] remove unneeded include --- lib/tasks/case_contact_types_reminder.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/tasks/case_contact_types_reminder.rb b/lib/tasks/case_contact_types_reminder.rb index eb32eafc5d..1f9fb7e97f 100644 --- a/lib/tasks/case_contact_types_reminder.rb +++ b/lib/tasks/case_contact_types_reminder.rb @@ -1,6 +1,4 @@ class CaseContactTypesReminder - include Rails.application.routes.url_helpers - NEW_CASE_CONTACT_PAGE_PATH = Rails.application.credentials[:BASE_URL] FIRST_MESSAGE = "It's been 60 days or more since you've reached out to these members of your youth's network:\n" THIRD_MESSAGE = "If you have made contact with them in the past 60 days, remember to log it: "