Skip to content

Commit

Permalink
Don't send bad link in welcome message
Browse files Browse the repository at this point in the history
  • Loading branch information
cdccollins committed Oct 18, 2024
1 parent bc191a5 commit f772939
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
18 changes: 13 additions & 5 deletions app/jobs/send_welcome_message_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ class SendWelcomeMessageJob < ApplicationJob
}

def perform(user)
message = Message.create do |m|
m.token = m.send(:generate_token)
m.link = WELCOME_VIDEOS[user.child_age_in_months_today]
m.user = user
m.body = "Welcome to our programme of weekly texts with fun activities! Here's a video to get you started: #{track_link_url(m.token)}"
message = if WELCOME_VIDEOS[user.child_age_in_months_today]
Message.create do |m|
m.token = m.send(:generate_token)
m.link = WELCOME_VIDEOS[user.child_age_in_months_today]
m.user = user
m.body = "Welcome to Tiny Happy People, a programme of weekly texts with fun activities! Here's a video to get you started: #{track_link_url(m.token)}"
end
else
Message.create do |m|
m.token = m.send(:generate_token)
m.user = user
m.body = "Welcome to Tiny Happy People, a programme of weekly texts with fun activities! You'll receive your first activity soon."
end
end

Twilio::Client.new.send_message(message)
Expand Down
17 changes: 16 additions & 1 deletion test/jobs/send_welcome_message_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SendWelcomeMessageJobTest < ActiveSupport::TestCase

Message.any_instance.stubs(:generate_token).returns("123")

message = "Welcome to our programme of weekly texts with fun activities! Here's a video to get you started: #{track_link_url(123)}"
message = "Welcome to Tiny Happy People, a programme of weekly texts with fun activities! Here's a video to get you started: #{track_link_url(123)}"

stub_successful_twilio_call(message, user)

Expand All @@ -19,4 +19,19 @@ class SendWelcomeMessageJobTest < ActiveSupport::TestCase
assert_match(/m\/123/, Message.last.body)
assert_equal "https://www.bbc.co.uk/tiny-happy-people/shopping-game-18-24/zbhyf4j", Message.last.link
end

test "#perform sends message with no link if there isn't appropriate content" do
user = create(:user, child_birthday: 25.months.ago)

Message.any_instance.stubs(:generate_token).returns("123")

message = "Welcome to Tiny Happy People, a programme of weekly texts with fun activities! You'll receive your first activity soon."

stub_successful_twilio_call(message, user)

SendWelcomeMessageJob.new.perform(user)

assert_equal 1, Message.count
assert_nil Message.last.link
end
end
4 changes: 2 additions & 2 deletions test/system/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UsersTest < ApplicationSystemTestCase
check "I accept the terms of service and privacy policy"

Message.any_instance.stubs(:generate_token).returns("123")
message = "Welcome to our programme of weekly texts with fun activities! Here's a video to get you started: http://localhost:3000/m/123"
message = "Welcome to Tiny Happy People, a programme of weekly texts with fun activities! Here's a video to get you started: http://localhost:3000/m/123"
stub_successful_twilio_call(message, User.new(phone_number: "+447444930200"))

within("#sign-up-form") do
Expand All @@ -36,7 +36,7 @@ class UsersTest < ApplicationSystemTestCase
assert_text "ABC123"
assert_text "Does have family support"
assert_text "On Slack"
assert_text "Welcome to our programme of weekly texts with fun activities!"
assert_text "Welcome to Tiny Happy People, a programme of weekly texts with fun activities!"
end

test "form shows errors" do
Expand Down

0 comments on commit f772939

Please sign in to comment.