-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a DsiUserSession record when creating or updating the user
We only do this if supplied an optional role. Bypass mechanisisms will still function without a role.
- Loading branch information
Showing
3 changed files
with
40 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
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,3 @@ | ||
class DsiUserSession < ApplicationRecord | ||
belongs_to :dsi_user | ||
end |
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 |
---|---|---|
|
@@ -3,7 +3,18 @@ | |
RSpec.describe DsiUser, type: :model do | ||
describe ".create_or_update_from_dsi" do | ||
let(:dsi_payload) do | ||
OmniAuth::AuthHash.new(uid: "123456", info: { email:, first_name: "John", last_name: "Doe" }) | ||
OmniAuth::AuthHash.new( | ||
uid: "123456", | ||
info: { email:, first_name: "John", last_name: "Doe" }, | ||
extra: { | ||
raw_info: { | ||
organisation: { | ||
id: "09876", | ||
name: "Test Org", | ||
} | ||
} | ||
} | ||
) | ||
end | ||
let(:email) { "[email protected]" } | ||
|
||
|
@@ -32,5 +43,19 @@ | |
expect(dsi_user.last_name).to eq dsi_payload.info.last_name | ||
end | ||
end | ||
|
||
context "when the user has a role" do | ||
it "creates a session record" do | ||
role = { "id" => "123", "code" => "TestRole_code" } | ||
described_class.create_or_update_from_dsi(dsi_payload, role) | ||
|
||
dsi_user_session = DsiUser.first.dsi_user_sessions.first | ||
expect(dsi_user_session).to be_present | ||
expect(dsi_user_session.role_id).to eq "123" | ||
expect(dsi_user_session.role_code).to eq "TestRole_code" | ||
expect(dsi_user_session.organisation_id).to eq "09876" | ||
expect(dsi_user_session.organisation_name).to eq "Test Org" | ||
end | ||
end | ||
end | ||
end |