-
Notifications
You must be signed in to change notification settings - Fork 87
Add comprehensive unit tests for AuthProvider #1034
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
Open
andoriyaprashant
wants to merge
1
commit into
mosip:master
Choose a base branch
from
andoriyaprashant:auth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,342 @@ | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:registration_client/provider/auth_provider.dart'; | ||
|
|
||
| void main() { | ||
| late AuthProvider authProvider; | ||
|
|
||
| setUp(() { | ||
| authProvider = AuthProvider(); | ||
| }); | ||
|
|
||
| group('Initial State Tests', () { | ||
| test('initial isLoggedIn should be false', () { | ||
| expect(authProvider.isLoggedIn, false); | ||
| }); | ||
|
|
||
| test('initial isSyncing should be false', () { | ||
| expect(authProvider.isSyncing, false); | ||
| }); | ||
|
|
||
| test('initial isOnboarded should be false', () { | ||
| expect(authProvider.isOnboarded, false); | ||
| }); | ||
|
|
||
| test('initial isDefault should be false', () { | ||
| expect(authProvider.isDefault, false); | ||
| }); | ||
|
|
||
| test('initial isSupervisor should be false', () { | ||
| expect(authProvider.isSupervisor, false); | ||
| }); | ||
|
|
||
| test('initial isOperator should be false', () { | ||
| expect(authProvider.isOperator, false); | ||
| }); | ||
|
|
||
| test('initial isOfficer should be false', () { | ||
| expect(authProvider.isOfficer, false); | ||
| }); | ||
|
|
||
| test('initial isValidUser should be false', () { | ||
| expect(authProvider.isValidUser, false); | ||
| }); | ||
|
|
||
| test('initial isLoggingIn should be false', () { | ||
| expect(authProvider.isLoggingIn, false); | ||
| }); | ||
|
|
||
| test('initial isPacketAuthenticated should be false', () { | ||
| expect(authProvider.isPacketAuthenticated, false); | ||
| }); | ||
|
|
||
| test('initial isMachineActive should be false', () { | ||
| expect(authProvider.isMachineActive, false); | ||
| }); | ||
|
|
||
| test('initial isCenterActive should be false', () { | ||
| expect(authProvider.isCenterActive, false); | ||
| }); | ||
|
|
||
| test('initial isNetworkPresent should be false', () { | ||
| expect(authProvider.isNetworkPresent, false); | ||
| }); | ||
|
|
||
| test('initial loginError should be empty', () { | ||
| expect(authProvider.loginError, ""); | ||
| }); | ||
|
|
||
| test('initial packetError should be empty', () { | ||
| expect(authProvider.packetError, ""); | ||
| }); | ||
|
|
||
| test('initial userId should be empty', () { | ||
| expect(authProvider.userId, ""); | ||
| }); | ||
|
|
||
| test('initial username should be empty', () { | ||
| expect(authProvider.username, ""); | ||
| }); | ||
|
|
||
| test('initial userEmail should be empty', () { | ||
| expect(authProvider.userEmail, ""); | ||
| }); | ||
|
|
||
| test('initial forgotPasswordUrl should be empty', () { | ||
| expect(authProvider.forgotPasswordUrl, ""); | ||
| }); | ||
|
|
||
| test('initial refreshedLoginTime should be empty', () { | ||
| expect(authProvider.refreshedLoginTime, ""); | ||
| }); | ||
|
|
||
| test('initial idleTime should be empty', () { | ||
| expect(authProvider.idleTime, ""); | ||
| }); | ||
|
|
||
| test('initial passwordLength should be empty', () { | ||
| expect(authProvider.passwordLength, ""); | ||
| }); | ||
| }); | ||
|
|
||
| group('Setter Tests', () { | ||
| test('setIsLoggedIn updates state', () { | ||
| authProvider.setIsLoggedIn(true); | ||
|
|
||
| expect(authProvider.isLoggedIn, true); | ||
| }); | ||
|
|
||
| test('setIsSyncing updates state', () { | ||
| authProvider.setIsSyncing(true); | ||
|
|
||
| expect(authProvider.isSyncing, true); | ||
| }); | ||
|
|
||
| test('setIsOnboarded updates state', () { | ||
| authProvider.setIsOnboarded(true); | ||
|
|
||
| expect(authProvider.isOnboarded, true); | ||
| }); | ||
|
|
||
| test('setIsDefault updates state', () { | ||
| authProvider.setIsDefault(true); | ||
|
|
||
| expect(authProvider.isDefault, true); | ||
| }); | ||
|
|
||
| test('setIsSupervisor updates state', () { | ||
| authProvider.setIsSupervisor(true); | ||
|
|
||
| expect(authProvider.isSupervisor, true); | ||
| }); | ||
|
|
||
| test('setIsOperator updates state', () { | ||
| authProvider.setIsOperator(true); | ||
|
|
||
| expect(authProvider.isOperator, true); | ||
| }); | ||
|
|
||
| test('setIsOfficer updates state', () { | ||
| authProvider.setIsOfficer(true); | ||
|
|
||
| expect(authProvider.isOfficer, true); | ||
| }); | ||
|
|
||
| test('setIsValidUser updates state', () { | ||
| authProvider.setIsValidUser(true); | ||
|
|
||
| expect(authProvider.isValidUser, true); | ||
| }); | ||
|
|
||
| test('setLoginError updates state', () { | ||
| authProvider.setLoginError('Invalid Credentials'); | ||
|
|
||
| expect(authProvider.loginError, 'Invalid Credentials'); | ||
| }); | ||
|
|
||
| test('setIsPacketAuthenticated updates state', () { | ||
| authProvider.setIsPacketAuthenticated(true); | ||
|
|
||
| expect(authProvider.isPacketAuthenticated, true); | ||
| }); | ||
|
|
||
| test('setIsMachineActive updates state', () { | ||
| authProvider.setIsMachineActive(true); | ||
|
|
||
| expect(authProvider.isMachineActive, true); | ||
| }); | ||
|
|
||
| test('setIsCenterActive updates state', () { | ||
| authProvider.setIsCenterActive(true); | ||
|
|
||
| expect(authProvider.isCenterActive, true); | ||
| }); | ||
|
|
||
| test('setPacketError updates state', () { | ||
| authProvider.setPacketError('Packet Error'); | ||
|
|
||
| expect(authProvider.packetError, 'Packet Error'); | ||
| }); | ||
|
|
||
| test('setUserId updates state', () { | ||
| authProvider.setUserId('user123'); | ||
|
|
||
| expect(authProvider.userId, 'user123'); | ||
| }); | ||
|
|
||
| test('setUsername updates state', () { | ||
| authProvider.setUsername('Prashant'); | ||
|
|
||
| expect(authProvider.username, 'Prashant'); | ||
| }); | ||
|
|
||
| test('setUserEmail updates state', () { | ||
| authProvider.setUserEmail('test@example.com'); | ||
|
|
||
| expect(authProvider.userEmail, 'test@example.com'); | ||
| }); | ||
|
|
||
| test('setIsNetworkPresent updates state', () { | ||
| authProvider.setIsNetworkPresent(true); | ||
|
|
||
| expect(authProvider.isNetworkPresent, true); | ||
| }); | ||
|
|
||
| test('setIsLoggingIn follows current implementation', () { | ||
| authProvider.setIsLoggingIn(true); | ||
|
|
||
| expect(authProvider.isLoggingIn, false); | ||
| }); | ||
| }); | ||
|
|
||
| group('clearUser Tests', () { | ||
| test('clearUser resets relevant user state values', () { | ||
| authProvider.setIsLoggedIn(true); | ||
| authProvider.setIsValidUser(true); | ||
| authProvider.setIsDefault(true); | ||
| authProvider.setIsOfficer(true); | ||
| authProvider.setIsOnboarded(true); | ||
| authProvider.setIsSupervisor(true); | ||
|
|
||
| authProvider.clearUser(); | ||
|
|
||
| expect(authProvider.isLoggedIn, false); | ||
| expect(authProvider.isValidUser, false); | ||
| expect(authProvider.isDefault, false); | ||
| expect(authProvider.isOfficer, false); | ||
| expect(authProvider.isOnboarded, false); | ||
| expect(authProvider.isSupervisor, false); | ||
| }); | ||
|
|
||
| test('clearUser does not affect operator state', () { | ||
| authProvider.setIsOperator(true); | ||
|
|
||
| authProvider.clearUser(); | ||
|
|
||
| expect(authProvider.isOperator, true); | ||
| }); | ||
|
|
||
| test('clearUser does not affect syncing state', () { | ||
| authProvider.setIsSyncing(true); | ||
|
|
||
| authProvider.clearUser(); | ||
|
|
||
| expect(authProvider.isSyncing, true); | ||
| }); | ||
| }); | ||
|
|
||
| group('State Transition Tests', () { | ||
| test('multiple sequential state updates work correctly', () { | ||
| authProvider.setIsLoggedIn(true); | ||
| authProvider.setIsSyncing(true); | ||
| authProvider.setIsOperator(true); | ||
| authProvider.setIsMachineActive(true); | ||
|
|
||
| expect(authProvider.isLoggedIn, true); | ||
| expect(authProvider.isSyncing, true); | ||
| expect(authProvider.isOperator, true); | ||
| expect(authProvider.isMachineActive, true); | ||
|
|
||
| authProvider.clearUser(); | ||
|
|
||
| expect(authProvider.isLoggedIn, false); | ||
| expect(authProvider.isSyncing, true); | ||
| expect(authProvider.isOperator, true); | ||
| expect(authProvider.isMachineActive, true); | ||
| }); | ||
| }); | ||
|
|
||
| group('Edge Case Tests', () { | ||
| test('set empty username', () { | ||
| authProvider.setUsername(''); | ||
|
|
||
| expect(authProvider.username, ''); | ||
| }); | ||
|
|
||
| test('set empty userEmail', () { | ||
| authProvider.setUserEmail(''); | ||
|
|
||
| expect(authProvider.userEmail, ''); | ||
| }); | ||
|
|
||
| test('set empty loginError', () { | ||
| authProvider.setLoginError(''); | ||
|
|
||
| expect(authProvider.loginError, ''); | ||
| }); | ||
|
|
||
| test('set empty packetError', () { | ||
| authProvider.setPacketError(''); | ||
|
|
||
| expect(authProvider.packetError, ''); | ||
| }); | ||
|
|
||
| test('set long username', () { | ||
| final username = 'a' * 500; | ||
|
|
||
| authProvider.setUsername(username); | ||
|
|
||
| expect(authProvider.username, username); | ||
| }); | ||
|
|
||
| test('set long email value', () { | ||
| final email = '${'a' * 200}@example.com'; | ||
|
|
||
| authProvider.setUserEmail(email); | ||
|
|
||
| expect(authProvider.userEmail, email); | ||
| }); | ||
| }); | ||
|
|
||
| group('Notify Listener Behavior Tests', () { | ||
| test('listener gets triggered on state change', () { | ||
| int notifyCount = 0; | ||
|
|
||
| authProvider.addListener(() { | ||
| notifyCount++; | ||
| }); | ||
|
|
||
| authProvider.setIsLoggedIn(true); | ||
|
|
||
| expect(notifyCount, 1); | ||
| }); | ||
|
|
||
|
|
||
| test('multiple listeners are triggered', () { | ||
| int listenerOne = 0; | ||
| int listenerTwo = 0; | ||
|
|
||
| authProvider.addListener(() { | ||
| listenerOne++; | ||
| }); | ||
|
|
||
| authProvider.addListener(() { | ||
| listenerTwo++; | ||
| }); | ||
|
|
||
| authProvider.setIsDefault(true); | ||
|
|
||
| expect(listenerOne, 1); | ||
| expect(listenerTwo, 1); | ||
| }); | ||
| }); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: mosip/android-registration-client
Length of output: 547
Fix
setIsLoggingInimplementation — it ignores the parameter and always sets the flag tofalse.The implementation (line 113-114) is:
This is a bug. The setter discards the
valueparameter and unconditionally sets_isLoggingIn = false, breaking the setter's purpose. Update it to:The test (line 204-208) must also be corrected to assert the intended behavior:
🤖 Prompt for AI Agents