Import friendlyDescription from course import

closes OUT-4493
flag=outcomes_friendly_description

test plan:
- Do each of the following:
  - Import a course with an outcome that has a
  friendly description
  - Course copy a course with an outcome that has
  a friendly description
  - Create a blueprint course with an outcome that
  has a friendly description
- Observe that the friendly description is imported
properly and is present within the imported
outcome

Change-Id: I824853e5ccccca7e37fc3598aa1f761c36355e9e
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/270994
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Pat Renner <prenner@instructure.com>
Product-Review: Ben Friedman <ben.friedman@instructure.com>
Reviewed-by: Pat Renner <prenner@instructure.com>
Reviewed-by: Martin Yosifov <martin.yosifov@instructure.com>
This commit is contained in:
Angela Gomba 2021-08-18 16:36:13 -07:00
parent d874bd856a
commit 9be319934a
3 changed files with 53 additions and 0 deletions

View File

@ -162,6 +162,11 @@ module Importers
end
end
# Create OutcomeFriendlyDescription from course import
if item && Account.site_admin.feature_enabled?(:outcomes_friendly_description) && item.context_type == 'Course' && hash[:friendly_description].present?
OutcomeFriendlyDescription.find_or_create_by(context: item.context, learning_outcome: item).update(description: hash[:friendly_description])
end
migration.outcome_to_id_map[hash[:migration_id]] = item.id
item

View File

@ -67,6 +67,7 @@ module CC::Importer::Canvas
outcome[:is_global_outcome] = get_bool_val(node, 'is_global_outcome')
outcome[:external_identifier] = get_node_val(node, 'external_identifier')
outcome[:vendor_guid] = get_val_if_child(node, 'vendor_guid')
outcome[:friendly_description] = get_val_if_child(node, 'friendly_description')
outcome[:ratings] = []
node.css('rating').each do |r_node|

View File

@ -82,6 +82,53 @@ describe "Importing Learning Outcomes" do
expect(@context.learning_outcomes.count).to eq 2
end
it "should create an OutcomeFriendlyDescription if the outcome has a friendly description" do
Account.site_admin.enable_feature! :outcomes_friendly_description
existing_outcome = LearningOutcome.where(migration_id: "bdf6dc13-5d8f-43a8-b426-03380c9b6781").first
identifier = existing_outcome.migration_id
lo_data = @data["learning_outcomes"].find{|lo| lo["migration_id"] == identifier }
friendly_description = "a friendly description"
lo_data[:friendly_description] = friendly_description
Importers::LearningOutcomeImporter.import_from_migration(lo_data, @migration, existing_outcome)
expect(OutcomeFriendlyDescription.find_by(context_id: @context.id).description).to eq friendly_description
end
it "should create a new OutcomeFriendlyDescription if the outcome is being imported to a new context" do
context2 = course_model
outcome = context2.created_learning_outcomes.create!({:title => 'new outcome'})
friendly_description = "a friendly description"
OutcomeFriendlyDescription.create!({
learning_outcome: outcome,
context: context2,
description: friendly_description
})
outcome.write_attribute('migration_id', "bdf6dc13-5d8f-43a8-b426-03380c9b6781")
identifier = outcome.migration_id
lo_data = @data["learning_outcomes"].find{|lo| lo["migration_id"] == identifier }
Account.site_admin.enable_feature! :outcomes_friendly_description
lo_data[:friendly_description] = friendly_description
Importers::LearningOutcomeImporter.import_from_migration(lo_data, @migration, outcome)
expect(OutcomeFriendlyDescription.count).to eq 2
expect(OutcomeFriendlyDescription.find_by(context_id: @context.id).description).to eq friendly_description
end
it "should update an OutcomeFriendlyDescription if there is a friendly description in the database" do
Account.site_admin.enable_feature! :outcomes_friendly_description
existing_outcome = LearningOutcome.where(migration_id: "bdf6dc13-5d8f-43a8-b426-03380c9b6781").first
OutcomeFriendlyDescription.create!({
learning_outcome: existing_outcome,
context: existing_outcome.context,
description: "I will be updated to a new friendly description"
})
identifier = existing_outcome.migration_id
lo_data = @data["learning_outcomes"].find{|lo| lo["migration_id"] == identifier }
friendly_description = "I was updated to a new friendly description"
lo_data[:friendly_description] = friendly_description
Importers::LearningOutcomeImporter.import_from_migration(lo_data, @migration, existing_outcome)
expect(OutcomeFriendlyDescription.where(learning_outcome_id: existing_outcome.id).count).to eq 1
expect(OutcomeFriendlyDescription.find_by(learning_outcome_id: existing_outcome.id).description).to eq friendly_description
end
it "change calculation method, calculation int and rubric criterion" do
existing_outcome = LearningOutcome.where(migration_id: "bdf6dc13-5d8f-43a8-b426-03380c9b6781").first
expect(existing_outcome.calculation_method).to eq "decaying_average"