From 9be319934aeef3745f30ca93f11850c78784e008 Mon Sep 17 00:00:00 2001 From: Angela Gomba Date: Wed, 18 Aug 2021 16:36:13 -0700 Subject: [PATCH] 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 QA-Review: Pat Renner Product-Review: Ben Friedman Reviewed-by: Pat Renner Reviewed-by: Martin Yosifov --- .../importers/learning_outcome_importer.rb | 5 ++ .../canvas/learning_outcomes_converter.rb | 1 + .../learning_outcomes_importer_spec.rb | 47 +++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/app/models/importers/learning_outcome_importer.rb b/app/models/importers/learning_outcome_importer.rb index 5df4a0ea58c..7d43717c6ff 100644 --- a/app/models/importers/learning_outcome_importer.rb +++ b/app/models/importers/learning_outcome_importer.rb @@ -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 diff --git a/lib/cc/importer/canvas/learning_outcomes_converter.rb b/lib/cc/importer/canvas/learning_outcomes_converter.rb index a815a2f2876..9f04cc806f1 100644 --- a/lib/cc/importer/canvas/learning_outcomes_converter.rb +++ b/lib/cc/importer/canvas/learning_outcomes_converter.rb @@ -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| diff --git a/spec/models/importers/learning_outcomes_importer_spec.rb b/spec/models/importers/learning_outcomes_importer_spec.rb index 39e1c098ec0..ae39ab2e98f 100644 --- a/spec/models/importers/learning_outcomes_importer_spec.rb +++ b/spec/models/importers/learning_outcomes_importer_spec.rb @@ -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"