Skip to content

Commit

Permalink
Merge pull request #532 from crossroads/master
Browse files Browse the repository at this point in the history
#JulyRelease3
  • Loading branch information
namrataukirde authored Jul 18, 2018
2 parents 9a97f0c + be10a14 commit dd5ec8f
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 10 deletions.
13 changes: 10 additions & 3 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def set_initial_state
if order.detail_type == "GoodCity"
order.designate_orders_packages
order.send_new_order_notificationen
order.send_new_order_sms
order.send_new_order_confirmed_sms_to_charity
order.send_order_placed_sms_to_order_fulfilment_users
end
end
end
Expand All @@ -213,8 +214,14 @@ def send_new_order_notificationen
}
end

def send_new_order_sms
TwilioService.new(submitted_by).send_new_order_sms(self)
def send_new_order_confirmed_sms_to_charity
TwilioService.new(submitted_by).order_confirmed_sms_to_charity(self)
end

def send_order_placed_sms_to_order_fulfilment_users
User.order_fulfilment.each do |user|
TwilioService.new(user).order_submitted_sms_to_order_fulfilment_users(self)
end
end

def nullify_columns(*columns)
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class User < ActiveRecord::Base
scope :donors, -> { where(permission_id: nil) }
scope :reviewers, -> { where(roles: { name: 'Reviewer' }).joins(:roles) }
scope :supervisors, -> { where(roles: { name: 'Supervisor' }).joins(:roles) }
scope :order_fulfilment, -> { where(roles: { name: 'Order fulfilment' }).joins(:roles) }
scope :system, -> { where(roles: { name: 'System' }).joins(:roles) }
scope :staff, -> { where(roles: { name: ['Supervisor', 'Reviewer'] }).joins(:roles) }
scope :except_stockit_user, -> { where.not(first_name: "Stockit", last_name: "User") }
Expand Down
19 changes: 15 additions & 4 deletions app/services/twilio_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ def send_welcome_msg
TwilioJob.perform_later(options)
end

def send_new_order_sms(order)
def order_confirmed_sms_to_charity(order)
return unless allowed_to_send?
options = { to: @user.mobile, body: new_order_text(order) }
options = { to: @user.mobile, body: new_order_confirmed_text_to_charity(order) }
TwilioJob.perform_later(options)
end

def order_submitted_sms_to_order_fulfilment_users(order)
return unless allowed_to_send?
options = { to: @user.mobile, body: new_order_placed_text_to_users(order) }
TwilioJob.perform_later(options)
end

Expand Down Expand Up @@ -57,8 +63,13 @@ def welcome_sms_text
full_name: User.current_user.full_name)
end

def new_order_text(order)
I18n.t('twilio.new_order_submitted_sms',
def new_order_placed_text_to_users(order)
I18n.t('twilio.order_submitted_sms_to_order_fulfilment_users',
code: order.code, submitter_name: order.submitted_by.full_name, organisation_name: order.organisation.try(:name_en))
end

def new_order_confirmed_text_to_charity(order)
I18n.t('twilio.new_order_submitted_sms_to_charity',
code: order.code)
end
end
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ en:
your quality goods. (If you didn't request this message, please ignore)
charity_user_welcome_sms: |
%{full_name} has added you to the GoodCity for Charities platform. Please download the app and log in using this mobile number.
new_order_submitted_sms: |
order_submitted_sms_to_order_fulfilment_users: |
%{submitter_name} from %{organisation_name} has just placed an order %{code} on GoodCity.
new_order_submitted_sms_to_charity: |
Thank you for placing order %{code} on GoodCity. Our team will be in touch with you soon.
input_offer_id_message: "Please input an offer ID and we will forward you to the donor's number."
thank_you_calling_message: "Thank you for calling GoodCity.HK, operated by Crossroads Foundation. Please wait a moment while we try to connect you to one of our staff."
Expand Down
4 changes: 3 additions & 1 deletion config/locales/zh-tw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ zh-tw:
(如你並沒有要求驗證碼,請忽略此信息)
charity_user_welcome_sms: |
%{full_name} 已將閣下登記於好人好巿平台。請下載該應用程式及以此電話號碼登入。
new_order_submitted_sms: |
order_submitted_sms_to_order_fulfilment_users: |
%{submitter_name} from %{organisation_name} has just placed an order %{code} on GoodCity.
new_order_submitted_sms_to_charity: |
Thank you for placing order %{code} on GoodCity. Our team will be in touch with you soon.
input_offer_id_message: "請輸入捐獻號碼,提取捐贈人士的號碼。"
thank_you_calling_message: "感謝致電十字路會主辦物資捐獻系統,好人好市。請稍候片刻,職員將儘快接聽你的電話。"
Expand Down
24 changes: 24 additions & 0 deletions spec/models/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,28 @@
end
end

describe '#send_new_order_confirmed_sms_to_charity' do
let(:charity) { create(:user, :charity) }
let(:order) { build(:order, submitted_by: charity) }
let(:twilio) { TwilioService.new(charity) }

it "send order submission sms to charity user who submitted order" do
expect(TwilioService).to receive(:new).with(charity).and_return(twilio)
expect(twilio).to receive(:order_confirmed_sms_to_charity).with(order)
order.send_new_order_confirmed_sms_to_charity
end
end

describe '#send_order_placed_sms_to_order_fulfilment_users' do
let(:charity) { create(:user, :charity) }
let(:order_1) { create(:order, submitted_by: charity) }
let(:order_fulfiment_user_1) { create(:user, :order_fulfilment) }
let(:twilio) { TwilioService.new(order_fulfiment_user_1) }

it "send new order submitted alert sms to order_fulfilment users" do
expect(TwilioService).to receive(:new).with(order_fulfiment_user_1).and_return(twilio)
expect(twilio).to receive(:order_submitted_sms_to_order_fulfilment_users).with(order_1)
order_1.send_order_placed_sms_to_order_fulfilment_users
end
end
end
24 changes: 23 additions & 1 deletion spec/services/twilio_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
end

context "new_offer_alert" do

let(:donor) { build(:user, first_name: "John", last_name: "Lowe") }
let(:offer) { build(:offer, created_by: donor) }

Expand All @@ -37,7 +36,30 @@
expect(TwilioJob).to receive(:perform_later).with(to: user.mobile, body: body)
twilio.new_offer_alert(offer)
end
end

context "order_confirmed_sms_to_charity" do
let(:charity) { build(:user, :charity) }
let(:order) { build(:order, created_by: charity) }

it "sends order submitted acknowledgement to charity who submitted order" do
allow(twilio).to receive(:allowed_to_send?).and_return(true)
body = "Thank you for placing order #{order.code} on GoodCity. Our team will be in touch with you soon.\n"
expect(TwilioJob).to receive(:perform_later).with(to: user.mobile, body: body)
twilio.order_confirmed_sms_to_charity(order)
end
end

context "order_submitted_sms_to_order_fulfilment_users" do
let(:order_fulfilment_user) { build(:user, :order_fulfilment) }
let(:charity) { build(:user, :charity) }
let(:order) { build(:order, created_by: charity, submitted_by: charity) }

it "sends order submitted alert to order_fulfilment_user" do
allow(twilio).to receive(:allowed_to_send?).and_return(true)
body = "#{charity.full_name} from #{order.organisation.name_en} has just placed an order #{order.code} on GoodCity.\n"
expect(TwilioJob).to receive(:perform_later).with(to: user.mobile, body: body)
twilio.order_submitted_sms_to_order_fulfilment_users(order)
end
end
end

0 comments on commit dd5ec8f

Please sign in to comment.