|
|
|
|
@ -52,48 +52,85 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the current user is support" do |
|
|
|
|
let(:support_user) { build(:user, :support) } |
|
|
|
|
let(:owning_org_user) { create(:user) } |
|
|
|
|
let(:managing_org_user) { create(:user) } |
|
|
|
|
let(:support_user) { create(:user, :support, organisation: owning_org_user.organisation) } |
|
|
|
|
|
|
|
|
|
it "is shown in check answers" do |
|
|
|
|
expect(question.hidden_in_check_answers?(nil, support_user)).to be false |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "#displayed_answer_options" do |
|
|
|
|
let(:lettings_log) do |
|
|
|
|
create(:lettings_log, created_by: support_user, owning_organisation: owning_org_user.organisation, managing_organisation: managing_org_user.organisation) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
let(:expected_answer_options) do |
|
|
|
|
{ |
|
|
|
|
"" => "Select an option", |
|
|
|
|
managing_org_user.id => "#{managing_org_user.name} (#{managing_org_user.email})", |
|
|
|
|
owning_org_user.id => "#{owning_org_user.name} (#{owning_org_user.email})", |
|
|
|
|
support_user.id => "#{support_user.name} (#{support_user.email})", |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "only displays users that belong to owning and managing organisations" do |
|
|
|
|
expect(question.displayed_answer_options(lettings_log, support_user)).to eq(expected_answer_options) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the current user is daa coordinator" do |
|
|
|
|
let(:user) { build(:user, :data_coordinator) } |
|
|
|
|
context "when the current user is data_coordinator" do |
|
|
|
|
let(:managing_org_user) { create(:user) } |
|
|
|
|
let(:data_coordinator) { create(:user, :data_coordinator) } |
|
|
|
|
|
|
|
|
|
it "is shown in check answers" do |
|
|
|
|
expect(question.hidden_in_check_answers?(nil, user)).to be false |
|
|
|
|
expect(question.hidden_in_check_answers?(nil, data_coordinator)).to be false |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the current user is not support" do |
|
|
|
|
let(:user) { build(:user) } |
|
|
|
|
describe "#displayed_answer_options" do |
|
|
|
|
let(:lettings_log) do |
|
|
|
|
create(:lettings_log, created_by: data_coordinator, owning_organisation: data_coordinator.organisation, managing_organisation: managing_org_user.organisation) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "is not shown in check answers" do |
|
|
|
|
expect(question.hidden_in_check_answers?(nil, user)).to be true |
|
|
|
|
let(:user_in_same_org) { create(:user, organisation: data_coordinator.organisation) } |
|
|
|
|
|
|
|
|
|
let(:expected_answer_options) do |
|
|
|
|
{ |
|
|
|
|
"" => "Select an option", |
|
|
|
|
data_coordinator.id => "#{data_coordinator.name} (#{data_coordinator.email})", |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "only displays users that belong user's org" do |
|
|
|
|
expect(question.displayed_answer_options(lettings_log, data_coordinator)).to eq(expected_answer_options) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the owning organisation is already set" do |
|
|
|
|
let(:lettings_log) do |
|
|
|
|
create( |
|
|
|
|
:lettings_log, |
|
|
|
|
created_by: user_2, |
|
|
|
|
owning_organisation: user_2.organisation, |
|
|
|
|
managing_organisation: user_3.organisation, |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
let(:expected_answer_options) do |
|
|
|
|
{ |
|
|
|
|
"" => "Select an option", |
|
|
|
|
user_2.id => "#{user_2.name} (#{user_2.email})", |
|
|
|
|
user_3.id => "#{user_3.name} (#{user_3.email})", |
|
|
|
|
} |
|
|
|
|
context "when the current user is data_provider" do |
|
|
|
|
let(:data_provider) { create(:user, :data_provider) } |
|
|
|
|
|
|
|
|
|
it "is not shown in check answers" do |
|
|
|
|
expect(question.hidden_in_check_answers?(nil, data_provider)).to be true |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "only displays users that belong to that organisation" do |
|
|
|
|
expect(question.displayed_answer_options(lettings_log)).to eq(expected_answer_options) |
|
|
|
|
describe "#displayed_answer_options" do |
|
|
|
|
let(:owning_org_user) { create(:user) } |
|
|
|
|
let(:lettings_log) { create(:lettings_log, owning_organisation: owning_org_user.organisation) } |
|
|
|
|
let(:user_in_same_org) { create(:user, organisation: data_provider.organisation) } |
|
|
|
|
|
|
|
|
|
let(:expected_answer_options) do |
|
|
|
|
{ |
|
|
|
|
"" => "Select an option", |
|
|
|
|
user_in_same_org.id => "#{user_in_same_org.name} (#{user_in_same_org.email})", |
|
|
|
|
data_provider.id => "#{data_provider.name} (#{data_provider.email})", |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "only displays users that belong user's org" do |
|
|
|
|
expect(question.displayed_answer_options(lettings_log, data_provider)).to eq(Form::Common::Questions::CreatedById::ANSWER_OPTS) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|