refactor(mobile): use user service methods (#16783)

* refactor: user entity

* chore: rebase fixes

* refactor(mobile): refactor to use user service methods

* fix: late init error

* fix: lint

---------

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
shenlong
2025-03-18 19:02:33 +05:30
committed by GitHub
parent 6c2985df26
commit dd263b010c
17 changed files with 137 additions and 143 deletions
@@ -27,12 +27,16 @@ void main() {
userApiRepository: mockUserApiRepo,
storeService: mockStoreService,
);
registerFallbackValue(UserStub.admin);
when(() => mockStoreService.get(StoreKey.currentUser))
.thenReturn(UserStub.admin);
when(() => mockStoreService.tryGet(StoreKey.currentUser))
.thenReturn(UserStub.admin);
});
group('getMyUser', () {
test('should return user from store', () {
when(() => mockStoreService.get(StoreKey.currentUser))
.thenReturn(UserStub.admin);
final result = sut.getMyUser();
expect(result, UserStub.admin);
});
@@ -47,8 +51,6 @@ void main() {
group('tryGetMyUser', () {
test('should return user from store', () {
when(() => mockStoreService.tryGet(StoreKey.currentUser))
.thenReturn(UserStub.admin);
final result = sut.tryGetMyUser();
expect(result, UserStub.admin);
});
@@ -107,26 +109,48 @@ void main() {
group('createProfileImage', () {
test('should return profile image path', () async {
const profileImagePath = 'profile.jpg';
final updatedUser =
UserStub.admin.copyWith(profileImagePath: profileImagePath);
when(
() => mockUserApiRepo.createProfileImage(
name: 'profile.jpg',
name: profileImagePath,
data: Uint8List(0),
),
).thenAnswer((_) async => 'profile.jpg');
).thenAnswer((_) async => profileImagePath);
when(() => mockStoreService.put(StoreKey.currentUser, updatedUser))
.thenAnswer((_) async => true);
when(() => mockUserRepo.update(updatedUser))
.thenAnswer((_) async => UserStub.admin);
final result = await sut.createProfileImage('profile.jpg', Uint8List(0));
expect(result, 'profile.jpg');
final result =
await sut.createProfileImage(profileImagePath, Uint8List(0));
verify(() => mockStoreService.put(StoreKey.currentUser, updatedUser))
.called(1);
verify(() => mockUserRepo.update(updatedUser)).called(1);
expect(result, profileImagePath);
});
test('should return null if profile image creation fails', () async {
const profileImagePath = 'profile.jpg';
final updatedUser =
UserStub.admin.copyWith(profileImagePath: profileImagePath);
when(
() => mockUserApiRepo.createProfileImage(
name: 'profile.jpg',
name: profileImagePath,
data: Uint8List(0),
),
).thenThrow(Exception('Failed to create profile image'));
final result = await sut.createProfileImage('profile.jpg', Uint8List(0));
final result =
await sut.createProfileImage(profileImagePath, Uint8List(0));
verifyNever(
() => mockStoreService.put(StoreKey.currentUser, updatedUser),
);
verifyNever(() => mockUserRepo.update(updatedUser));
expect(result, isNull);
});
});