test(auth): pin onComplete and factor refresh on successful MFA enrollment - #2462
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors MfaEnrollmentScreen by extracting an internal composable MfaEnrollmentScreenInternal to allow injecting stubbed enrollment handlers for unit testing. It also adds several unit tests to verify successful and failed TOTP enrollment scenarios. The review feedback correctly identifies that the tests incorrectly use the whenever { ... } syntax to stub suspend functions, which will result in a NotAMockException at runtime. These stubbing calls should be wrapped in runBlocking to function properly.
837d1b8 to
bcb4a97
Compare
444543d to
059bba8
Compare
bcb4a97 to
5a7ea86
Compare
russellwheatley
left a comment
There was a problem hiding this comment.
LGTM
The Internal seam keeps the public API clean, and the success tests actually pin onComplete with exact enroll arguments. SMS coverage is more than the issue asked for and I think that's the right call.
A few non-blocking nits if you feel like it: the resend test could assert errors after the final verify, and there's no TOTP twin of the missing-session test. Not worth holding this.
…lment (#2462) * test(auth): pin onComplete and factor refresh on successful MFA enrollment * test(auth): pin the SMS MFA enrollment route through send, verify and resend * test(auth): pin the missing TOTP secret guard and the resend's clean enroll
Nothing asserted that
onCompletefires when MFA enrollment succeeds. #2457 removed the recovery-codes step, which movedonCompleteone user interaction earlier for every default-configured integrator — the suite would have passed equally well had it been deleted rather than hoisted. The SMS route was unpinned end to end: deleting itsenrollWithVerificationCodecall left all 633 tests green.MfaEnrollmentScreenbuilt its handlers inside the composable, so there was nothing to stub. An internalMfaEnrollmentScreenInternalnow takes them as parameters and the public composable constructs the real ones and delegates to it; the public signature is unchanged.Added nine tests across both enrollment routes — TOTP (
onCompletefires exactly once with the entered code, the enrolled-factors refresh, the failure path) and SMS (dial-code prefix and session storage, exact enroll arguments, the missing-session guard, send and enroll failures, resend session replacement and its rate-limit gate). Each was verified to fail when the line it pins is removed.Maintainer note: Fixes internal CPRN-383