new grading schemes json controller
Adds a controller that returns clean json for grading schemes. This controller will be used in the future by the UI to load data for the new 'Improved Grading Scheme UX' feature. closes EVAL-3138 flag = none Test plan: - verify that the controller endpoints do not expose any data without proper authentication and authorization - note: nothing in the UI is currently calling this controller Change-Id: Ib69c7f0b08213776024f34a02567b739b7ad5e13 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/318824 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Derek Williams <derek.williams@instructure.com> Reviewed-by: Cameron Ray <cameron.ray@instructure.com> QA-Review: Cameron Ray <cameron.ray@instructure.com> Product-Review: Cameron Ray <cameron.ray@instructure.com>
This commit is contained in:
parent
6957e9b3f2
commit
3d1df1ef0f
|
@ -0,0 +1,151 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2023 - 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/>.
|
||||
#
|
||||
|
||||
class GradingSchemesJsonController < ApplicationController
|
||||
JSON_METHODS =
|
||||
%i[assessed_assignment? context_name].freeze
|
||||
GRADING_SCHEMES_LIMIT = 100
|
||||
before_action :require_context
|
||||
before_action :require_user
|
||||
def detail_list
|
||||
if authorized_action(@context, @current_user, :manage_grades)
|
||||
grading_standards = GradingStandard.for(@context).sorted.limit(GRADING_SCHEMES_LIMIT)
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: grading_standards.map { |grading_standard|
|
||||
GradingSchemesJsonController.to_grading_scheme_json(grading_standard, @current_user)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def summary_list
|
||||
if authorized_action(@context, @current_user, :manage_grades)
|
||||
grading_standards = GradingStandard.for(@context).sorted.limit(GRADING_SCHEMES_LIMIT)
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: grading_standards.map { |grading_standard|
|
||||
GradingSchemesJsonController.to_grading_scheme_summary_json(grading_standard)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
if authorized_action(@context, @current_user, :manage_grades)
|
||||
grading_standard = GradingStandard.for(@context).find(params[:id])
|
||||
respond_to do |format|
|
||||
format.json { render json: GradingSchemesJsonController.to_grading_scheme_json(grading_standard, @current_user) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show_default_grading_scheme
|
||||
grading_standard_data = GradingStandard.default_grading_standard
|
||||
props = {}
|
||||
props["title"] = I18n.t("Default Canvas Grading Scheme")
|
||||
props["data"] = grading_standard_data
|
||||
default_grading_standard = @context.grading_standards.build(props)
|
||||
respond_to do |format|
|
||||
format.json { render json: GradingSchemesJsonController.to_grading_scheme_json(default_grading_standard, @current_user) }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
if authorized_action(@context, @current_user, :manage_grades)
|
||||
grading_standard = @context.grading_standards.build({ title: params[:title], data: GradingSchemesJsonController.to_grading_standard_data(params[:data]) })
|
||||
respond_to do |format|
|
||||
if grading_standard.save
|
||||
format.json { render json: GradingSchemesJsonController.to_grading_scheme_json(grading_standard, @current_user) }
|
||||
else
|
||||
format.json { render json: grading_standard.errors, status: :bad_request }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
grading_standard = GradingStandard.for(@context).find(params[:id])
|
||||
if authorized_action(grading_standard, @current_user, :manage)
|
||||
grading_standard.user = @current_user
|
||||
respond_to do |format|
|
||||
if grading_standard.update({ title: params[:title], data: GradingSchemesJsonController.to_grading_standard_data(params[:data]) })
|
||||
format.json { render json: GradingSchemesJsonController.to_grading_scheme_json(grading_standard, @current_user) }
|
||||
else
|
||||
format.json { render json: grading_standard.errors, status: :bad_request }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
grading_standard = GradingStandard.for(@context).find(params[:id])
|
||||
if authorized_action(grading_standard, @current_user, :manage)
|
||||
respond_to do |format|
|
||||
if grading_standard.destroy
|
||||
format.json { render json: {} }
|
||||
else
|
||||
format.json { render json: grading_standard.errors, status: :bad_request }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.to_grading_scheme_summary_json(grading_standard)
|
||||
{
|
||||
title: grading_standard.title,
|
||||
id: grading_standard.id.to_s
|
||||
}.as_json
|
||||
end
|
||||
|
||||
def self.to_grading_scheme_json(grading_standard, user)
|
||||
grading_standard.as_json({ methods: JSON_METHODS,
|
||||
include_root: false }
|
||||
.merge(only: %w[id title context_type context_id],
|
||||
permissions: { user: user }))
|
||||
.tap do |json|
|
||||
# because GradingStandard generates the JSON property with a '?' on the end of it,
|
||||
# instead of using the JSON convention for boolean properties
|
||||
json["assessed_assignment"] = json["assessed_assignment?"]
|
||||
json.delete "assessed_assignment?"
|
||||
|
||||
# because GradingStandard serializes its id as a number instead of a string
|
||||
json["id"] = json["id"].to_s
|
||||
|
||||
# because GradingStandard serializes its data rows to JSON as an array of arrays: [["A", .90], ["B", .80]]
|
||||
# instead of our desired format of an array of objects with name/value pairs [{name: "A", value: .90], {name: "B", value: .80}]
|
||||
json["data"] = grading_standard["data"].map { |grading_standard_data_row| { name: grading_standard_data_row[0], value: grading_standard_data_row[1] } }
|
||||
end
|
||||
end
|
||||
|
||||
def self.to_grading_standard_data(grading_scheme_json_data)
|
||||
# converts a GradingScheme UI model's data field format from:
|
||||
# [{"name": "A", "value": .94}, {"name": "B", "value": .84}, ]
|
||||
# to the GradingStandard ActiveRecord's data field format:
|
||||
# { "A" => 0.94, "B" => .84, }
|
||||
grading_standard_data = {}
|
||||
grading_scheme_json_data.map do |grading_scheme_data_row|
|
||||
grading_standard_data[grading_scheme_data_row["name"]] = grading_scheme_data_row["value"]
|
||||
end
|
||||
grading_standard_data
|
||||
end
|
||||
end
|
|
@ -501,8 +501,15 @@ CanvasRails::Application.routes.draw do
|
|||
delete "test_student" => "courses#reset_test_student"
|
||||
get "content_migrations" => "content_migrations#index"
|
||||
get "link_validator" => "courses#link_validator", :as => :link_validator
|
||||
end
|
||||
|
||||
get "grading_schemes" => "grading_schemes_json#detail_list"
|
||||
get "grading_scheme_summaries" => "grading_schemes_json#summary_list"
|
||||
post "grading_schemes" => "grading_schemes_json#create"
|
||||
delete "grading_schemes/:id" => "grading_schemes_json#destroy"
|
||||
put "grading_schemes/:id" => "grading_schemes_json#update"
|
||||
get "grading_schemes/default" => "grading_schemes_json#show_default_grading_scheme"
|
||||
get "grading_schemes/:id" => "grading_schemes_json#show"
|
||||
end
|
||||
get "quiz_statistics/:quiz_statistics_id/files/:file_id/download" => "files#show", :as => :quiz_statistics_download, :download => "1"
|
||||
|
||||
resources :page_views, only: :update
|
||||
|
@ -772,6 +779,14 @@ CanvasRails::Application.routes.draw do
|
|||
get "release_notes" => "release_notes#manage", :as => :release_notes_manage
|
||||
|
||||
get "blackout_dates" => "blackout_dates#index"
|
||||
|
||||
get "grading_schemes" => "grading_schemes_json#detail_list"
|
||||
get "grading_scheme_summaries" => "grading_schemes_json#summary_list"
|
||||
post "grading_schemes" => "grading_schemes_json#create"
|
||||
delete "grading_schemes/:id" => "grading_schemes_json#destroy"
|
||||
put "grading_schemes/:id" => "grading_schemes_json#update"
|
||||
get "grading_schemes/default" => "grading_schemes_json#show_default_grading_scheme"
|
||||
get "grading_schemes/:id" => "grading_schemes_json#show"
|
||||
end
|
||||
|
||||
get "images/users/:user_id" => "users#avatar_image", :as => :avatar_image
|
||||
|
|
|
@ -0,0 +1,477 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2023 - 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 "../spec_helper"
|
||||
|
||||
describe GradingSchemesJsonController, type: :request do
|
||||
require_relative "../spec_helper"
|
||||
|
||||
context "account admin" do
|
||||
before(:once) do
|
||||
@account = Account.default
|
||||
@admin = account_admin_user(account: @account)
|
||||
end
|
||||
|
||||
describe "get grading schemes" do
|
||||
it "returns account level grading schemes json" do
|
||||
data = [{ "name" => "A", "value" => 0.92 },
|
||||
{ "name" => "A-", "value" => 0.9 },
|
||||
{ "name" => "B+", "value" => 0.87 },
|
||||
{ "name" => "B", "value" => 0.82 },
|
||||
{ "name" => "B-", "value" => 0.8 },
|
||||
{ "name" => "C+", "value" => 0.77 },
|
||||
{ "name" => "C", "value" => 0.72 },
|
||||
{ "name" => "C-", "value" => 0.7 },
|
||||
{ "name" => "D+", "value" => 0.67 },
|
||||
{ "name" => "D", "value" => 0.62 },
|
||||
{ "name" => "D-", "value" => 0.61 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
account_level_grading_standard = @account.grading_standards.build(title: "My Grading Scheme", data: GradingSchemesJsonController.to_grading_standard_data(data))
|
||||
account_level_grading_standard.save
|
||||
|
||||
user_session(@admin)
|
||||
get "/accounts/" + @account.id.to_s + "/grading_schemes", as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
response_json = response.parsed_body
|
||||
expect(response_json.first).to eq({ "id" => account_level_grading_standard.id.to_s,
|
||||
"title" => "My Grading Scheme",
|
||||
"context_type" => "Account",
|
||||
"context_id" => @account.id,
|
||||
"context_name" => "Default Account",
|
||||
"data" => data,
|
||||
"permissions" => { "manage" => true },
|
||||
"assessed_assignment" => false })
|
||||
end
|
||||
end
|
||||
|
||||
describe "get grading scheme" do
|
||||
it "returns account level grading scheme json" do
|
||||
data = [{ "name" => "A", "value" => 0.92 },
|
||||
{ "name" => "A-", "value" => 0.9 },
|
||||
{ "name" => "B+", "value" => 0.87 },
|
||||
{ "name" => "B", "value" => 0.82 },
|
||||
{ "name" => "B-", "value" => 0.8 },
|
||||
{ "name" => "C+", "value" => 0.77 },
|
||||
{ "name" => "C", "value" => 0.72 },
|
||||
{ "name" => "C-", "value" => 0.7 },
|
||||
{ "name" => "D+", "value" => 0.67 },
|
||||
{ "name" => "D", "value" => 0.62 },
|
||||
{ "name" => "D-", "value" => 0.61 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
account_level_grading_standard = @account.grading_standards.build(title: "My Grading Scheme", data: GradingSchemesJsonController.to_grading_standard_data(data))
|
||||
account_level_grading_standard.save
|
||||
|
||||
user_session(@admin)
|
||||
get "/accounts/" + @account.id.to_s + "/grading_schemes/" + account_level_grading_standard.id.to_s, as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
response_json = response.parsed_body
|
||||
expect(response_json).to eq({ "id" => account_level_grading_standard.id.to_s,
|
||||
"title" => "My Grading Scheme",
|
||||
"context_type" => "Account",
|
||||
"context_id" => @account.id,
|
||||
"context_name" => "Default Account",
|
||||
"data" => data,
|
||||
"permissions" => { "manage" => true },
|
||||
"assessed_assignment" => false })
|
||||
end
|
||||
end
|
||||
|
||||
describe "get grading scheme summaries" do
|
||||
it "returns course and account level grading scheme summary json" do
|
||||
account_scheme_data = [{ "name" => "A", "value" => 0.90 },
|
||||
{ "name" => "B", "value" => 0.80 },
|
||||
{ "name" => "C", "value" => 0.70 },
|
||||
{ "name" => "D", "value" => 0.60 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
account_level_grading_standard = @account.grading_standards.build(title: "My Account Level Grading Standard", data: GradingSchemesJsonController.to_grading_standard_data(account_scheme_data))
|
||||
account_level_grading_standard.save
|
||||
|
||||
user_session(@admin)
|
||||
get "/accounts/" + @account.id.to_s + "/grading_scheme_summaries", as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
expect(response_json.length).to eq 1
|
||||
|
||||
expect(response_json.first).to eq({ "id" => account_level_grading_standard.id.to_s,
|
||||
"title" => "My Account Level Grading Standard" })
|
||||
end
|
||||
end
|
||||
|
||||
describe "get default grading scheme" do
|
||||
it "returns default grading scheme json" do
|
||||
user_session(@admin)
|
||||
get "/accounts/" + @account.id.to_s + "/grading_schemes/default", as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
expect(response_json["title"]).to eq "Default Canvas Grading Scheme"
|
||||
expect(response_json["data"]).to eq [{ "name" => "A", "value" => 0.94 },
|
||||
{ "name" => "A-", "value" => 0.9 },
|
||||
{ "name" => "B+", "value" => 0.87 },
|
||||
{ "name" => "B", "value" => 0.84 },
|
||||
{ "name" => "B-", "value" => 0.8 },
|
||||
{ "name" => "C+", "value" => 0.77 },
|
||||
{ "name" => "C", "value" => 0.74 },
|
||||
{ "name" => "C-", "value" => 0.7 },
|
||||
{ "name" => "D+", "value" => 0.67 },
|
||||
{ "name" => "D", "value" => 0.64 },
|
||||
{ "name" => "D-", "value" => 0.61 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
end
|
||||
end
|
||||
|
||||
describe "create grading scheme" do
|
||||
it "creates grading scheme at account level" do
|
||||
user_session(@admin)
|
||||
|
||||
data = [{ "name" => "A", "value" => 0.90 },
|
||||
{ "name" => "B", "value" => 0.80 },
|
||||
{ "name" => "C", "value" => 0.70 },
|
||||
{ "name" => "D", "value" => 0.60 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
params = { title: "My Scheme Title",
|
||||
data: data }
|
||||
|
||||
post "/accounts/" + @account.id.to_s + "/grading_schemes",
|
||||
params: params,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
expect(response_json["context_type"]).to eq "Account"
|
||||
expect(response_json["context_id"]).to eq @account.id
|
||||
expect(response_json["title"]).to eq "My Scheme Title"
|
||||
expect(response_json["data"]).to eq data
|
||||
expect(response_json["permissions"]).to eq({ "manage" => true })
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete grading scheme" do
|
||||
it "deletes grading scheme at account level" do
|
||||
data = [{ "name" => "A", "value" => 0.90 },
|
||||
{ "name" => "B", "value" => 0.80 },
|
||||
{ "name" => "C", "value" => 0.70 },
|
||||
{ "name" => "D", "value" => 0.60 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
|
||||
account_level_grading_standard = @account.grading_standards.build(title: "My Grading Scheme to Delete", data: GradingSchemesJsonController.to_grading_standard_data(data))
|
||||
account_level_grading_standard.save
|
||||
|
||||
expect(GradingStandard.all.count).to be 1
|
||||
user_session(@admin)
|
||||
delete "/accounts/" + @account.id.to_s + "/grading_schemes/" + account_level_grading_standard.id.to_s, as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
|
||||
# it's a soft delete
|
||||
expect(GradingStandard.all.count).to be 1
|
||||
expect(GradingStandard.first.title).to eq "My Grading Scheme to Delete"
|
||||
expect(GradingStandard.first.workflow_state).to eq "deleted"
|
||||
expect(response_json).to eq({})
|
||||
end
|
||||
end
|
||||
|
||||
describe "update grading scheme" do
|
||||
it "returns success when putting account level grading scheme" do
|
||||
data = [{ "name" => "A", "value" => 0.92 },
|
||||
{ "name" => "A-", "value" => 0.9 },
|
||||
{ "name" => "B+", "value" => 0.87 },
|
||||
{ "name" => "B", "value" => 0.82 },
|
||||
{ "name" => "B-", "value" => 0.8 },
|
||||
{ "name" => "C+", "value" => 0.77 },
|
||||
{ "name" => "C", "value" => 0.72 },
|
||||
{ "name" => "C-", "value" => 0.7 },
|
||||
{ "name" => "D+", "value" => 0.67 },
|
||||
{ "name" => "D", "value" => 0.62 },
|
||||
{ "name" => "D-", "value" => 0.61 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
account_level_grading_standard = @account.grading_standards.build(title: "My Grading Scheme", data: GradingSchemesJsonController.to_grading_standard_data(data))
|
||||
account_level_grading_standard.save
|
||||
|
||||
user_session(@admin)
|
||||
|
||||
updated_data = [{ "name" => "A", "value" => 0.90 },
|
||||
{ "name" => "B", "value" => 0.80 },
|
||||
{ "name" => "C", "value" => 0.70 },
|
||||
{ "name" => "D", "value" => 0.60 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
params = { title: "My Scheme Title",
|
||||
data: updated_data }
|
||||
|
||||
put "/accounts/" + @account.id.to_s + "/grading_schemes/" + account_level_grading_standard.id.to_s,
|
||||
params: params,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
|
||||
expect(response_json).to eq({ "id" => account_level_grading_standard.id.to_s,
|
||||
"title" => "My Scheme Title",
|
||||
"context_type" => "Account",
|
||||
"context_id" => @account.id,
|
||||
"context_name" => "Default Account",
|
||||
"data" => updated_data,
|
||||
"permissions" => { "manage" => true },
|
||||
"assessed_assignment" => false })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "course teacher" do
|
||||
before(:once) do
|
||||
@account = Account.default
|
||||
course_with_teacher(active_all: true)
|
||||
end
|
||||
|
||||
describe "get grading schemes" do
|
||||
it "returns course and account level grading schemes json" do
|
||||
account_scheme_data = [{ "name" => "A", "value" => 0.9 },
|
||||
{ "name" => "B", "value" => 0.8 },
|
||||
{ "name" => "C", "value" => 0.7 },
|
||||
{ "name" => "D", "value" => 0.6 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
account_level_grading_standard = @account.grading_standards.build(title: "My Account Level Grading Standard", data: GradingSchemesJsonController.to_grading_standard_data(account_scheme_data))
|
||||
account_level_grading_standard.save
|
||||
|
||||
course_scheme_data = [{ "name" => "A", "value" => 0.98 },
|
||||
{ "name" => "A-", "value" => 0.9 },
|
||||
{ "name" => "B+", "value" => 0.88 },
|
||||
{ "name" => "B", "value" => 0.85 },
|
||||
{ "name" => "B-", "value" => 0.8 },
|
||||
{ "name" => "C+", "value" => 0.78 },
|
||||
{ "name" => "C", "value" => 0.75 },
|
||||
{ "name" => "C-", "value" => 0.7 },
|
||||
{ "name" => "D+", "value" => 0.68 },
|
||||
{ "name" => "D", "value" => 0.65 },
|
||||
{ "name" => "D-", "value" => 0.61 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
|
||||
course_level_grading_standard = @course.grading_standards.build(title: "My Course Level Grading Standard", data: GradingSchemesJsonController.to_grading_standard_data(course_scheme_data))
|
||||
course_level_grading_standard.save
|
||||
|
||||
user_session(@teacher)
|
||||
get "/courses/" + @course.id.to_s + "/grading_schemes", as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
expect(response_json.length).to eq 2
|
||||
|
||||
expect(response_json.first).to eq({ "id" => account_level_grading_standard.id.to_s,
|
||||
"title" => "My Account Level Grading Standard",
|
||||
"context_type" => "Account",
|
||||
"context_id" => @account.id,
|
||||
"context_name" => "Default Account",
|
||||
"data" => account_scheme_data,
|
||||
"permissions" => { "manage" => false },
|
||||
"assessed_assignment" => false })
|
||||
|
||||
expect(response_json[1]).to eq({ "id" => course_level_grading_standard.id.to_s,
|
||||
"title" => "My Course Level Grading Standard",
|
||||
"context_type" => "Course",
|
||||
"context_id" => @course.id,
|
||||
"context_name" => "Unnamed Course",
|
||||
"data" => course_scheme_data,
|
||||
"permissions" => { "manage" => true },
|
||||
"assessed_assignment" => false })
|
||||
end
|
||||
end
|
||||
|
||||
describe "get grading scheme summaries" do
|
||||
it "returns course and account level grading scheme summary json" do
|
||||
account_scheme_data = [{ "name" => "A", "value" => 0.90 },
|
||||
{ "name" => "B", "value" => 0.80 },
|
||||
{ "name" => "C", "value" => 0.70 },
|
||||
{ "name" => "D", "value" => 0.60 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
account_level_grading_standard = @account.grading_standards.build(title: "My Account Level Grading Standard", data: GradingSchemesJsonController.to_grading_standard_data(account_scheme_data))
|
||||
account_level_grading_standard.save
|
||||
|
||||
course_scheme_data = [{ "name" => "A", "value" => 0.90 },
|
||||
{ "name" => "B", "value" => 0.80 },
|
||||
{ "name" => "C", "value" => 0.70 },
|
||||
{ "name" => "D", "value" => 0.60 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
|
||||
course_level_grading_standard = @course.grading_standards.build(title: "My Course Level Grading Standard", data: GradingSchemesJsonController.to_grading_standard_data(course_scheme_data))
|
||||
course_level_grading_standard.save
|
||||
|
||||
user_session(@teacher)
|
||||
get "/courses/" + @course.id.to_s + "/grading_scheme_summaries", as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
expect(response_json.length).to eq 2
|
||||
|
||||
expect(response_json.first).to eq({ "id" => account_level_grading_standard.id.to_s,
|
||||
"title" => "My Account Level Grading Standard" })
|
||||
|
||||
expect(response_json[1]).to eq({ "id" => course_level_grading_standard.id.to_s,
|
||||
"title" => "My Course Level Grading Standard" })
|
||||
end
|
||||
end
|
||||
|
||||
describe "create grading scheme" do
|
||||
it "creates grading scheme at account level" do
|
||||
user_session(@teacher)
|
||||
data = [{ "name" => "A", "value" => 0.90 },
|
||||
{ "name" => "B", "value" => 0.80 },
|
||||
{ "name" => "C", "value" => 0.70 },
|
||||
{ "name" => "D", "value" => 0.60 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
|
||||
params = { title: "My Scheme Title",
|
||||
data: data }
|
||||
|
||||
post "/courses/" + @course.id.to_s + "/grading_schemes",
|
||||
params: params,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
expect(response_json["context_type"]).to eq "Course"
|
||||
expect(response_json["context_id"]).to eq @course.id
|
||||
expect(response_json["title"]).to eq "My Scheme Title"
|
||||
expect(response_json["data"]).to eq data
|
||||
expect(response_json["permissions"]).to eq({ "manage" => true })
|
||||
end
|
||||
end
|
||||
|
||||
describe "get default grading scheme" do
|
||||
it "returns default grading scheme json" do
|
||||
user_session(@teacher)
|
||||
get "/courses/" + @course.id.to_s + "/grading_schemes/default", as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
expect(response_json["title"]).to eq "Default Canvas Grading Scheme"
|
||||
expect(response_json["data"]).to eq [{ "name" => "A", "value" => 0.94 },
|
||||
{ "name" => "A-", "value" => 0.9 },
|
||||
{ "name" => "B+", "value" => 0.87 },
|
||||
{ "name" => "B", "value" => 0.84 },
|
||||
{ "name" => "B-", "value" => 0.8 },
|
||||
{ "name" => "C+", "value" => 0.77 },
|
||||
{ "name" => "C", "value" => 0.74 },
|
||||
{ "name" => "C-", "value" => 0.7 },
|
||||
{ "name" => "D+", "value" => 0.67 },
|
||||
{ "name" => "D", "value" => 0.64 },
|
||||
{ "name" => "D-", "value" => 0.61 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete grading scheme" do
|
||||
it "deletes grading scheme at account level" do
|
||||
data = [{ "name" => "A", "value" => 0.90 },
|
||||
{ "name" => "B", "value" => 0.80 },
|
||||
{ "name" => "C", "value" => 0.70 },
|
||||
{ "name" => "D", "value" => 0.60 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
|
||||
course_level_grading_standard = @course.grading_standards.build(title: "My Grading Scheme to Delete", data: GradingSchemesJsonController.to_grading_standard_data(data))
|
||||
course_level_grading_standard.save
|
||||
|
||||
expect(GradingStandard.all.count).to be 1
|
||||
user_session(@teacher)
|
||||
delete "/courses/" + @course.id.to_s + "/grading_schemes/" + course_level_grading_standard.id.to_s, as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
|
||||
# it's a soft delete
|
||||
expect(GradingStandard.all.count).to be 1
|
||||
expect(GradingStandard.first.title).to eq "My Grading Scheme to Delete"
|
||||
expect(GradingStandard.first.workflow_state).to eq "deleted"
|
||||
expect(response_json).to eq({})
|
||||
end
|
||||
end
|
||||
|
||||
describe "update grading scheme" do
|
||||
it "returns success when putting account level grading scheme" do
|
||||
data = [{ "name" => "A", "value" => 0.92 },
|
||||
{ "name" => "A-", "value" => 0.9 },
|
||||
{ "name" => "B+", "value" => 0.87 },
|
||||
{ "name" => "B", "value" => 0.82 },
|
||||
{ "name" => "B-", "value" => 0.8 },
|
||||
{ "name" => "C+", "value" => 0.77 },
|
||||
{ "name" => "C", "value" => 0.72 },
|
||||
{ "name" => "C-", "value" => 0.7 },
|
||||
{ "name" => "D+", "value" => 0.67 },
|
||||
{ "name" => "D", "value" => 0.62 },
|
||||
{ "name" => "D-", "value" => 0.61 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
grading_standard = @course.grading_standards.build(title: "My Grading Scheme", data: GradingSchemesJsonController.to_grading_standard_data(data))
|
||||
grading_standard.save
|
||||
|
||||
user_session(@teacher)
|
||||
|
||||
updated_data = [{ "name" => "A", "value" => 0.90 },
|
||||
{ "name" => "B", "value" => 0.80 },
|
||||
{ "name" => "C", "value" => 0.70 },
|
||||
{ "name" => "D", "value" => 0.60 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
params = { title: "My Scheme Title",
|
||||
data: updated_data }
|
||||
|
||||
put "/courses/" + @course.id.to_s + "/grading_schemes/" + grading_standard.id.to_s,
|
||||
params: params,
|
||||
as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
response_json = response.parsed_body
|
||||
|
||||
expect(response_json).to eq({ "id" => grading_standard.id.to_s,
|
||||
"title" => "My Scheme Title",
|
||||
"context_type" => "Course",
|
||||
"context_id" => @course.id,
|
||||
"context_name" => "Unnamed Course",
|
||||
"data" => updated_data,
|
||||
"permissions" => { "manage" => true },
|
||||
"assessed_assignment" => false })
|
||||
end
|
||||
end
|
||||
|
||||
describe "get grading scheme" do
|
||||
it "returns course level grading scheme json" do
|
||||
data = [{ "name" => "A", "value" => 0.92 },
|
||||
{ "name" => "A-", "value" => 0.9 },
|
||||
{ "name" => "B+", "value" => 0.87 },
|
||||
{ "name" => "B", "value" => 0.82 },
|
||||
{ "name" => "B-", "value" => 0.8 },
|
||||
{ "name" => "C+", "value" => 0.77 },
|
||||
{ "name" => "C", "value" => 0.72 },
|
||||
{ "name" => "C-", "value" => 0.7 },
|
||||
{ "name" => "D+", "value" => 0.67 },
|
||||
{ "name" => "D", "value" => 0.62 },
|
||||
{ "name" => "D-", "value" => 0.61 },
|
||||
{ "name" => "F", "value" => 0.0 }]
|
||||
course_level_grading_standard = @course.grading_standards.build(title: "My Grading Scheme", data: GradingSchemesJsonController.to_grading_standard_data(data))
|
||||
course_level_grading_standard.save
|
||||
|
||||
user_session(@teacher)
|
||||
get "/courses/" + @course.id.to_s + "/grading_schemes/" + course_level_grading_standard.id.to_s, as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
response_json = response.parsed_body
|
||||
|
||||
expect(response_json).to eq({ "id" => course_level_grading_standard.id.to_s,
|
||||
"title" => "My Grading Scheme",
|
||||
"context_type" => "Course",
|
||||
"context_id" => @course.id,
|
||||
"context_name" => "Unnamed Course",
|
||||
"data" => data,
|
||||
"permissions" => { "manage" => true },
|
||||
"assessed_assignment" => false })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue