Skip to content

Add comprehensive unit tests for AuthProvider#1034

Open
andoriyaprashant wants to merge 1 commit into
mosip:masterfrom
andoriyaprashant:auth
Open

Add comprehensive unit tests for AuthProvider#1034
andoriyaprashant wants to merge 1 commit into
mosip:masterfrom
andoriyaprashant:auth

Conversation

@andoriyaprashant
Copy link
Copy Markdown

@andoriyaprashant andoriyaprashant commented May 7, 2026

Fixes #1033

Summary

This Pull Request adds comprehensive unit tests for AuthProvider covering its internal state management and listener behavior.

Added Test Coverage

  • Initial provider state validation
  • Setter method behavior
  • State transition handling
  • clearUser() functionality
  • Listener notification behavior
  • Edge case handling for empty and long values
  • Sequential state update verification

Result

00:00 +0: Initial State Tests initial isLoggedIn should be false
00:00 +1: Initial State Tests initial isSyncing should be false
00:00 +2: Initial State Tests initial isOnboarded should be false
00:00 +3: Initial State Tests initial isDefault should be false
00:00 +4: Initial State Tests initial isSupervisor should be false
00:00 +5: Initial State Tests initial isOperator should be false
00:00 +6: Initial State Tests initial isOfficer should be false
00:00 +7: Initial State Tests initial isValidUser should be false
00:00 +8: Initial State Tests initial isLoggingIn should be false
00:00 +9: Initial State Tests initial isPacketAuthenticated should be false
00:00 +10: Initial State Tests initial isMachineActive should be false
00:00 +11: Initial State Tests initial isCenterActive should be false
00:00 +12: Initial State Tests initial isNetworkPresent should be false
00:00 +13: Initial State Tests initial loginError should be empty
00:00 +14: Initial State Tests initial packetError should be empty
00:00 +15: Initial State Tests initial userId should be empty
00:00 +16: Initial State Tests initial username should be empty
00:00 +17: Initial State Tests initial userEmail should be empty
00:00 +18: Initial State Tests initial forgotPasswordUrl should be empty
00:00 +19: Initial State Tests initial refreshedLoginTime should be empty
00:00 +20: Initial State Tests initial idleTime should be empty
00:00 +21: Initial State Tests initial passwordLength should be empty
00:00 +22: Setter Tests setIsLoggedIn updates state
00:00 +23: Setter Tests setIsSyncing updates state
00:00 +24: Setter Tests setIsOnboarded updates state
00:00 +25: Setter Tests setIsDefault updates state
00:00 +26: Setter Tests setIsSupervisor updates state
00:00 +27: Setter Tests setIsOperator updates state
00:00 +28: Setter Tests setIsOfficer updates state
00:00 +29: Setter Tests setIsValidUser updates state
00:00 +30: Setter Tests setLoginError updates state
00:00 +31: Setter Tests setIsPacketAuthenticated updates state
00:00 +32: Setter Tests setIsMachineActive updates state
00:00 +33: Setter Tests setIsCenterActive updates state
00:00 +34: Setter Tests setPacketError updates state
00:00 +35: Setter Tests setUserId updates state
00:00 +36: Setter Tests setUsername updates state
00:00 +37: Setter Tests setUserEmail updates state
00:00 +38: Setter Tests setIsNetworkPresent updates state
00:00 +39: Setter Tests setIsLoggingIn follows current implementation
00:00 +40: clearUser Tests clearUser resets relevant user state values
00:00 +41: clearUser Tests clearUser does not affect operator state
00:00 +42: clearUser Tests clearUser does not affect syncing state
00:00 +43: State Transition Tests multiple sequential state updates work correctly
00:00 +44: Edge Case Tests set empty username
00:00 +45: Edge Case Tests set empty userEmail
00:00 +46: Edge Case Tests set empty loginError
00:00 +47: Edge Case Tests set empty packetError
00:00 +48: Edge Case Tests set long username
00:00 +49: Edge Case Tests set long email value
00:00 +50: Notify Listener Behavior Tests listener gets triggered on state change
00:00 +51: Notify Listener Behavior Tests multiple listeners are triggered
00:00 +52: All tests passed!

