Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

139 lines
4.2 KiB

require "rails_helper"
RSpec.describe UserHelper do
let(:current_user) { FactoryBot.create(:user, :data_coordinator) }
let(:user) { FactoryBot.create(:user, :data_coordinator) }
describe "aliased_user_edit" do
context "when the current logged in user is the same as the user being viewed" do
let(:user) { current_user }
it "returns the edit account path" do
expect(aliased_user_edit(user, current_user)).to eq(edit_account_path)
end
end
context "when the current logged in user is not the same as the user being viewed" do
it "returns the edit user path" do
expect(aliased_user_edit(user, current_user)).to eq(edit_user_path(user))
end
end
end
describe "pronoun" do
context "when the current logged in user is the same as the user being viewed" do
let(:user) { current_user }
it "returns 'you'" do
expect(pronoun(user, current_user)).to eq("you")
end
end
context "when the current logged in user is not the same as the user being viewed" do
it "returns 'they'" do
expect(pronoun(user, current_user)).to eq("they")
end
end
end
describe "change button permissions" do
context "when the user is a data provider viewing their own details" do
let(:current_user) { FactoryBot.create(:user, :data_provider) }
let(:user) { current_user }
it "allows changing name" do
expect(can_edit_names?(user, current_user)).to be true
end
it "allows changing email" do
expect(can_edit_emails?(user, current_user)).to be true
end
it "allows changing password" do
expect(can_edit_password?(user, current_user)).to be true
end
it "does not allow changing roles" do
expect(can_edit_roles?(user, current_user)).to be false
end
it "does not allow changing dpo" do
expect(can_edit_dpo?(user, current_user)).to be false
end
it "does not allow changing key contact" do
expect(can_edit_key_contact?(user, current_user)).to be false
end
end
context "when the user is a data coordinator viewing another user's details" do
it "allows changing name" do
expect(can_edit_names?(user, current_user)).to be true
end
it "allows changing email" do
expect(can_edit_emails?(user, current_user)).to be true
end
it "allows changing password" do
expect(can_edit_password?(user, current_user)).to be false
end
it "does not allow changing roles" do
expect(can_edit_roles?(user, current_user)).to be true
end
it "does not allow changing dpo" do
expect(can_edit_dpo?(user, current_user)).to be true
end
it "does not allow changing key contact" do
expect(can_edit_key_contact?(user, current_user)).to be true
end
context "when the user is a data coordinator viewing their own details" do
let(:user) { current_user }
it "allows changing password" do
expect(can_edit_password?(user, current_user)).to be true
end
end
end
context "when the user is a support user viewing another user's details" do
let(:current_user) { FactoryBot.create(:user, :support) }
it "allows changing name" do
expect(can_edit_names?(user, current_user)).to be true
end
it "allows changing email" do
expect(can_edit_emails?(user, current_user)).to be true
end
it "allows changing password" do
expect(can_edit_password?(user, current_user)).to be false
end
it "does not allow changing roles" do
expect(can_edit_roles?(user, current_user)).to be true
end
it "does not allow changing dpo" do
expect(can_edit_dpo?(user, current_user)).to be true
end
it "does not allow changing key contact" do
expect(can_edit_key_contact?(user, current_user)).to be true
end
context "when the user is a support user viewing their own details" do
let(:user) { current_user }
it "allows changing password" do
expect(can_edit_password?(user, current_user)).to be true
end
end
end
end
end