-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1278 from concord-consortium/187420676-research-c…
…lasses-no-archived-resources Filter out archived resources on Research Classes page, add basic Research Classes API tests
- Loading branch information
Showing
2 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
rails/spec/controllers/api/v1/research_classes_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
require 'spec_helper' | ||
|
||
describe API::V1::ResearchClassesController do | ||
|
||
before(:each) { | ||
# This silences warnings in the console when running | ||
generate_default_settings_with_mocks | ||
} | ||
|
||
before (:each) do | ||
@teacher1 = FactoryBot.create(:portal_teacher) | ||
@teacher2 = FactoryBot.create(:portal_teacher) | ||
|
||
@project1 = FactoryBot.create(:project, name: 'Project 1') | ||
@project2 = FactoryBot.create(:project, name: 'Project 2') | ||
|
||
@cohort1 = FactoryBot.create(:admin_cohort, project: @project1) | ||
@cohort2 = FactoryBot.create(:admin_cohort, project: @project2) | ||
|
||
@teacher1.cohorts << @cohort1 | ||
@teacher2.cohorts << @cohort2 | ||
|
||
# test different tools | ||
@runnable1 = FactoryBot.create(:external_activity) | ||
@runnable2 = FactoryBot.create(:external_activity) | ||
|
||
@offering1 = FactoryBot.create(:portal_offering, {clazz: @teacher1.clazzes[0], runnable: @runnable1}) | ||
@offering2 = FactoryBot.create(:portal_offering, {clazz: @teacher2.clazzes[0], runnable: @runnable2}) | ||
|
||
sign_in researcher | ||
end | ||
|
||
let(:researcher) do | ||
user = FactoryBot.create(:confirmed_user) | ||
user.add_role_for_project('researcher', @project1) | ||
user | ||
end | ||
|
||
describe "anonymous' access" do | ||
before (:each) do | ||
logout_user | ||
end | ||
describe "GET index" do | ||
it "wont allow index, returns error 403" do | ||
get :index | ||
expect(response.status).to eql(403) | ||
end | ||
end | ||
end | ||
|
||
describe "simple user access" do | ||
let(:simple_user) { FactoryBot.create(:confirmed_user, :login => "authorized_student") } | ||
before (:each) do | ||
sign_in simple_user | ||
end | ||
describe "GET index" do | ||
it "wont allow index, returns error 403" do | ||
get :index | ||
expect(response.status).to eql(403) | ||
end | ||
end | ||
end | ||
|
||
describe "project admin access" do | ||
before (:each) do | ||
project = FactoryBot.create(:project) | ||
user = FactoryBot.create(:confirmed_user) | ||
user.add_role_for_project('admin', project) | ||
sign_in user | ||
end | ||
|
||
describe "GET index" do | ||
it "allows index" do | ||
get :index | ||
expect(response.status).to eql(200) | ||
end | ||
end | ||
end | ||
|
||
describe "project researcher access" do | ||
before (:each) do | ||
sign_in researcher | ||
end | ||
|
||
describe "GET index" do | ||
it "allows index" do | ||
get :index | ||
expect(response.status).to eql(200) | ||
end | ||
end | ||
end | ||
|
||
describe "basic query" do | ||
describe "GET index" do | ||
let (:params) do | ||
{ | ||
project_id: "#{@project1.id}", | ||
cohorts: "#{@cohort1.id}", | ||
teachers: "#{@teacher1.id}", | ||
runnables: "#{@runnable1.id}" | ||
} | ||
end | ||
it "allows index" do | ||
get :index, params: params | ||
expect(response.status).to eql(200) | ||
end | ||
it "gets class info" do | ||
get :index, params: params | ||
json = JSON.parse(response.body) | ||
expect(response.status).to eql(200) | ||
clazz = @teacher1.clazzes[0] | ||
expect(json["hits"]).to eql({"classes"=>[{"class_url"=>materials_portal_clazz_url(clazz.id, researcher: true), "cohort_names"=>@cohort1.name, "id"=>clazz.id, "name"=>clazz.name, "school_name"=>@teacher1.school.name, "teacher_names"=>@teacher1.name}]}) | ||
end | ||
it "gets totals" do | ||
get :index, params: params | ||
json = JSON.parse(response.body) | ||
expect(response.status).to eql(200) | ||
expect(json["totals"]).to eql({"classes"=>1, "cohorts"=>1, "runnables"=>1, "teachers"=>1}) | ||
end | ||
it "gets all teachers" do | ||
params[:load_only] = "teachers" | ||
get :index, params: params | ||
json = JSON.parse(response.body) | ||
expect(response.status).to eql(200) | ||
expect(json["hits"]["teachers"].length).to eql(1) | ||
end | ||
it "gets all cohorts" do | ||
params[:load_only] = "cohorts" | ||
get :index, params: params | ||
json = JSON.parse(response.body) | ||
expect(response.status).to eql(200) | ||
expect(json["hits"]["cohorts"].length).to eql(1) | ||
expect(json["hits"]["cohorts"][0]).to eql({"id"=>@cohort1.id, "label"=>"Project 1: test cohort"}) | ||
end | ||
it "gets all runnables" do | ||
params[:load_only] = "runnables" | ||
get :index, params: params | ||
json = JSON.parse(response.body) | ||
expect(response.status).to eql(200) | ||
expect(json["hits"]["runnables"].length).to eql(1) | ||
end | ||
it "filters out archived runnables" do | ||
@runnable1.update_attribute(:is_archived, true) | ||
params[:load_only] = "runnables" | ||
get :index, params: params | ||
json = JSON.parse(response.body) | ||
expect(response.status).to eql(200) | ||
expect(json["hits"]["runnables"].length).to eql(0) | ||
end | ||
end | ||
end | ||
end |