Skip to content

LG-10157 Profiles should have activation characterization tests#8629

Merged
kbighorse merged 64 commits intomainfrom
LG-10157-profile-activation-characterization-tests
Jul 3, 2023
Merged

LG-10157 Profiles should have activation characterization tests#8629
kbighorse merged 64 commits intomainfrom
LG-10157-profile-activation-characterization-tests

Conversation

@kbighorse
Copy link
Contributor

@kbighorse kbighorse commented Jun 21, 2023

🎫 Ticket

Profile de-/activation methods should have characterization tests

🛠 Summary of changes

  • add before and after tests around activation calls, including deactivation methods
  • prefer pre-defined profile factories with traits whenever possible

@kbighorse kbighorse marked this pull request as draft June 21, 2023 17:41

# TODO: this preserves the previous passing behavior, but should be re-implemented
# to rely on the `Profile#active` boolean rather than the `Profile#activated_at` timestamp
let!(:user) { create(:user, profiles: [create(:profile, activated_at: Time.zone.now)]) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kbighorse kbighorse marked this pull request as ready for review June 26, 2023 15:15
@kbighorse kbighorse changed the title Profiles should have activation characterization tests LG-10157 Profiles should have activation characterization tests Jun 26, 2023
@kbighorse kbighorse requested review from jmhooper and theabrad June 26, 2023 15:16
request_url: 'http://example.com',
}

expect(unverified_profile.activated_at).to be_present
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the profile is unverified should there be an activated_at?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is an issue to investigate if we keep this code around.

expect(unverified_profile.fraud_review_pending?).to eq(false)
expect(unverified_profile.gpo_verification_pending_at).to be_nil
expect(unverified_profile.initiating_service_provider).to be_nil
expect(unverified_profile.verified_at).to be_nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it 'logs a reproofing event upon reproofing' do
user.profiles.create(verified_at: Time.zone.now, active: true, activated_at: Time.zone.now)
unverified_profile = user.profiles.first
verified_profile = create(:profile, :verified, user: user)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theabrad note: is this equivalent to what's on main?

expect(verified_profile.initiating_service_provider).to be_nil
expect(verified_profile.verified_at).to be_present

expect(@irs_attempts_api_tracker).to receive(:idv_reproof)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soniaconnolly: @theabrad and I think that Profile#has_proofed_before? may need to be refactored to rely on activated_at AND verified_at. It currently considers activated_at only.

@benjaminchait this is IRS-related code, should we loop in anyone else?

Copy link
Contributor

@soniaconnolly soniaconnolly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for all this work and analysis! Approving, with the strong recommendation to add one more commit to automatically include :verified in the :active trait. And some other comments.

request_url: 'http://example.com',
}

expect(unverified_profile.activated_at).to be_present
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is an issue to investigate if we keep this code around.

Comment on lines 11 to 13
# `activated_at` will be always defined for active profiles,
# but it is not defined here so tests will not rely on it
# instead of the `active` boolean above as they should
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend adding activated_at and verified_at fields to accurately reflect what's required in the code.


trait :deactivated do
active { false }
activated_at { Time.zone.now }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's deactivated, activated_at should be in the past, and this should also have a matching verified_at.

describe '#activate' do
it 'activates current Profile, de-activates all other Profile for the user' do
active_profile = user.profiles.create(active: true)
# TODO: should also be verified
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted above, :active should automatically imply :verified.

describe '#activate_after_password_reset' do
it 'activates a profile after password reset' do
it 'activates a non-verified, non-active, non-activated profile after password reset' do
# TODO: this profile scenario shouldn't be possible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, this scenario should expect a RuntimeError, and the code should raise.

end

# ??? This method still nils out deactivation_reason even though it raises
it 'does not activate a profile if it has a pending reason' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test title could be more descriptive.

Suggested change
it 'does not activate a profile if it has a pending reason' do
it 'does not activate a profile after password reset if it has fraud review pending' do

Maybe it's removing password_reset as the deactivation reason because they used their Personal Key to recover the PII bundle? Do they have a Personal Key if they're fraud review pending? Maybe these password reset specs are left over from when the user saw the Personal Key before entering their GPO code.

Comment on lines +752 to +753
:fraud_review_pending,
:in_person_verification_pending,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an invalid combination of characteristics. Fraud review pending doesn't apply to in person proofing.

Comment on lines +925 to +926
# TODO: does deactivating make sense for a non-active profile? Should we prevent it?
# TODO: related: should we test against an active profile here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to activate and immediately deactivate. I think Amir fixed that, but the method names still include "deactivate."

@kbighorse kbighorse merged commit 77311e9 into main Jul 3, 2023
@kbighorse kbighorse deleted the LG-10157-profile-activation-characterization-tests branch July 3, 2023 17:05
@kbighorse kbighorse restored the LG-10157-profile-activation-characterization-tests branch July 3, 2023 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants