Add Broadcast seeds + generator service to set up for welcome notifications (#6080)

* Add more Broadcasts to seeds for welcome notification flow

* Remove unnecessary welcoming_user_id from development config

* Add basic service class for generating appropriate broadcast per user

Eventually, this should be called from a rake task that will rely on this service to determine which broadcast, if any, is the appropriate one to send to newly signed-up users, and will enqueue a worker to create/send a welcome notification when appropriate.

* Add a few TODOs, plus some general cleanup

* Add some skipped tests for WelcomeNotification::Generator
This commit is contained in:
Vaidehi Joshi 2020-02-14 12:30:25 -08:00 committed by GitHub
parent 6a277ba10d
commit 76fe99b76a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 81 additions and 4 deletions

View file

@ -4,6 +4,7 @@ class Broadcast < ApplicationRecord
has_many :notifications, as: :notifiable, inverse_of: :notifiable
validates :title, :type_of, :processed_html, presence: true
# TODO: [@thepracticaldev/delightful] Remove Onboarding type once we have launched welcome notifications.
validates :type_of, inclusion: { in: %w[Announcement Onboarding Welcome] }
def get_inner_body(content)

View file

@ -0,0 +1,28 @@
# Generates a broadcast to be delivered as a notification.
module Broadcasts
module WelcomeNotification
class Generator
def initialize(receiver_id)
@receiver_id = receiver_id
end
def self.call(*args)
new(*args).call
end
def call
# This method should find the user based on the `receiver_id`.
# It should then determine the appropriate Broadcast for a user,
# based on the `created_at` and the different conditions for sending a notification.
# `welcome_broadcast = ...`
# Once it has the appropriate Broadcast to be sent, it should send a notification for it:
# `Notification.send_welcome_notification(receiver_id, welcome_broadcast.id)`
end
private
attr_reader :receiver_id
end
end
end

View file

@ -1,4 +1,4 @@
# send welcome notification
# Creates and sends a specific welcome notification.
module Notifications
module WelcomeNotification
class Send

View file

@ -96,8 +96,6 @@ Rails.application.configure do
# Debug is the default log_level, but can be changed per environment.
config.log_level = :debug
config.welcoming_user_id = ENV["WELCOMING_USER_ID"]
# See <https://github.com/flyerhzm/bullet#configuration> for other config options
config.after_initialize do
Bullet.enable = true

View file

@ -201,6 +201,7 @@ end
Rails.logger.info "7. Creating Broadcasts"
# TODO: [@thepracticaldev/delightful] Remove this once we have launched welcome notifications.
Broadcast.create!(
title: "Welcome Notification",
processed_html: "Welcome to dev.to! Start by introducing yourself in <a href='/welcome' data-no-instant>the welcome thread</a>.",
@ -208,6 +209,22 @@ Broadcast.create!(
sent: true,
)
broadcast_messages = {
set_up_profile: "Welcome to DEV! 👋 I'm Sloan, the community mascot and I'm here to help get you started. Let's begin by <a href='/settings'>setting up your profile</a>!",
welcome_thread: "Sloan here again! 👋 DEV is a friendly community. Why not introduce yourself by leaving a comment in <a href='/welcome'>the welcome thread</a>!",
twitter_connect: "You're on a roll! 🎉 Let's connect your <a href='/settings'> Twitter account</a> to complete your identity so that we don't think you're a robot. 🤖",
github_connect: "You're on a roll! 🎉 Let's connect your <a href='/settings'> GitHub account</a> to complete your identity so that we don't think you're a robot. 🤖"
}
broadcast_messages.each do |type, message|
Broadcast.create!(
title: "Welcome Notification: #{type}",
processed_html: message,
type_of: "Welcome",
sent: true,
)
end
##############################################################################
Rails.logger.info "8. Creating Chat Channels and Messages"

View file

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Broadcasts::WelcomeNotification::Generator, type: :service do
describe "::call" do
context "when sending a set_up_profile notification" do
xit "generates the appropriate broadcast to be sent to a user"
xit "it sends a welcome notification for that broadcast"
xit "it does not send duplicate welcome notification for that broadcast"
xit "does not send a notification to a user who has set up their profile"
end
context "when sending a welcome_thread notification" do
xit "generates the appropriate broadcast to be sent to a user"
xit "it sends a welcome notification for that broadcast"
xit "it does not send duplicate welcome notification for that broadcast"
xit "does not send a notification to a user who has commented in a welcome thread"
end
context "when sending a twitter_connect notification" do
xit "generates the appropriate broadcast to be sent to a user"
xit "it sends a welcome notification for that broadcast"
xit "it does not send duplicate welcome notification for that broadcast"
xit "does not send a notification to a user who is connected via twitter"
end
context "when sending a github_connect notification" do
xit "generates the appropriate broadcast to be sent to a user"
xit "it sends a welcome notification for that broadcast"
xit "it does not send duplicate welcome notification for that broadcast"
xit "does not send a notification to a user who is connected via github"
end
end
end

View file

@ -6,7 +6,7 @@ RSpec.describe Notifications::WelcomeNotification::Send, type: :service do
allow(User).to receive(:welcoming_account).and_return(create(:user))
end
it "checks a newly created welcome notification", :aggregate_failures do
it "creates a new welcome notification", :aggregate_failures do
welcome_broadcast = create(:broadcast, :onboarding)
welcome_notification = described_class.call(create(:user).id, welcome_broadcast)