Browse Source

Additional feature tests for log creation (#695)

pull/647/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
c8edd8b5d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 68
      spec/features/log_spec.rb

68
spec/features/log_spec.rb

@ -56,4 +56,72 @@ RSpec.describe "Log Features" do
end end
end end
end end
context "when the signed is user is a Support user" do
let(:support_user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now) }
let(:devise_notify_mailer) { DeviseNotifyMailer.new }
let(:notify_client) { instance_double(Notifications::Client) }
let(:mfa_template_id) { User::MFA_TEMPLATE_ID }
let(:otp) { "999111" }
before do
allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer)
allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client)
allow(notify_client).to receive(:send_email).and_return(true)
allow(SecureRandom).to receive(:random_number).and_return(otp)
visit("/account/sign-in")
fill_in("user[email]", with: support_user.email)
fill_in("user[password]", with: support_user.password)
click_button("Sign in")
fill_in("code", with: otp)
click_button("Submit")
end
context "when completing the setup log section" do
it "includes the organisation and created by questions" do
visit("/logs")
click_button("Create a new lettings log")
click_link("Set up this lettings log")
select(support_user.organisation.name, from: "case-log-owning-organisation-id-field")
click_button("Save and continue")
select(support_user.name, from: "case-log-created-by-id-field")
click_button("Save and continue")
log_id = page.current_path.scan(/\d/).join
visit("logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Owning organisation #{support_user.organisation.name}")
expect(page).to have_content("User #{support_user.name}")
expect(page).to have_content("You have answered 2 of 7 questions")
end
end
end
context "when the signed is user is not a Support user" do
let(:support_user) { FactoryBot.create(:user) }
let(:devise_notify_mailer) { DeviseNotifyMailer.new }
let(:notify_client) { instance_double(Notifications::Client) }
before do
allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer)
allow(devise_notify_mailer).to receive(:notify_client).and_return(notify_client)
allow(notify_client).to receive(:send_email).and_return(true)
visit("/account/sign-in")
fill_in("user[email]", with: support_user.email)
fill_in("user[password]", with: support_user.password)
click_button("Sign in")
end
context "when completing the setup log section" do
it "does not include the organisation and created by questions" do
visit("/logs")
click_button("Create a new lettings log")
click_link("Set up this lettings log")
log_id = page.current_path.scan(/\d/).join
expect(page).to have_current_path("/logs/#{log_id}/needs-type")
visit("logs/#{log_id}/setup/check-answers")
expect(page).not_to have_content("Owning organisation #{support_user.organisation.name}")
expect(page).not_to have_content("User #{support_user.name}")
expect(page).to have_content("You have answered 0 of 5 questions")
end
end
end
end end

Loading…
Cancel
Save