Add conversation message created live event

refs PFS-15497
flag = none

Test plan:
1. create a new conversation on canvas with another user
2. create a new message in the conversation by replying
3. verify live event for conversation_message_created has been triggered

Change-Id: Idf929eb5398f6040d8a3e45c644481b207858042
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/232152
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Product-Review: Dan Dickson <ddickson@instructure.com>
QA-Review: Aiona Rae Hernandez <ahernandez@instructure.com>
Reviewed-by: Sean Mikkelsen <smikkelsen@instructure.com>
Reviewed-by: Weston Dransfield <wdransfield@instructure.com>
This commit is contained in:
Michelle Truong 2020-03-30 11:45:10 -07:00 committed by Weston Dransfield
parent 2821328fd2
commit b5f9082b5d
5 changed files with 38 additions and 0 deletions

View File

@ -19,6 +19,7 @@ class LiveEventsObserver < ActiveRecord::Observer
observe :content_export,
:content_migration,
:conversation,
:conversation_message,
:course,
:discussion_entry,
:discussion_topic,

View File

@ -88,6 +88,15 @@ module Canvas::LiveEvents
})
end
def self.conversation_message_created(conversation_message)
post_event_stringified('conversation_message_created', {
author_id: conversation_message.author_id,
conversation_id: conversation_message.conversation_id,
created_at: conversation_message.created_at,
message_id: conversation_message.id
})
end
def self.discussion_entry_created(entry)
post_event_stringified('discussion_entry_created', get_discussion_entry_data(entry))
end

View File

@ -24,6 +24,8 @@ module Canvas::LiveEventsCallbacks
Canvas::LiveEvents.course_created(obj)
when Conversation
Canvas::LiveEvents.conversation_created(obj)
when ConversationMessage
Canvas::LiveEvents.conversation_message_created(obj)
when DiscussionEntry
Canvas::LiveEvents.discussion_entry_created(obj)
when DiscussionTopic

View File

@ -271,6 +271,22 @@ describe Canvas::LiveEvents do
end
end
describe ".conversation_message_created" do
it "should include the author id, conversation message id, and conversation id" do
user1 = user_model
user2 = user_model
convo = Conversation.initiate([user1, user2], false)
convo_message = convo.add_message(user1, 'Hi! You are doing great...')
expect_event('conversation_message_created',
hash_including(
author_id: convo_message.author_id.to_s,
conversation_id: convo_message.conversation_id.to_s,
message_id: convo_message.id.to_s
)).once
Canvas::LiveEvents.conversation_message_created(convo_message)
end
end
describe '.course_grade_change' do
before(:once) do
@user = User.create!

View File

@ -115,6 +115,16 @@ describe LiveEventsObserver do
end
describe "conversation messsage" do
it "posts conversation message create events" do
expect(Canvas::LiveEvents).to receive(:conversation_message_created).once
user1 = user_model
user2 = user_model
convo = Conversation.initiate([user1, user2], false)
convo.add_message(user1, "create new conversation message")
end
end
describe "course" do
it "posts create events" do
expect(Canvas::LiveEvents).to receive(:course_created).once