forked from eatvio/eatvio_app
feat: test profile service
This commit is contained in:
92
test/features/profile/services/profile_service_test.dart
Normal file
92
test/features/profile/services/profile_service_test.dart
Normal file
@@ -0,0 +1,92 @@
|
||||
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
|
||||
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/profile/models/weight_model.dart';
|
||||
import 'package:eatvio_app/features/profile/services/profile_service.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'profile_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ProfileService>()])
|
||||
void main() {
|
||||
group('profileService', () {
|
||||
final mockProfileService = MockProfileService();
|
||||
test('getMyProfile', () async {
|
||||
when(mockProfileService.getMyProfile()).thenAnswer(
|
||||
(_) async => await Future.value(
|
||||
ProfileModel(
|
||||
id: 0,
|
||||
name: 'Alexander Avanesyan',
|
||||
email: 'mso7nueh@mail.ru',
|
||||
isPublicProfile: true,
|
||||
isEntitySubscribedByMe: false,
|
||||
slug: 'slug',
|
||||
profilePhotoUrl: '',
|
||||
role: 'user',
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(await mockProfileService.getMyProfile(), isA<ProfileModel>());
|
||||
});
|
||||
|
||||
test('getProfileDetailsBySlug', () async {
|
||||
when(mockProfileService.getProfileDetailsBySlug(slug: 'slug')).thenAnswer(
|
||||
(_) async => await Future.value(
|
||||
ProfileDetailsModel(
|
||||
firstName: 'Alexnader',
|
||||
lastName: 'Avanesyan',
|
||||
birthdate: '2024-05-28',
|
||||
gender: 'male',
|
||||
country: 'Russia',
|
||||
city: 'Moscow',
|
||||
lang: 'Russian',
|
||||
weight: 84,
|
||||
height: 178,
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 90,
|
||||
bloodPressureUp: 120,
|
||||
bloodPressureDown: 80,
|
||||
hasHypo: false,
|
||||
hasHyper: false,
|
||||
aboutAlergy: '',
|
||||
aboutTakingPils: '',
|
||||
aboutSportHobbies: 'Judo',
|
||||
favoriteFoods: '',
|
||||
unfavoriteFoods: '',
|
||||
additionalInfo: '10 lvl faceit',
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: true,
|
||||
activityCoefficient: 2,
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(await mockProfileService.getProfileDetailsBySlug(slug: 'slug'), isA<ProfileDetailsModel>());
|
||||
});
|
||||
|
||||
test('getBlogPostByAuthorSlug', () async {
|
||||
when(mockProfileService.getBlogPostByAuthorSlug(slug: '')).thenAnswer(
|
||||
(_) async => [],
|
||||
);
|
||||
expect(await mockProfileService.getBlogPostByAuthorSlug(slug: 'slug'), isA<List<FeedBlogPostModel>>());
|
||||
});
|
||||
|
||||
test('getWeight', () async {
|
||||
when(mockProfileService.getWeight(period: '')).thenAnswer(
|
||||
(_) async => [],
|
||||
);
|
||||
expect(await mockProfileService.getWeight(period: ''), isA<List<WeightModel>>());
|
||||
});
|
||||
|
||||
test('getCircumferences', () async {
|
||||
when(mockProfileService.getCircumferences(period: '')).thenAnswer(
|
||||
(_) async => [],
|
||||
);
|
||||
expect(await mockProfileService.getCircumferences(period: ''), isA<List<CircumferenceModel>>());
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/profile/services/profile_service.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'profile_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ProfileService>()])
|
||||
void main() {
|
||||
group('fetchProfile', () {
|
||||
final mockProfileService = MockProfileService();
|
||||
|
||||
test('getMyProfile', () async {
|
||||
when(mockProfileService.getMyProfile()).thenAnswer(
|
||||
(_) async => ProfileModel(
|
||||
id: 0,
|
||||
name: 'Alexander Avanesyan',
|
||||
email: 'mso7nueh@mail.ru',
|
||||
isPublicProfile: true,
|
||||
isEntitySubscribedByMe: false,
|
||||
slug: 'slug',
|
||||
profilePhotoUrl: '',
|
||||
role: 'user',
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
),
|
||||
);
|
||||
expect(await mockProfileService.getMyProfile(), isA<ProfileModel>());
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user