forked from eatvio/eatvio_app
feat(diary): tests
This commit is contained in:
@@ -509,6 +509,359 @@ void main() {
|
||||
final state = profileCubit!.state;
|
||||
expect(state, isA<ProfileStateError>());
|
||||
});
|
||||
test('deletePhoto - успешно удаляет фото', () async {
|
||||
profileCubit = ProfileCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
chatRepository: mockChatRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
);
|
||||
|
||||
const testProfile = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'https://example.com/icon.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
const profileDetails = ProfileDetailsModel(
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
country: 'Russia',
|
||||
city: 'Moscow',
|
||||
lang: 'ru',
|
||||
weight: 70.0,
|
||||
height: 175,
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: false,
|
||||
hasHyper: false,
|
||||
aboutAlergy: '',
|
||||
aboutTakingPils: '',
|
||||
aboutSportHobbies: '',
|
||||
favoriteFoods: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: '',
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: true,
|
||||
activityCoefficient: 1.2,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.deletePhoto()).thenAnswer((_) async => {});
|
||||
when(mockProfileRepository.getMyProfile()).thenAnswer((_) async => testProfile);
|
||||
when(mockProfileRepository.getMyProfileDetails()).thenAnswer((_) async => profileDetails);
|
||||
when(mockProfileRepository.getBlogPostsByAuthorSlug(slug: 'test-user')).thenAnswer((_) async => []);
|
||||
when(mockProfileRepository.getWeight(period: '1')).thenAnswer((_) async => []);
|
||||
when(mockProfileRepository.getCircumferences(period: '1')).thenAnswer((_) async => []);
|
||||
|
||||
await profileCubit!.deletePhoto();
|
||||
|
||||
verify(mockProfileRepository.deletePhoto()).called(1);
|
||||
expect(profileCubit!.state, isA<ProfileStateLoaded>());
|
||||
});
|
||||
|
||||
test('deletePhoto - обработка ошибки', () async {
|
||||
profileCubit = ProfileCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
chatRepository: mockChatRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.deletePhoto()).thenThrow(Exception('Ошибка удаления'));
|
||||
|
||||
await profileCubit!.deletePhoto();
|
||||
|
||||
expect(profileCubit!.state, isA<ProfileStateError>());
|
||||
});
|
||||
|
||||
test('hideCertPhoto - успешно скрывает фото', () async {
|
||||
profileCubit = ProfileCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
chatRepository: mockChatRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
);
|
||||
|
||||
const testProfile = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: '',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
const profileDetails = ProfileDetailsModel(
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
country: 'Russia',
|
||||
city: 'Moscow',
|
||||
lang: 'ru',
|
||||
weight: 70.0,
|
||||
height: 175,
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: false,
|
||||
hasHyper: false,
|
||||
aboutAlergy: '',
|
||||
aboutTakingPils: '',
|
||||
aboutSportHobbies: '',
|
||||
favoriteFoods: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: '',
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: true,
|
||||
activityCoefficient: 1.2,
|
||||
);
|
||||
|
||||
// Устанавливаем начальное loaded-состояние
|
||||
profileCubit!.emit(const ProfileState.loaded(
|
||||
profile: testProfile,
|
||||
isMyProfile: true,
|
||||
profileDetails: profileDetails,
|
||||
blogPosts: [],
|
||||
certPhotos: [],
|
||||
));
|
||||
|
||||
when(mockConsultantRepository.hideConsultantCertPhoto(1)).thenAnswer((_) async => {});
|
||||
when(mockConsultantRepository.getConsultantCertPhotos()).thenAnswer((_) async => []);
|
||||
|
||||
await profileCubit!.hideCertPhoto(1);
|
||||
|
||||
verify(mockConsultantRepository.hideConsultantCertPhoto(1)).called(1);
|
||||
expect(profileCubit!.state, isA<ProfileStateLoaded>());
|
||||
});
|
||||
|
||||
test('unhideCertPhoto - успешно показывает фото', () async {
|
||||
profileCubit = ProfileCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
chatRepository: mockChatRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
);
|
||||
|
||||
const testProfile = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: '',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
const profileDetails = ProfileDetailsModel(
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
country: 'Russia',
|
||||
city: 'Moscow',
|
||||
lang: 'ru',
|
||||
weight: 70.0,
|
||||
height: 175,
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: false,
|
||||
hasHyper: false,
|
||||
aboutAlergy: '',
|
||||
aboutTakingPils: '',
|
||||
aboutSportHobbies: '',
|
||||
favoriteFoods: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: '',
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: true,
|
||||
activityCoefficient: 1.2,
|
||||
);
|
||||
|
||||
profileCubit!.emit(const ProfileState.loaded(
|
||||
profile: testProfile,
|
||||
isMyProfile: true,
|
||||
profileDetails: profileDetails,
|
||||
blogPosts: [],
|
||||
certPhotos: [],
|
||||
));
|
||||
|
||||
when(mockConsultantRepository.unHideConsultantCertPhoto(2)).thenAnswer((_) async => {});
|
||||
when(mockConsultantRepository.getConsultantCertPhotos()).thenAnswer((_) async => []);
|
||||
|
||||
await profileCubit!.unhideCertPhoto(2);
|
||||
|
||||
verify(mockConsultantRepository.unHideConsultantCertPhoto(2)).called(1);
|
||||
expect(profileCubit!.state, isA<ProfileStateLoaded>());
|
||||
});
|
||||
|
||||
test('getProfileBySlug - загрузка своего профиля (isMyProfile = true)', () async {
|
||||
profileCubit = ProfileCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
chatRepository: mockChatRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
);
|
||||
|
||||
const testProfile = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: '',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
const profileDetails = ProfileDetailsModel(
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
country: 'Russia',
|
||||
city: 'Moscow',
|
||||
lang: 'ru',
|
||||
weight: 70.0,
|
||||
height: 175,
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: false,
|
||||
hasHyper: false,
|
||||
aboutAlergy: '',
|
||||
aboutTakingPils: '',
|
||||
aboutSportHobbies: '',
|
||||
favoriteFoods: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: '',
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: true,
|
||||
activityCoefficient: 1.2,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.getProfileBySlug('test-user')).thenAnswer((_) async => testProfile);
|
||||
when(mockProfileRepository.getMyProfile()).thenAnswer((_) async => testProfile);
|
||||
when(mockProfileRepository.getProfileDetailsBySlug('test-user')).thenAnswer((_) async => profileDetails);
|
||||
when(mockProfileRepository.getBlogPostsByAuthorSlug(slug: 'test-user')).thenAnswer((_) async => []);
|
||||
when(mockConsultantRepository.getConsultantCertPhotos()).thenAnswer((_) async => []);
|
||||
|
||||
await profileCubit!.getProfileBySlug('test-user');
|
||||
|
||||
final state = profileCubit!.state;
|
||||
expect(state, isA<ProfileStateLoaded>());
|
||||
if (state is ProfileStateLoaded) {
|
||||
expect(state.isMyProfile, true);
|
||||
}
|
||||
});
|
||||
|
||||
test('getMyProfile - с указанием period', () async {
|
||||
profileCubit = ProfileCubit(
|
||||
profileRepository: mockProfileRepository,
|
||||
chatRepository: mockChatRepository,
|
||||
consultantRepository: mockConsultantRepository,
|
||||
);
|
||||
|
||||
const testProfile = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: '',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
const profileDetails = ProfileDetailsModel(
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
birthdate: '1990-01-01',
|
||||
gender: 'male',
|
||||
country: 'Russia',
|
||||
city: 'Moscow',
|
||||
lang: 'ru',
|
||||
weight: 70.0,
|
||||
height: 175,
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: false,
|
||||
hasHyper: false,
|
||||
aboutAlergy: '',
|
||||
aboutTakingPils: '',
|
||||
aboutSportHobbies: '',
|
||||
favoriteFoods: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: '',
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: true,
|
||||
activityCoefficient: 1.2,
|
||||
);
|
||||
|
||||
when(mockProfileRepository.getMyProfile()).thenAnswer((_) async => testProfile);
|
||||
when(mockProfileRepository.getMyProfileDetails()).thenAnswer((_) async => profileDetails);
|
||||
when(mockProfileRepository.getBlogPostsByAuthorSlug(slug: 'test-user')).thenAnswer((_) async => []);
|
||||
when(mockProfileRepository.getWeight(period: '3')).thenAnswer((_) async => []);
|
||||
when(mockProfileRepository.getCircumferences(period: '3')).thenAnswer((_) async => []);
|
||||
|
||||
await profileCubit!.getMyProfile(period: '3');
|
||||
|
||||
verify(mockProfileRepository.getWeight(period: '3')).called(1);
|
||||
verify(mockProfileRepository.getCircumferences(period: '3')).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user