Summary by CodeRabbit

Release Notes

  • Tests
    • Added comprehensive test suite for authentication provider to validate state management and listener functionality.

Note: This release includes internal testing improvements with no user-facing changes.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack

Warning

Rate limit exceeded

@andoriyaprashant has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 57 minutes and 37 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9ca3c729-3be3-45a9-b5e0-163488840b52

📥 Commits

Reviewing files that changed from the base of the PR and between 7168f49 and 6e045b2.

📒 Files selected for processing (1)
  • test/auth_provider_test.dart

Walkthrough

This PR introduces a comprehensive Flutter unit test suite for AuthProvider with 342 lines of new test code covering initial state validation, setter method behavior, state transitions, the clearUser() reset logic, edge cases with empty and long string values, and change listener notifications.

Changes

AuthProvider Unit Tests

Layer / File(s) Summary
Test Harness & Initial State
test/auth_provider_test.dart (lines 1–99)
Initializes AuthProvider in setUp() and validates all default properties (login/onboarding/role flags, syncing/network/machine/center flags, error strings, user identity fields) start in false/empty-string states.
Setter Method Behavior
test/auth_provider_test.dart (lines 101–209)
Tests state mutation for all AuthProvider setters, asserting each updates its corresponding property; includes explicit verification that setIsLoggingIn(true) does not change isLoggingIn per current implementation.
clearUser() State Reset
test/auth_provider_test.dart (lines 211–245)
Verifies clearUser() resets user-related flags (isLoggingIn, isOnboarding, isMachineSelection, isCenterSelection) to false while preserving isOperator and isSyncing.
Sequential State Transitions
test/auth_provider_test.dart (lines 247–266)
Confirms multiple setters applied before clearUser() result in expected mix of preserved and reset fields.
Edge Case Value Handling
test/auth_provider_test.dart (lines 268–308)
Validates empty strings (username, email, loginError, packetError) and long username/email values are stored correctly.
Change Listener Notifications
test/auth_provider_test.dart (lines 310–341)
Verifies registered listeners are invoked after state changes and multiple listeners each fire once per update.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Poem

🐰 A test suite hops through AuthProvider's domain,
Validating state with meticulous refrain—
Defaults checked, setters traced, listeners alerted,
Each assertion precise, no detail deserted! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding comprehensive unit tests for AuthProvider, which directly matches the changeset.
Linked Issues check ✅ Passed All coding objectives from issue #1033 are addressed: initial state validation, setter methods, state transitions, clearUser() functionality, listener notifications, and edge case handling are all covered by the test suite.
Out of Scope Changes check ✅ Passed All changes are scoped to the test file and directly address the objectives in issue #1033; no unrelated or out-of-scope modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: andoriyaprashant <prashantandoriya@gmail.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
test/auth_provider_test.dart (2)

7-9: ⚡ Quick win

Add tearDown(() => authProvider.dispose()) to avoid resource leaks.

AuthProvider extends ChangeNotifier. Without disposing it after each test, registered listeners are never freed and the object is left in an indeterminate state for the GC. Add a tearDown block alongside the existing setUp:

♻️ Proposed fix
  setUp(() {
    authProvider = AuthProvider();
  });

