spec: add Catalog consumer to Pact contract test suite
closes USERS-436 test plan: - requires a pact contract in local or public broker - execute tests against Pact files - run `bin/contracts-verify-live-events` Change-Id: I847787780e1bc4e5024e0cd2c46001dac6e31dfa Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/230402 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: August Thornton <august@instructure.com> Product-Review: August Thornton <august@instructure.com> Reviewed-by: Brian Watson <bwatson@instructure.com> Reviewed-by: Robin Kuss <rkuss@instructure.com>
This commit is contained in:
parent
5a1ad391f2
commit
630721d212
|
@ -0,0 +1,51 @@
|
|||
#
|
||||
# Copyright (C) 2020 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
require_relative '../live_events_pact_helper'
|
||||
|
||||
RSpec.describe 'Canvas LMS Live Events', :pact_live_events do
|
||||
describe 'course_completed' do
|
||||
let(:live_event) do
|
||||
LiveEvents::PactHelper::Event.new(
|
||||
event_name: 'course_completed', event_subscriber: PactConfig::LiveEventConsumers::CATALOG
|
||||
)
|
||||
end
|
||||
|
||||
it 'keeps the contract' do
|
||||
live_event.emit_with do
|
||||
course_model
|
||||
assignment_model(course: @course)
|
||||
student_in_course(active_all: true, course: @course)
|
||||
@user.update(email: 'user@example.com')
|
||||
context_module = @course.context_modules.create!
|
||||
tag = context_module.add_item({ id: @assignment.id, type: 'assignment' })
|
||||
context_module.completion_requirements = { tag.id => { type: 'must_submit' } }
|
||||
context_module.update(requirement_count: 1)
|
||||
context_module_progression =
|
||||
context_module.context_module_progressions.create!(
|
||||
user_id: @user.id,
|
||||
workflow_state: 'completed',
|
||||
requirements_met: [{ id: tag.id, type: 'must_submit' }]
|
||||
)
|
||||
Canvas::LiveEvents.course_completed(context_module_progression)
|
||||
end
|
||||
|
||||
expect(live_event).to have_kept_the_contract
|
||||
end
|
||||
end
|
||||
end
|
|
@ -26,6 +26,14 @@ module LiveEvents
|
|||
module PactHelper
|
||||
include PactConfig
|
||||
|
||||
def self.message_contract_for(consumer, event)
|
||||
Pact::Messages.get_message_contract(
|
||||
PactConfig::Providers::CANVAS_LMS_LIVE_EVENTS,
|
||||
consumer,
|
||||
event
|
||||
)
|
||||
end
|
||||
|
||||
class Event
|
||||
attr_reader :event_message, :event_name, :event_settings, :event_subscriber, :stream_client
|
||||
|
||||
|
@ -66,11 +74,18 @@ module LiveEvents
|
|||
end
|
||||
|
||||
def contract_message
|
||||
# Canvas Live Event Subscribers
|
||||
catalog = PactConfig::LiveEventConsumers::CATALOG
|
||||
outcomes = PactConfig::LiveEventConsumers::OUTCOMES
|
||||
quiz_lti = PactConfig::LiveEventConsumers::QUIZ_LTI
|
||||
|
||||
case event_subscriber
|
||||
when PactConfig::LiveEventConsumers::QUIZ_LTI
|
||||
LiveEvents::PactHelper.quiz_lti_contract_for(event_name)
|
||||
when PactConfig::LiveEventConsumers::OUTCOMES
|
||||
LiveEvents::PactHelper.outcomes_contract_for(event_name)
|
||||
when catalog
|
||||
LiveEvents::PactHelper.message_contract_for(catalog, event_name)
|
||||
when outcomes
|
||||
LiveEvents::PactHelper.message_contract_for(outcomes, event_name)
|
||||
when quiz_lti
|
||||
LiveEvents::PactHelper.message_contract_for(quiz_lti, event_name)
|
||||
else
|
||||
raise ArgumentError, "Invalid event_subscriber: #{event_subscriber}"
|
||||
end
|
||||
|
@ -108,25 +123,5 @@ module LiveEvents
|
|||
}
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def quiz_lti_contract_for(event)
|
||||
message_contract_for(PactConfig::LiveEventConsumers::QUIZ_LTI, event)
|
||||
end
|
||||
|
||||
def outcomes_contract_for(event)
|
||||
message_contract_for(PactConfig::LiveEventConsumers::OUTCOMES, event)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def message_contract_for(consumer, event)
|
||||
Pact::Messages.get_message_contract(
|
||||
PactConfig::Providers::CANVAS_LMS_LIVE_EVENTS,
|
||||
consumer,
|
||||
event
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,6 +53,7 @@ module PactConfig
|
|||
|
||||
# Add new Live Events consumers to this module
|
||||
module LiveEventConsumers
|
||||
CATALOG = 'Catalog'.freeze
|
||||
OUTCOMES = 'Outcomes'.freeze
|
||||
QUIZ_LTI = 'Quiz LTI'.freeze
|
||||
end
|
||||
|
@ -69,9 +70,7 @@ module PactConfig
|
|||
|
||||
def broker_uri
|
||||
URI::HTTP.build(
|
||||
scheme: protocol,
|
||||
userinfo: "#{broker_username}:#{broker_password}",
|
||||
host: broker_host
|
||||
scheme: protocol, userinfo: "#{broker_username}:#{broker_password}", host: broker_host
|
||||
).to_s
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue