-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for signing in with access code
- Loading branch information
1 parent
934d387
commit 7e98bcd
Showing
5 changed files
with
100 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe "log in with access code", type: :system do | ||
let!(:organization) { create(:organization) } | ||
let(:access_code) { "ABCDE12345" } | ||
let(:incorrect_code) { "FalseCode" } | ||
|
||
include_context "with single access code" | ||
before do | ||
switch_to_host(organization.host) | ||
visit_helsinki_smsauth | ||
click_link "Log in with a code given by your teacher" | ||
end | ||
|
||
it "does not authenticate when incorrect code" do | ||
fill_in "sms_verification[access_code]", with: incorrect_code | ||
click_button "Log in" | ||
within_flash_messages do | ||
expect(page).to have_content("Failed to verify the access code. Make sure that you have entered the correct code and try again.") | ||
end | ||
expect(page).to have_current_path("/users/auth/sms/access_code_validation") | ||
end | ||
|
||
context "when correct code" do | ||
let!(:auth_metadata) { { school: "0004", grade: 1, phone_number: "+3584551122334" } } | ||
let!(:creator) { create(:user, :confirmed, :admin, organization: organization) } | ||
let!(:signin_code_set) { create(:signin_code_set, creator: creator) } | ||
let!(:signin_code) { create(:signin_code, code: access_code, signin_code_set: signin_code_set) } | ||
|
||
it "creates users and signs in with correct code" do | ||
expect(signin_code_set.used_code_amount).to eq(0) | ||
|
||
# digest = "#{access_code}-#{Rails.application.secrets.secret_key_base}" | ||
# puts "TEST:digest is: #{digest} " | ||
# puts "TEST: the code hash is:#{Digest::MD5.hexdigest(digest)}" | ||
# puts "The access code is #{::Decidim::HelsinkiSmsauth::SigninCode.last.code_hash}" | ||
|
||
fill_in "sms_verification[access_code]", with: access_code | ||
click_button "Log in" | ||
expect(page).to have_content("Login successful.") | ||
signin_code_set.reload | ||
expect(signin_code_set.used_code_amount).to eq(1) | ||
|
||
expect(page).to have_current_path("/authorizations") | ||
authorization = Decidim::Authorization.last | ||
expect(authorization.metadata["school"]).to eq(signin_code_set.metadata["school"]) | ||
expect(authorization.metadata["grade"]).to eq(signin_code_set.metadata["grade"]) | ||
within_flash_messages do | ||
expect(page).to have_content "Login successful" | ||
end | ||
end | ||
end | ||
end |