Skip to content

Commit

Permalink
Merge pull request #27 from wyeworks/feature/MER-879-grade-sync-schoo…
Browse files Browse the repository at this point in the history
…logy

[FEATURE] [MER-879] Grade sync schoology
  • Loading branch information
eliknebel authored Oct 5, 2022
2 parents 82b759b + 6b68ee5 commit a1d1c71
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/lti_1p3/tool/services/ags/line_item.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Lti_1p3.Tool.Services.AGS.LineItem do
@derive Jason.Encoder
@derive {Jason.Encoder, except: [:id]}
@enforce_keys [:scoreMaximum, :label, :resourceId]
defstruct [:id, :scoreMaximum, :label, :resourceId]

Expand Down
3 changes: 2 additions & 1 deletion lib/lti_1p3/tool/services/nrps.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ defmodule Lti_1p3.Tool.Services.NRPS do
defp headers(%AccessToken{} = access_token) do
[
{"Content-Type", "application/json"},
{"Authorization", "Bearer #{access_token.access_token}"}
{"Authorization", "Bearer #{access_token.access_token}"},
{"Accept", "application/vnd.ims.lti-nrps.v2.membershipcontainer+json"}
]
end
end
2 changes: 1 addition & 1 deletion test/lti_1p3/tool/services/ags_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ defmodule Lti_1p3.Tool.Services.AGSTest do
)
end

test "fetch line item set headers correctly", %{
test "fetch line item is build correctly with query params", %{
access_token: access_token
} do
expect(MockHTTPoison, :get, fn url, _headers ->
Expand Down
53 changes: 47 additions & 6 deletions test/lti_1p3/tool/services/nrps_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
defmodule Lti_1p3.Tool.Services.NRPSTest do
use ExUnit.Case, async: true

alias Lti_1p3.Tool.Services.NRPS
import Mox

alias Lti_1p3.Test.MockHTTPoison
alias Lti_1p3.Tool.Services.{AccessToken, NRPS}

@context_memberships_url "https://lms.example.edu/api/lti/courses/8/names_and_roles"

@lti_params %{
"aud" => "10000000000041",
Expand All @@ -23,7 +28,7 @@ defmodule Lti_1p3.Tool.Services.NRPSTest do
"validation_context" => nil
},
"https://purl.imsglobal.org/spec/lti-nrps/claim/namesroleservice" => %{
"context_memberships_url" => "https://lms.example.edu/api/lti/courses/8/names_and_roles",
"context_memberships_url" => @context_memberships_url,
"service_versions" => ["2.0"]
},
"https://purl.imsglobal.org/spec/lti/claim/context" => %{
Expand Down Expand Up @@ -88,10 +93,46 @@ defmodule Lti_1p3.Tool.Services.NRPSTest do
"sub" => "c36c3c87-993f-4d2e-9e22-e47d5d2637ae"
}

test "nrps" do
assert NRPS.nrps_enabled?(@lti_params)
describe "nrps" do
setup [:setup_session]

test "access to lti params is correct" do
assert NRPS.nrps_enabled?(@lti_params)

assert NRPS.get_context_memberships_url(@lti_params) ==
@context_memberships_url
end

test "nrps fetch memberships set headers correctly", %{
access_token: access_token
} do
expect(MockHTTPoison, :get, fn _url, headers ->
assert [
{"Content-Type", "application/json"},
{"Authorization", "Bearer fake_token"},
{"Accept", "application/vnd.ims.lti-nrps.v2.membershipcontainer+json"}
] == headers

{:ok, %HTTPoison.Response{status_code: 200, body: "{\"members\": []}"}}
end)

{:ok, _response} =
NRPS.fetch_memberships(
@context_memberships_url,
access_token
)
end
end

defp setup_session(_context) do
access_token = %AccessToken{
scope:
"https://purl.imsglobal.org/spec/lti-ags/scope/score https://purl.imsglobal.org/spec/lti-nrps/scope/contextmembership.readonly",
access_token: "fake_token",
token_type: "Bearer",
expires_in: 3_600
}

assert NRPS.get_context_memberships_url(@lti_params) ==
"https://lms.example.edu/api/lti/courses/8/names_and_roles"
{:ok, %{access_token: access_token}}
end
end

0 comments on commit a1d1c71

Please sign in to comment.