Add download_app Welcome Notification (#8067)

* Add download_broadcast to generator.rb
  * Adds memoized download_broadcast method
  * Adds send_download_notification method
  * Adds send_download_notification to call method

* Add download_app to broadcasts.rb and seeds.rb
  * Adds download_app broadcast info and copy to factory
  * Adds download_app copy to seeds

* Add specs around #send_download_app_notification in generator_spec.rb

* Fix quotes around copy

* Remove extra space within copy
This commit is contained in:
Julianna Tetreault 2020-05-27 08:14:47 -06:00 committed by GitHub
parent 7f75f99560
commit 6cf177c3e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 1 deletions

View file

@ -18,6 +18,7 @@ module Broadcasts
send_feed_customization_notification unless notification_enqueued
send_ux_customization_notification unless notification_enqueued
send_discuss_and_ask_notification unless notification_enqueued
send_download_app_notification unless notification_enqueued
rescue ActiveRecord::RecordNotFound => e
Honeybadger.notify(e)
end
@ -60,6 +61,13 @@ module Broadcasts
@notification_enqueued = true
end
def send_download_app_notification
return if received_notification?(download_app_broadcast) || user.created_at > 7.days.ago
Notification.send_welcome_notification(user.id, download_app_broadcast.id)
@notification_enqueued = true
end
def received_notification?(broadcast)
Notification.exists?(notifiable: broadcast, user: user)
end
@ -97,6 +105,10 @@ module Broadcasts
@discuss_and_ask_broadcast ||= find_discuss_ask_broadcast
end
def download_app_broadcast
@download_app_broadcast ||= Broadcast.active.find_by!(title: "Welcome Notification: download_app")
end
def identities
@identities ||= user.identities.where(provider: SiteConfig.authentication_providers)
end

View file

@ -244,7 +244,8 @@ broadcast_messages = {
customize_experience: "Sloan here! 👋 Did you know that that you can customize your DEV experience? Try changing <a href='settings/ux'>your font and theme</a> and find the best style for you!",
start_discussion: "Sloan here! 👋 I noticed that you haven't <a href='https://dev.to/t/discuss'>started a discussion</a> yet. Starting a discussion is easy to do; just click on 'Write a Post' in the sidebar of the tag page to get started!",
ask_question: "Sloan here! 👋 I noticed that you haven't <a href='https://dev.to/t/explainlikeimfive'>asked a question</a> yet. Asking a question is easy to do; just click on 'Write a Post' in the sidebar of the tag page to get started!",
discuss_and_ask: "Sloan here! 👋 I noticed that you haven't <a href='https://dev.to/t/explainlikeimfive'>asked a question</a> or <a href='https://dev.to/t/discuss'>started a discussion</a> yet. It's easy to do both of these; just click on 'Write a Post' in the sidebar of the tag page to get started!"
discuss_and_ask: "Sloan here! 👋 I noticed that you haven't <a href='https://dev.to/t/explainlikeimfive'>asked a question</a> or <a href='https://dev.to/t/discuss'>started a discussion</a> yet. It's easy to do both of these; just click on 'Write a Post' in the sidebar of the tag page to get started!",
download_app: "Sloan here, with one last tip! 👋 Have you downloaded the DEV mobile app yet? Consider <a href='https://dev.to/downloads'>downloading</a> it so you can access all of your favorite DEV content on the go!"
}
broadcast_messages.each do |type, message|

View file

@ -55,5 +55,11 @@ FactoryBot.define do
type_of { "Welcome" }
processed_html { "Sloan here! 👋 I noticed that you haven't <a href='https://dev.to/t/explainlikeimfive'>asked a question</a> or <a href='https://dev.to/t/discuss'>started a discussion</a> yet. It's easy to do both of these; just click on 'Write a Post' in the sidebar of the tag page to get started!" }
end
factory :download_app_broadcast do
title { "Welcome Notification: download_app" }
type_of { "Welcome" }
processed_html { "Sloan here, with one last tip! 👋 Have you downloaded the DEV mobile app yet? Consider <a href='https://dev.to/downloads'>downloading</a> it so you can access all of your favorite DEV content on the go!" }
end
end
end

View file

@ -11,6 +11,7 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
let_it_be_readonly(:customize_feed_broadcast) { create(:customize_feed_broadcast) }
let_it_be_readonly(:discuss_and_ask_broadcast) { create(:discuss_and_ask_broadcast) }
let_it_be_readonly(:customize_ux_broadcast) { create(:customize_ux_broadcast) }
let_it_be_readonly(:download_app_broadcast) { create(:download_app_broadcast) }
before do
omniauth_mock_providers_payload
@ -67,6 +68,10 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
Timecop.travel(1.day.since)
expect { sidekiq_perform_enqueued_jobs { described_class.call(user.id) } }.to change(user.notifications, :count).by(1)
expect(user.notifications.last.notifiable).to eq(discuss_and_ask_broadcast)
Timecop.travel(1.day.since)
expect { sidekiq_perform_enqueued_jobs { described_class.call(user.id) } }.to change(user.notifications, :count).by(1)
expect(user.notifications.last.notifiable).to eq(download_app_broadcast)
Timecop.return
end
# rubocop:enable RSpec/ExampleLength
@ -252,5 +257,28 @@ RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
end
expect(user.notifications.count).to eq(1)
end
describe "#send_download_app_notification" do
let!(:user) { create(:user, :with_identity, identities: %w[twitter github], created_at: 7.days.ago) }
it "does not send a notification to a newly-created user" do
user.update!(created_at: Time.zone.now)
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_download_app_notification) }
expect(Notification).not_to have_received(:send_welcome_notification)
end
it "generates the correct broadcast type and sends the notification to the user" do
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_download_app_notification) }
expect(user.notifications.count).to eq(1)
expect(user.notifications.first.notifiable).to eq(download_app_broadcast)
end
it "does not send duplicate notifications" do
2.times do
sidekiq_perform_enqueued_jobs { described_class.new(user.id).send(:send_download_app_notification) }
end
expect(user.notifications.count).to eq(1)
end
end
end
end