fix tests / move notification types to constants file
This commit is contained in:
parent
7ec4d6021d
commit
28ecbdfa48
|
|
@ -10,8 +10,9 @@ require "will_paginate/active_record"
|
|||
require "action_mailer"
|
||||
require "devise"
|
||||
require "sendgrid"
|
||||
require "jam_ruby/constants/validation_messages"
|
||||
require "jam_ruby/constants/limits"
|
||||
require "jam_ruby/constants/notification_types"
|
||||
require "jam_ruby/constants/validation_messages"
|
||||
require "jam_ruby/errors/permission_error"
|
||||
require "jam_ruby/errors/state_error"
|
||||
require "jam_ruby/errors/jam_argument_error"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
module NotificationTypes
|
||||
|
||||
FRIEND_UPDATE = "friend_update"
|
||||
FRIEND_REQUEST = "friend_request"
|
||||
FRIEND_REQUEST_ACCEPTED = "friend_request_accepted"
|
||||
|
||||
end
|
||||
|
|
@ -41,7 +41,7 @@ module JamRuby
|
|||
Friendship.save(friend_request.user_id, friend_request.friend_id)
|
||||
|
||||
# send notification
|
||||
Notification.send_friend_request_accepted(user_id, friend_id)
|
||||
Notification.send_friend_request_accepted(friend_request.user_id, friend_request.friend_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -79,24 +79,26 @@ module JamRuby
|
|||
|
||||
def format_msg(type, user)
|
||||
case type
|
||||
when "friend_update"
|
||||
when NotificationTypes::FRIEND_UPDATE
|
||||
return "#{user.name} is now "
|
||||
|
||||
when "friend_request"
|
||||
when NotificationTypes::FRIEND_REQUEST
|
||||
return "#{user.name} has sent you a friend request."
|
||||
|
||||
when "friend_request_accepted"
|
||||
when NotificationTypes::FRIEND_REQUEST_ACCEPTED
|
||||
return "#{user.name} has accepted your friend request."
|
||||
|
||||
when "friend_joined_session"
|
||||
when "social_media_friend_joined"
|
||||
when "join_request_approved"
|
||||
when "join_request_rejected"
|
||||
when "session_invitation"
|
||||
when "band_invitation"
|
||||
when "band_invitation_accepted"
|
||||
when "recording_available"
|
||||
else
|
||||
return ""
|
||||
# when "friend_joined_session"
|
||||
# when "social_media_friend_joined"
|
||||
# when "join_request_approved"
|
||||
# when "join_request_rejected"
|
||||
# when "session_invitation"
|
||||
# when "band_invitation"
|
||||
# when "band_invitation_accepted"
|
||||
# when "recording_available"
|
||||
# else
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -106,7 +108,7 @@ module JamRuby
|
|||
|
||||
# (1) create notification
|
||||
online_msg = online ? "online." : "offline."
|
||||
notification_msg = format_msg("friend_update", user) + online_msg
|
||||
notification_msg = format_msg(NotificationTypes::FRIEND_UPDATE, user) + online_msg
|
||||
msg = @@message_factory.friend_update(user_id, user.name, user.photo_url, online, notification_msg)
|
||||
|
||||
# (2) get all of this user's friends
|
||||
|
|
@ -121,7 +123,7 @@ module JamRuby
|
|||
user = User.find(user_id)
|
||||
|
||||
# (1) create notification
|
||||
notification_msg = format_msg("friend_request", user)
|
||||
notification_msg = format_msg(NotificationTypes::FRIEND_REQUEST, user)
|
||||
msg = @@message_factory.friend_request(id, user_id, user.name, user.photo_url, friend_id, notification_msg)
|
||||
|
||||
# (2) send notification
|
||||
|
|
@ -129,7 +131,7 @@ module JamRuby
|
|||
|
||||
# (3) save to database
|
||||
notification = Notification.new
|
||||
notification.type = "friend_request"
|
||||
notification.type = NotificationTypes::FRIEND_REQUEST
|
||||
notification.source_user_id = user_id
|
||||
notification.target_user_id = friend_id
|
||||
notification.save
|
||||
|
|
@ -140,14 +142,15 @@ module JamRuby
|
|||
friend = User.find(friend_id)
|
||||
|
||||
# (1) create notification
|
||||
msg = @@message_factory.friend_request_accepted(friend_id, friend.name, friend.photo_url, user_id)
|
||||
notification_msg = format_msg(NotificationTypes::FRIEND_REQUEST_ACCEPTED, friend)
|
||||
msg = @@message_factory.friend_request_accepted(friend_id, friend.name, friend.photo_url, user_id, notification_msg)
|
||||
|
||||
# (2) send notification
|
||||
@@mq_router.publish_to_user(user_id, msg)
|
||||
|
||||
# (3) save to database
|
||||
notification = Notification.new
|
||||
notification.type = "friend_request_accepted"
|
||||
notification.type = NotificationTypes::FRIEND_REQUEST_ACCEPTED
|
||||
notification.source_user_id = friend_id
|
||||
notification.target_user_id = user_id
|
||||
notification.save
|
||||
|
|
|
|||
Loading…
Reference in New Issue