Browse Source

test: add tests for path

pull/1265/head
natdeanlewissoftwire 3 years ago
parent
commit
d4157f50e5
  1. 1
      db/schema.rb
  2. 20
      spec/mailers/devise_notify_mailer_spec.rb
  3. 26
      spec/requests/auth/confirmations_controller_spec.rb

1
db/schema.rb

@ -510,7 +510,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_03_174815) do
t.integer "old_persons_shared_ownership_value_check"
t.integer "staircase_bought_value_check"
t.integer "monthly_charges_value_check"
t.integer "saledate_check"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

20
spec/mailers/devise_notify_mailer_spec.rb

@ -51,5 +51,25 @@ RSpec.describe DeviseNotifyMailer do
end
end
end
context "when a user is invited for the first time" do
let(:email) { "test@example.com" }
it "sends initial confirmation template" do
expect(notify_client).to receive(:send_email).with(hash_including(template_id: User::CONFIRMABLE_TEMPLATE_ID))
User.create!(name:, organisation:, email:, password:, role:)
end
end
context "when a user requests a new confirmation link" do
let(:email) { "test@example.com" }
it "sends re-confirmation template" do
user = User.create!(name:, organisation:, email:, password:, role:)
expect(notify_client).to receive(:send_email).with(hash_including(template_id: User::RECONFIRMABLE_TEMPLATE_ID))
user.send_confirmation_instructions
end
end
end
end

26
spec/requests/auth/confirmations_controller_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Auth::ConfirmationsController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:notify_client) { instance_double(Notifications::Client) }
let(:devise_notify_mailer) { DeviseNotifyMailer.new }
let(:user) { FactoryBot.create(:user, :data_provider, sign_in_count: 0, confirmed_at: nil) }
let(:user) { FactoryBot.create(:user, :data_provider, sign_in_count: 0, confirmed_at: nil, initial_confirmation_sent: nil) }
before do
allow(DeviseNotifyMailer).to receive(:new).and_return(devise_notify_mailer)
@ -39,11 +39,33 @@ RSpec.describe Auth::ConfirmationsController, type: :request do
get "/account/confirmation?confirmation_token=#{user.confirmation_token}"
end
it "shows the error page" do
it "shows the expired page" do
expect(page).to have_content("For security reasons, your join link expired - get another one using the button below (valid for 3 hours).")
end
end
context "when the token is blank" do
before do
user.send_confirmation_instructions
get "/account/confirmation"
end
it "shows the invalid page" do
expect(page).to have_content("It looks like you have requested a newer join link than this one. Check your emails and follow the most recent link instead.")
end
end
context "when the token is invalid" do
before do
user.send_confirmation_instructions
get "/account/confirmation?confirmation_token=SOMETHING_INVALID"
end
it "shows the invalid page" do
expect(page).to have_content("It looks like you have requested a newer join link than this one. Check your emails and follow the most recent link instead.")
end
end
context "when the user has already been confirmed" do
let(:user) { FactoryBot.create(:user, :data_provider, sign_in_count: 0, confirmed_at: Time.zone.now) }

Loading…
Cancel
Save