+ tearDown(() {
+   authProvider.dispose();
+ });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/auth_provider_test.dart` around lines 7 - 9, Add a tearDown that calls
authProvider.dispose() to prevent leaking listeners from AuthProvider (which
extends ChangeNotifier); alongside the existing setUp that instantiates
authProvider = AuthProvider(), add a tearDown(() => authProvider.dispose()) so
each test cleans up the AuthProvider instance and frees registered listeners.

211-244: ⚡ Quick win

clearUser tests do not assert string field behavior.

The group only verifies boolean flags. If clearUser() is expected to also reset userId, username, userEmail, loginError, or packetError, regressions in those resets would go undetected. Consider adding assertions (or an explicit "does not reset" assertion) for all string-typed fields that clearUser() could touch.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/auth_provider_test.dart` around lines 211 - 244, Update the clearUser
test group to also assert string-typed fields are handled correctly by
clearUser: after calling authProvider.clearUser() add assertions that
authProvider.userId, authProvider.username, authProvider.userEmail,
authProvider.loginError, and authProvider.packetError are reset to their
expected cleared values (e.g., empty string or null per implementation); if any
of these string fields are intended to be preserved instead, add explicit "does
not reset" assertions for those fields; locate these checks alongside the
existing boolean expectations in the 'clearUser Tests' group that call
authProvider.clearUser().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/auth_provider_test.dart`:
- Around line 204-208: The setter setIsLoggingIn currently ignores its parameter
and always sets _isLoggingIn to false; change setIsLoggingIn(bool value) to
assign _isLoggingIn = value so the flag reflects the passed value, and update
the test 'setIsLoggingIn follows current implementation' to assert
authProvider.isLoggingIn is true after calling authProvider.setIsLoggingIn(true)
so the test matches the corrected behavior.

---

Nitpick comments:
In `@test/auth_provider_test.dart`:
- Around line 7-9: Add a tearDown that calls authProvider.dispose() to prevent
leaking listeners from AuthProvider (which extends ChangeNotifier); alongside
the existing setUp that instantiates authProvider = AuthProvider(), add a
tearDown(() => authProvider.dispose()) so each test cleans up the AuthProvider
instance and frees registered listeners.
- Around line 211-244: Update the clearUser test group to also assert
string-typed fields are handled correctly by clearUser: after calling
authProvider.clearUser() add assertions that authProvider.userId,
authProvider.username, authProvider.userEmail, authProvider.loginError, and
authProvider.packetError are reset to their expected cleared values (e.g., empty
string or null per implementation); if any of these string fields are intended
to be preserved instead, add explicit "does not reset" assertions for those
fields; locate these checks alongside the existing boolean expectations in the
'clearUser Tests' group that call authProvider.clearUser().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e9a76132-9bd8-487e-a5bf-7989d5289363

📥 Commits

Reviewing files that changed from the base of the PR and between aef4fb6 and 7168f49.

📒 Files selected for processing (1)
  • test/auth_provider_test.dart

Comment on lines +204 to +208
test('setIsLoggingIn follows current implementation', () {
authProvider.setIsLoggingIn(true);

expect(authProvider.isLoggingIn, false);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Locate the AuthProvider implementation and inspect setIsLoggingIn
fd -e dart auth_provider --exec grep -n "setIsLoggingIn\|isLoggingIn" {}

Repository: mosip/android-registration-client

Length of output: 547


Fix setIsLoggingIn implementation — it ignores the parameter and always sets the flag to false.

The implementation (line 113-114) is:

setIsLoggingIn(bool value) {
  _isLoggingIn = false;
}

This is a bug. The setter discards the value parameter and unconditionally sets _isLoggingIn = false, breaking the setter's purpose. Update it to:

setIsLoggingIn(bool value) {
  _isLoggingIn = value;
}

The test (line 204-208) must also be corrected to assert the intended behavior:

test('setIsLoggingIn follows current implementation', () {
  authProvider.setIsLoggingIn(true);
  expect(authProvider.isLoggingIn, true);  // Should be true, not false
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/auth_provider_test.dart` around lines 204 - 208, The setter
setIsLoggingIn currently ignores its parameter and always sets _isLoggingIn to
false; change setIsLoggingIn(bool value) to assign _isLoggingIn = value so the
flag reflects the passed value, and update the test 'setIsLoggingIn follows
current implementation' to assert authProvider.isLoggingIn is true after calling
authProvider.setIsLoggingIn(true) so the test matches the corrected behavior.

@andoriyaprashant
Copy link
Copy Markdown
Author

andoriyaprashant commented May 7, 2026

Hi @SachinPremkumar @Pragya279 could you please review this Pull request and let me know if any changes are needed
Thanks!

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.

Add unit tests for AuthProvider state management and listener behavior

1 participant