fix : update local.properties path and improve null safety in chicken_local_imp.dart and chicken_repository_imp.dart; refactor profile view for better readability

This commit is contained in:
2025-10-19 09:47:33 +03:30
parent 464dacc39b
commit 6e4e3159d1
17 changed files with 3183 additions and 362 deletions

View File

@@ -0,0 +1,190 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:rasadyar_chicken/data/data_source/remote/auth/auth_remote.dart';
import 'package:rasadyar_chicken/data/models/response/user_info/user_info_model.dart';
import 'package:rasadyar_chicken/data/models/response/user_profile_model/user_profile_model.dart';
import 'package:rasadyar_chicken/data/repositories/auth/auth_repository_imp.dart';
class MockAuthRemoteDataSource extends Mock implements AuthRemoteDataSource {}
void main() {
late AuthRepositoryImpl authRepository;
late MockAuthRemoteDataSource mockAuthRemote;
setUp(() {
mockAuthRemote = MockAuthRemoteDataSource();
authRepository = AuthRepositoryImpl(mockAuthRemote);
});
group('AuthRepositoryImpl', () {
group('login', () {
test('should return UserProfileModel when login is successful', () async {
// Arrange
final authRequest = {
'username': 'test@example.com',
'password': 'password',
};
final expectedUserProfile = UserProfileModel(
accessToken: 'test-access-token',
firstname: 'John',
lastname: 'Doe',
mobile: '09123456789',
);
when(
() => mockAuthRemote.login(authRequest: authRequest),
).thenAnswer((_) async => expectedUserProfile);
// Act
final result = await authRepository.login(authRequest: authRequest);
// Assert
expect(result, equals(expectedUserProfile));
verify(() => mockAuthRemote.login(authRequest: authRequest)).called(1);
});
test('should return null when login fails', () async {
// Arrange
final authRequest = {
'username': 'test@example.com',
'password': 'wrong',
};
when(
() => mockAuthRemote.login(authRequest: authRequest),
).thenAnswer((_) async => null);
// Act
final result = await authRepository.login(authRequest: authRequest);
// Assert
expect(result, isNull);
verify(() => mockAuthRemote.login(authRequest: authRequest)).called(1);
});
});
group('logout', () {
test('should call remote logout method', () async {
// Arrange
when(() => mockAuthRemote.logout()).thenAnswer((_) async {});
// Act
await authRepository.logout();
// Assert
verify(() => mockAuthRemote.logout()).called(1);
});
});
group('hasAuthenticated', () {
test('should return true when user is authenticated', () async {
// Arrange
when(
() => mockAuthRemote.hasAuthenticated(),
).thenAnswer((_) async => true);
// Act
final result = await authRepository.hasAuthenticated();
// Assert
expect(result, isTrue);
verify(() => mockAuthRemote.hasAuthenticated()).called(1);
});
test('should return false when user is not authenticated', () async {
// Arrange
when(
() => mockAuthRemote.hasAuthenticated(),
).thenAnswer((_) async => false);
// Act
final result = await authRepository.hasAuthenticated();
// Assert
expect(result, isFalse);
verify(() => mockAuthRemote.hasAuthenticated()).called(1);
});
});
group('getUserInfo', () {
test('should return UserInfoModel when user info is found', () async {
// Arrange
const phoneNumber = '09123456789';
final expectedUserInfo = UserInfoModel(
isUser: true,
address: 'Test Address',
backend: 'test-backend',
apiKey: 'test-api-key',
);
when(
() => mockAuthRemote.getUserInfo(phoneNumber),
).thenAnswer((_) async => expectedUserInfo);
// Act
final result = await authRepository.getUserInfo(phoneNumber);
// Assert
expect(result, equals(expectedUserInfo));
verify(() => mockAuthRemote.getUserInfo(phoneNumber)).called(1);
});
test('should return null when user info is not found', () async {
// Arrange
const phoneNumber = '09123456789';
when(
() => mockAuthRemote.getUserInfo(phoneNumber),
).thenAnswer((_) async => null);
// Act
final result = await authRepository.getUserInfo(phoneNumber);
// Assert
expect(result, isNull);
verify(() => mockAuthRemote.getUserInfo(phoneNumber)).called(1);
});
});
group('submitUserInfo', () {
test(
'should call remote submitUserInfo with correct parameters',
() async {
// Arrange
const phone = '09123456789';
const deviceName = 'Test Device';
final expectedData = {'mobile': phone, 'device_name': deviceName};
when(
() => mockAuthRemote.submitUserInfo(any()),
).thenAnswer((_) async {});
// Act
await authRepository.submitUserInfo(
phone: phone,
deviceName: deviceName,
);
// Assert
verify(() => mockAuthRemote.submitUserInfo(expectedData)).called(1);
},
);
test('should call remote submitUserInfo without device name', () async {
// Arrange
const phone = '09123456789';
final expectedData = {'mobile': phone, 'device_name': null};
when(
() => mockAuthRemote.submitUserInfo(any()),
).thenAnswer((_) async {});
// Act
await authRepository.submitUserInfo(phone: phone);
// Assert
verify(() => mockAuthRemote.submitUserInfo(expectedData)).called(1);
});
});
});
}