-
Notifications
You must be signed in to change notification settings - Fork 166
LG-16017 Allow approving pending IPP enrollments in int #12014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eb2a543
fdbe78c
365765e
71d52b3
d1d4f89
824b16f
ec83ddd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Test::IppController do | ||
| describe 'GET index' do | ||
| context 'when allow_ipp_enrollment_approval? is true' do | ||
| it 'renders enrollments' do | ||
| allow(FeatureManagement).to receive(:allow_ipp_enrollment_approval?).and_return(true) | ||
|
|
||
| stub_sign_in | ||
| get :index | ||
|
|
||
| expect(response.status).to eq 200 | ||
| expect(response).to_not be_redirect | ||
| expect(subject).to render_template(:index) | ||
| end | ||
| end | ||
|
|
||
| context 'when allow_ipp_enrollment_approval? is false' do | ||
| it 'renders 404' do | ||
| allow(FeatureManagement).to receive(:allow_ipp_enrollment_approval?).and_return(false) | ||
|
|
||
| stub_sign_in | ||
| get :index | ||
|
|
||
| expect(response.status).to eq 404 | ||
| expect(response).to render_template('pages/page_not_found') | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'PUT update' do | ||
| context 'when allow_ipp_enrollment_approval? is true and pending enrollment is found' do | ||
| it 'updates the enrollment via a background job' do | ||
| allow(FeatureManagement).to receive(:allow_ipp_enrollment_approval?).and_return(true) | ||
| allow(Rails.env).to receive(:development?).and_return(true) | ||
|
|
||
| create( | ||
| :user, :with_phone, :with_pending_in_person_enrollment, password: 'p@assword!' | ||
| ) | ||
| job = instance_double(GetUspsProofingResultsJob) | ||
| allow(GetUspsProofingResultsJob).to receive(:new).and_return(job) | ||
| allow(job).to receive(:send).and_return(true) | ||
|
|
||
| stub_sign_in | ||
| put :update, params: { enrollment: InPersonEnrollment.last.id.to_s } | ||
|
|
||
| expect(response).to redirect_to test_ipp_url | ||
| expect(job).to have_received(:send) | ||
| end | ||
| end | ||
|
|
||
| context 'when allow_ipp_enrollment_approval? is true but enrollment is not found' do | ||
| it 'redirects to ipp_test_url with flash error' do | ||
| allow(FeatureManagement).to receive(:allow_ipp_enrollment_approval?).and_return(true) | ||
| allow(Rails.env).to receive(:development?).and_return(true) | ||
|
|
||
| stub_sign_in | ||
| put :update, params: { enrollment: '1' } | ||
|
|
||
| expect(response).to redirect_to test_ipp_url | ||
| expect(flash[:error]).to eq 'Could not find pending IPP enrollment with ID 1' | ||
| end | ||
| end | ||
|
|
||
| context 'when Rails env is not development and enrollment id belongs to current user' do | ||
| it 'updates the enrollment via a background job' do | ||
| allow(FeatureManagement).to receive(:allow_ipp_enrollment_approval?).and_return(true) | ||
| allow(Rails.env).to receive(:development?).and_return(false) | ||
|
|
||
| user = create( | ||
| :user, :with_phone, :with_pending_in_person_enrollment, password: 'p@assword!' | ||
| ) | ||
| job = instance_double(GetUspsProofingResultsJob) | ||
| allow(GetUspsProofingResultsJob).to receive(:new).and_return(job) | ||
| allow(job).to receive(:send).and_return(true) | ||
|
|
||
| stub_sign_in(user) | ||
| put :update, params: { enrollment: InPersonEnrollment.last.id.to_s } | ||
|
|
||
| expect(response).to redirect_to test_ipp_url | ||
| expect(job).to have_received(:send) | ||
| end | ||
| end | ||
|
|
||
| context 'when Rails env is not development and enrollment id does not belong to current user' do | ||
| it 'does not update the enrollment' do | ||
| allow(FeatureManagement).to receive(:allow_ipp_enrollment_approval?).and_return(true) | ||
| allow(Rails.env).to receive(:development?).and_return(false) | ||
|
|
||
| first_user = create( | ||
| :user, :with_phone, :with_pending_in_person_enrollment, password: 'p@assword!' | ||
| ) | ||
| second_user = create( | ||
| :user, :with_phone, :with_pending_in_person_enrollment, password: 'p@assword!' | ||
| ) | ||
| job = instance_double(GetUspsProofingResultsJob) | ||
| allow(GetUspsProofingResultsJob).to receive(:new).and_return(job) | ||
| allow(job).to receive(:send).and_return(true) | ||
|
|
||
| enrollment_id_for_first_user = InPersonEnrollment.find_by(user_id: first_user.id).id | ||
|
|
||
| stub_sign_in(second_user) | ||
| put :update, params: { enrollment: enrollment_id_for_first_user } | ||
|
|
||
| expect(response).to redirect_to test_ipp_url | ||
| expect(job).not_to have_received(:send) | ||
| expect(flash[:error]) | ||
| .to eq "Could not find pending IPP enrollment with ID #{enrollment_id_for_first_user}" | ||
| end | ||
| end | ||
|
|
||
| context 'when allow_ipp_enrollment_approval? is false' do | ||
| it 'renders 404' do | ||
| allow(FeatureManagement).to receive(:allow_ipp_enrollment_approval?).and_return(false) | ||
|
|
||
| stub_sign_in | ||
| put :update | ||
|
|
||
| expect(response.status).to eq 404 | ||
| expect(response).to render_template('pages/page_not_found') | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| require 'rails_helper' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend moving setup, such as allow statements and factory bot usage, out of it blocks.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you mean putting them in a Here are relevant resources that I agree with: https://thoughtbot.com/blog/a-journey-towards-better-testing-practices
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize that the testing practices I advocate for represent one side of the story, so I'd love to learn more about your recommendation to move the setup outside of the Either way, I'd be curious to understand the reasoning behind moving stuff outside the And I'd be curious what you think of the articles above. |
||
|
|
||
| RSpec.describe 'Approving Pending IPP Enrollments' do | ||
| context 'when Rails env is not development' do | ||
| it 'only shows pending enrollments for the current user' do | ||
| allow(FeatureManagement).to receive(:allow_ipp_enrollment_approval?).and_return(true) | ||
|
|
||
| first_user = create( | ||
| :user, :with_phone, :with_pending_in_person_enrollment, password: 'p@assword!' | ||
| ) | ||
| second_user = create( | ||
| :user, :with_phone, :with_pending_in_person_enrollment, password: 'p@assword!' | ||
| ) | ||
|
|
||
| sign_in_and_2fa_user(first_user) | ||
| visit test_ipp_path | ||
|
|
||
| expect(page).to have_content(first_user.uuid) | ||
| expect(page).not_to have_content(second_user.uuid) | ||
| end | ||
| end | ||
|
|
||
| context 'when Rails env is development' do | ||
| it 'shows all pending enrollments', allow_browser_log: true do | ||
| allow(FeatureManagement).to receive(:allow_ipp_enrollment_approval?).and_return(true) | ||
| allow(Rails.env).to receive(:development?).and_return(true) | ||
|
|
||
| first_user = create( | ||
| :user, :with_phone, :with_pending_in_person_enrollment, password: 'p@assword!' | ||
| ) | ||
| second_user = create( | ||
| :user, :with_phone, :with_pending_in_person_enrollment, password: 'p@assword!' | ||
| ) | ||
|
|
||
| sign_in_and_2fa_user(second_user) | ||
| visit test_ipp_path | ||
|
|
||
| expect(page).to have_content(first_user.uuid) | ||
| expect(page).to have_content(second_user.uuid) | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -537,4 +537,26 @@ | |
| end | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend moving setup out of it blocks. |
||
| end | ||
| end | ||
|
|
||
| describe 'allow_ipp_enrollment_approval?' do | ||
| context 'when IdentityConfig.store.in_person_enrollments_immediate_approval_enabled is true' do | ||
| it 'returns true' do | ||
| allow(IdentityConfig.store).to receive(:in_person_enrollments_immediate_approval_enabled) | ||
| .and_return(true) | ||
| allow(Rails.env).to receive(:production?).and_return(true) | ||
|
|
||
| expect(FeatureManagement.allow_ipp_enrollment_approval?).to eq true | ||
| end | ||
| end | ||
|
|
||
| context 'when IdentityConfig.store.in_person_enrollments_immediate_approval_enabled is false' do | ||
| it 'returns false' do | ||
| allow(IdentityConfig.store).to receive(:in_person_enrollments_immediate_approval_enabled) | ||
| .and_return(false) | ||
| allow(Rails.env).to receive(:production?).and_return(true) | ||
|
|
||
| expect(FeatureManagement.allow_ipp_enrollment_approval?).to eq false | ||
| end | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend moving setup, such as stubbing, allow statements, and factory bot usage, out of it blocks.