-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
require "rails_helper" | ||
|
||
RSpec.feature "Early years payment provider" do | ||
let(:journey_session) { Journeys::EarlyYearsPayment::Provider::Session.last } | ||
|
||
scenario "happy path claim" do | ||
when_early_years_payment_provider_journey_configuration_exists | ||
|
||
|
@@ -17,13 +19,14 @@ | |
expect(page).to have_content("We have sent an email to [email protected]") | ||
|
||
mail = ActionMailer::Base.deliveries.last | ||
mail_personalisation = mail[:personalisation].unparsed_value | ||
expect(mail_personalisation[:one_time_password]).to match(/\A\d{6}\Z/) | ||
|
||
# TODO - uncomment below when magic link functionality in place | ||
# expect(page).to have_content("Declaration of Employee Consent") | ||
# check "I confirm that I have obtained consent from my employee and have provided them with the relevant privacy notice." | ||
# click_button "Continue" | ||
otp = mail[:personalisation].unparsed_value[:one_time_password] | ||
expect(otp).to match(/\A\d{6}\Z/) | ||
|
||
visit claim_path(Journeys::EarlyYearsPayment::Provider::ROUTING_NAME, :consent, code: otp) | ||
expect(journey_session.reload.answers.email_verified).to be true | ||
expect(page).to have_content("Declaration of Employee Consent") | ||
check "I confirm that I have obtained consent from my employee and have provided them with the relevant privacy notice." | ||
click_button "Continue" | ||
end | ||
|
||
scenario "send another link" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
|
||
let(:journey) { Journeys::EarlyYearsPayment::Provider } | ||
let(:journey_session) { build(:early_years_payment_provider_session) } | ||
# let(:params) { ActionController::Parameters.new({journey: "test-journey", slug: "test_slug", claim: claim_params}) } | ||
|
||
let(:params) do | ||
ActionController::Parameters.new(claim: {email_address: email_address}) | ||
|
@@ -18,6 +17,22 @@ | |
describe "#save" do | ||
subject { form.save } | ||
|
||
around do |example| | ||
travel_to DateTime.new(2024, 1, 1, 12, 0, 0) do | ||
example.run | ||
end | ||
end | ||
|
||
before do | ||
allow(OneTimePassword::Generator).to receive(:new).and_return( | ||
instance_double(OneTimePassword::Generator, code: "111111") | ||
) | ||
end | ||
|
||
let(:policy) { journey_session.answers.policy } | ||
let(:claim_subject) { I18n.t("#{policy.locale_key}.claim_subject") } | ||
let(:email_subject) { claim_subject } | ||
|
||
it { should be_truthy } | ||
|
||
it "sets the email address" do | ||
|
@@ -26,5 +41,51 @@ | |
eq(email_address) | ||
) | ||
end | ||
|
||
it "sends an email" do | ||
subject | ||
|
||
expect(email_address).to have_received_email( | ||
"e0b78a08-601b-40ba-a97f-61fb00a7c951", | ||
email_subject: email_subject, | ||
one_time_password: "111111" | ||
) | ||
end | ||
|
||
it "updates sent_one_time_password_at" do | ||
subject | ||
expect(journey_session.answers.sent_one_time_password_at).to( | ||
eq(DateTime.new(2024, 1, 1, 12, 0, 0)) | ||
) | ||
end | ||
|
||
it "resets email_verified" do | ||
subject | ||
expect(journey_session.answers.email_verified).to be_nil | ||
end | ||
|
||
context "when the email address has been previously verified, and a new one is submitted" do | ||
before do | ||
journey_session.answers.assign_attributes(email_address: "[email protected]", email_verified: true) | ||
journey_session.save! | ||
end | ||
|
||
it "resets email_verified" do | ||
subject | ||
expect(journey_session.answers.email_verified).to be_nil | ||
end | ||
end | ||
|
||
context "when the email address submitted has been previously verified, and is the same" do | ||
before do | ||
journey_session.answers.assign_attributes(email_address: email_address, email_verified: true) | ||
journey_session.save! | ||
end | ||
|
||
it "returns email_verified" do | ||
subject | ||
expect(journey_session.answers.email_verified).to be true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters