Skip to content

Commit

Permalink
Merge pull request #1138 from concord-consortium/180951212-add-user-t…
Browse files Browse the repository at this point in the history
…o-user-report

Added user and portal_url to external report queries [#180951212]
  • Loading branch information
dougmartin authored Oct 26, 2022
2 parents 7d08dfb + 743f305 commit e24addd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def external_report_query_jwt
id: url_for(current_user),
email: current_user.email
},
portal_url: root_url,
learnersApiUrl: external_report_learners_from_jwt_api_v1_report_learners_es_url
}
}
Expand Down
5 changes: 5 additions & 0 deletions rails/app/controllers/api/v1/report_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def external_report_query
type: "users",
version: "1.0",
domain: URI.parse(APP_CONFIG[:site_url]).host,
user: {
id: url_for(current_user),
email: current_user.email
},
portal_url: root_url,
users: users,
runnables: runnables,
start_date: params[:start_date],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def set_jwt_bearer_token(auth_token)
let(:simple_user) { FactoryBot.create(:confirmed_user, :login => "authorized_student") }
let(:manager_user) { FactoryBot.generate(:manager_user) }

let(:url_for_admin_user) { "http://test.host/users/#{admin_user.id}" } # can't use url_for(user) helper in specs

let(:district) { FactoryBot.create(:portal_district) }
let(:mock_school) { FactoryBot.create(:portal_school, {:district => district}) }
let(:teacher_user1) { FactoryBot.create(:confirmed_user, login: "teacher_user1") }
Expand Down Expand Up @@ -211,8 +213,6 @@ def set_jwt_bearer_token(auth_token)
end
end
describe "GET external_report_query" do
let(:url_for_user) { "http://test.host/users/#{admin_user.id}" } # can't use url_for(user) helper in specs

it "allows index" do
get :external_report_query
expect(response.status).to eql(200)
Expand All @@ -238,7 +238,7 @@ def set_jwt_bearer_token(auth_token)
expect(filter["learners"][1]["run_remote_endpoint"]).to eq learner2.remote_endpoint_url
expect(filter["learners"][1]["class_id"]).to eq learner2.offering.clazz_id
expect(filter["learners"][2]["runnable_url"]).to eq nil # nil because it is in investigation
expect(filter["user"]["id"]).to eq url_for_user
expect(filter["user"]["id"]).to eq url_for_admin_user
expect(filter["user"]["email"]).to eq admin_user.email

expect(resp["signature"]).to eq OpenSSL::HMAC.hexdigest("SHA256", SignedJWT.hmac_secret, resp["json"].to_json)
Expand Down Expand Up @@ -350,13 +350,16 @@ def set_jwt_bearer_token(auth_token)
sign_in admin_user
end
describe "GET external_report_jwt_query" do

it "renders response that includes Log Manager query and JWT" do
get :external_report_query_jwt
resp = JSON.parse(response.body)
filter = resp["json"]
expect(filter["type"]).to eq "learners"
expect(filter["version"]).to eq "2"
expect(filter["query"]).not_to eq nil
expect(filter["user"]["id"]).to eq url_for_admin_user
expect(filter["user"]["email"]).to eq admin_user.email
expect(filter["portal_url"]).to eq "http://test.host/"
expect(filter["learnersApiUrl"]).to eq "http://test.host/api/v1/report_learners_es/external_report_learners_from_jwt"
expect(resp["token"]).to be_an_instance_of(String)
expect(resp["signature"]).to eq nil
Expand Down
5 changes: 5 additions & 0 deletions rails/spec/controllers/api/v1/report_users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
end
end
describe "GET external_report_query" do
let(:url_for_user) { "http://test.host/users/#{admin_user.id}" } # can't use url_for(user) helper in specs

before(:each) do
@old_configuration = APP_CONFIG[:site_url]
APP_CONFIG[:site_url] = 'http://example.com'
Expand All @@ -137,6 +139,9 @@
expect(filter["type"]).to eq "users"
expect(filter["version"]).to eq "1.0"
expect(filter["domain"]).to eq "example.com"
expect(filter["user"]["id"]).to eq url_for_user
expect(filter["user"]["email"]).to eq admin_user.email
expect(filter["portal_url"]).to eq "http://test.host/"
expect(filter["users"].length).to eq 5
expect(filter["runnables"].length).to eq 3
expect(filter["start_date"]).to eq "01/02/19"
Expand Down

0 comments on commit e24addd

Please sign in to comment.