Skip to content

Commit

Permalink
return :value for mailer if object doesn't match (#1283)
Browse files Browse the repository at this point in the history
* return 403 if token is expired and add spec

* else statement for email value in pin confirm

* keep 500 error
  • Loading branch information
mwvolo authored Nov 19, 2024
1 parent a952585 commit bebeb69
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
2 changes: 2 additions & 0 deletions app/routines/confirm_by_pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def self.sequential_failure_for(contact_info)
:value
when PreAuthState
:contact_info_value
else
:value
end

SequentialFailure.confirm_by_pin
Expand Down
51 changes: 17 additions & 34 deletions spec/mailers/newflow_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,28 @@

module Newflow
describe NewflowMailer, type: :mailer do
# let(:user) { FactoryBot.create :user, first_name: 'John', last_name: 'Doe', suffix: 'Jr.' }
# let(:email) { FactoryBot.create :email_address, value: 'to@example.org',
# user_id: user.id, confirmation_code: '1234', confirmation_pin: '123456' }
let(:user) { FactoryBot.create :user, first_name: 'John', last_name: 'Doe', suffix: 'Jr.' }
let(:email) { FactoryBot.create :email_address, value: 'to@example.org',
user_id: user.id, confirmation_code: '1234', confirmation_pin: '123456' }

describe '' do
# it 'has basic header and from info and greeting' do
# mail = ConfirmationMailer.instructions email_address: email
describe 'sends email confirmation' do
it 'has basic header and from info and greeting' do
mail = NewflowMailer.signup_email_confirmation email_address: email

# expect(mail.header['to'].to_s).to eq('"John Doe Jr." <to@example.org>')
# expect(mail.from).to eq(["noreply@openstax.org"])
# expect(mail.body.encoded).to include("Hi #{user.casual_name}")
# end
expect(mail.header['to'].to_s).to eq('to@example.org')
expect(mail.from).to eq(["noreply@openstax.org"])
expect(mail.body.encoded).to include("Welcome to OpenStax!")
end

# it 'does not include PIN when directed not to' do
# mail = ConfirmationMailer.instructions email_address: email, send_pin: false
it "has PIN info" do
allow(ConfirmByPin).to receive(:sequential_failure_for) { Hashie::Mash.new('attempts_remaining?' => true)}

# expect(mail.subject).to eq("[OpenStax] Confirm your email address")
# expect(mail.body.encoded).not_to include('Your PIN')
# end
mail = NewflowMailer.signup_email_confirmation email_address: email

# it "has PIN info when PIN attempts remain" do
# allow(ConfirmByPin).to receive(:sequential_failure_for) { Hashie::Mash.new('attempts_remaining?' => true)}

# mail = ConfirmationMailer.instructions email_address: email, send_pin: true

# expect(mail.subject).to eq("[OpenStax] Use PIN 123456 to confirm your email address")
# expect(mail.body.encoded).to include('Enter your 6-digit')
# expect(mail.body.encoded).to include('Your PIN: <b>123456</b>')
# end

# it "has just link when no PIN attempts remain" do
# allow(ConfirmByPin).to receive(:sequential_failure_for) { Hashie::Mash.new('attempts_remaining?' => false)}

# mail = ConfirmationMailer.instructions email_address: email, send_pin: true

# expect(mail.subject).to eq("[OpenStax] Confirm your email address")
# expect(mail.body.encoded).to include('Click on the link below')
# expect(mail.body.encoded).not_to include('Your PIN')
# end
expect(mail.subject).to eq("[OpenStax] Your OpenStax account PIN has arrived: 123456")
expect(mail.body.encoded).to include('<a href="http://localhost:2999/i/verify_email_by_code/1234"')
expect(mail.body.encoded).to include('use your pin: <b id=\'pin\'>123456</b>')
end
end
end
end

0 comments on commit bebeb69

Please sign in to comment.