From 25ea4eccadbc2060094d00e3c45da9f3bf99e941 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 9 Dec 2024 17:24:10 +0300 Subject: [PATCH] feat: test profile model --- test/profile_service_test.dart | 33 +++ test/profile_service_test.mocks.dart | 414 +++++++++++++++++++++++++++ 2 files changed, 447 insertions(+) create mode 100644 test/profile_service_test.dart create mode 100644 test/profile_service_test.mocks.dart diff --git a/test/profile_service_test.dart b/test/profile_service_test.dart new file mode 100644 index 00000000..5df6d580 --- /dev/null +++ b/test/profile_service_test.dart @@ -0,0 +1,33 @@ +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()]) +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()); + }); + }); +} diff --git a/test/profile_service_test.mocks.dart b/test/profile_service_test.mocks.dart new file mode 100644 index 00000000..2361099d --- /dev/null +++ b/test/profile_service_test.mocks.dart @@ -0,0 +1,414 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in eatvio_app/test/profile_service_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i5; +import 'dart:io' as _i9; + +import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart' + as _i6; +import 'package:eatvio_app/features/profile/models/circumference_model.dart' + as _i8; +import 'package:eatvio_app/features/profile/models/profile_model.dart' as _i2; +import 'package:eatvio_app/features/profile/models/sub_model.dart' as _i3; +import 'package:eatvio_app/features/profile/models/weight_model.dart' as _i7; +import 'package:eatvio_app/features/profile/services/profile_service.dart' + as _i4; +import 'package:mockito/mockito.dart' as _i1; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeProfileModel_0 extends _i1.SmartFake implements _i2.ProfileModel { + _FakeProfileModel_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeProfileDetailsModel_1 extends _i1.SmartFake + implements _i2.ProfileDetailsModel { + _FakeProfileDetailsModel_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeSubPaginationModel_2 extends _i1.SmartFake + implements _i3.SubPaginationModel { + _FakeSubPaginationModel_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [ProfileService]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockProfileService extends _i1.Mock implements _i4.ProfileService { + @override + _i5.Future<_i2.ProfileModel> getProfileBySlug({required String? slug}) => + (super.noSuchMethod( + Invocation.method( + #getProfileBySlug, + [], + {#slug: slug}, + ), + returnValue: _i5.Future<_i2.ProfileModel>.value(_FakeProfileModel_0( + this, + Invocation.method( + #getProfileBySlug, + [], + {#slug: slug}, + ), + )), + returnValueForMissingStub: + _i5.Future<_i2.ProfileModel>.value(_FakeProfileModel_0( + this, + Invocation.method( + #getProfileBySlug, + [], + {#slug: slug}, + ), + )), + ) as _i5.Future<_i2.ProfileModel>); + + @override + _i5.Future<_i2.ProfileModel> getMyProfile() => (super.noSuchMethod( + Invocation.method( + #getMyProfile, + [], + ), + returnValue: _i5.Future<_i2.ProfileModel>.value(_FakeProfileModel_0( + this, + Invocation.method( + #getMyProfile, + [], + ), + )), + returnValueForMissingStub: + _i5.Future<_i2.ProfileModel>.value(_FakeProfileModel_0( + this, + Invocation.method( + #getMyProfile, + [], + ), + )), + ) as _i5.Future<_i2.ProfileModel>); + + @override + _i5.Future<_i2.ProfileDetailsModel> getMyProfileDetails() => + (super.noSuchMethod( + Invocation.method( + #getMyProfileDetails, + [], + ), + returnValue: _i5.Future<_i2.ProfileDetailsModel>.value( + _FakeProfileDetailsModel_1( + this, + Invocation.method( + #getMyProfileDetails, + [], + ), + )), + returnValueForMissingStub: _i5.Future<_i2.ProfileDetailsModel>.value( + _FakeProfileDetailsModel_1( + this, + Invocation.method( + #getMyProfileDetails, + [], + ), + )), + ) as _i5.Future<_i2.ProfileDetailsModel>); + + @override + _i5.Future<_i2.ProfileDetailsModel> getProfileDetailsBySlug( + {required String? slug}) => + (super.noSuchMethod( + Invocation.method( + #getProfileDetailsBySlug, + [], + {#slug: slug}, + ), + returnValue: _i5.Future<_i2.ProfileDetailsModel>.value( + _FakeProfileDetailsModel_1( + this, + Invocation.method( + #getProfileDetailsBySlug, + [], + {#slug: slug}, + ), + )), + returnValueForMissingStub: _i5.Future<_i2.ProfileDetailsModel>.value( + _FakeProfileDetailsModel_1( + this, + Invocation.method( + #getProfileDetailsBySlug, + [], + {#slug: slug}, + ), + )), + ) as _i5.Future<_i2.ProfileDetailsModel>); + + @override + _i5.Future addCircumference({ + required int? chestCircumference, + required int? waistCircumference, + required int? hipCircumference, + }) => + (super.noSuchMethod( + Invocation.method( + #addCircumference, + [], + { + #chestCircumference: chestCircumference, + #waistCircumference: waistCircumference, + #hipCircumference: hipCircumference, + }, + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future addWeight({required double? weight}) => (super.noSuchMethod( + Invocation.method( + #addWeight, + [], + {#weight: weight}, + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future> getBlogPostByAuthorSlug( + {required String? slug}) => + (super.noSuchMethod( + Invocation.method( + #getBlogPostByAuthorSlug, + [], + {#slug: slug}, + ), + returnValue: _i5.Future>.value( + <_i6.FeedBlogPostModel>[]), + returnValueForMissingStub: + _i5.Future>.value( + <_i6.FeedBlogPostModel>[]), + ) as _i5.Future>); + + @override + _i5.Future> getWeight({required String? period}) => + (super.noSuchMethod( + Invocation.method( + #getWeight, + [], + {#period: period}, + ), + returnValue: + _i5.Future>.value(<_i7.WeightModel>[]), + returnValueForMissingStub: + _i5.Future>.value(<_i7.WeightModel>[]), + ) as _i5.Future>); + + @override + _i5.Future> getWeightBySlug({ + required String? period, + required String? slug, + }) => + (super.noSuchMethod( + Invocation.method( + #getWeightBySlug, + [], + { + #period: period, + #slug: slug, + }, + ), + returnValue: + _i5.Future>.value(<_i7.WeightModel>[]), + returnValueForMissingStub: + _i5.Future>.value(<_i7.WeightModel>[]), + ) as _i5.Future>); + + @override + _i5.Future> getCircumferences( + {required String? period}) => + (super.noSuchMethod( + Invocation.method( + #getCircumferences, + [], + {#period: period}, + ), + returnValue: _i5.Future>.value( + <_i8.CircumferenceModel>[]), + returnValueForMissingStub: + _i5.Future>.value( + <_i8.CircumferenceModel>[]), + ) as _i5.Future>); + + @override + _i5.Future> getCircumferencesBySlug({ + required String? period, + required String? slug, + }) => + (super.noSuchMethod( + Invocation.method( + #getCircumferencesBySlug, + [], + { + #period: period, + #slug: slug, + }, + ), + returnValue: _i5.Future>.value( + <_i8.CircumferenceModel>[]), + returnValueForMissingStub: + _i5.Future>.value( + <_i8.CircumferenceModel>[]), + ) as _i5.Future>); + + @override + _i5.Future<_i3.SubPaginationModel> getSubscribers({ + required String? slug, + String? query, + }) => + (super.noSuchMethod( + Invocation.method( + #getSubscribers, + [], + { + #slug: slug, + #query: query, + }, + ), + returnValue: + _i5.Future<_i3.SubPaginationModel>.value(_FakeSubPaginationModel_2( + this, + Invocation.method( + #getSubscribers, + [], + { + #slug: slug, + #query: query, + }, + ), + )), + returnValueForMissingStub: + _i5.Future<_i3.SubPaginationModel>.value(_FakeSubPaginationModel_2( + this, + Invocation.method( + #getSubscribers, + [], + { + #slug: slug, + #query: query, + }, + ), + )), + ) as _i5.Future<_i3.SubPaginationModel>); + + @override + _i5.Future<_i3.SubPaginationModel> getSubscriptions({ + required String? slug, + String? query, + }) => + (super.noSuchMethod( + Invocation.method( + #getSubscriptions, + [], + { + #slug: slug, + #query: query, + }, + ), + returnValue: + _i5.Future<_i3.SubPaginationModel>.value(_FakeSubPaginationModel_2( + this, + Invocation.method( + #getSubscriptions, + [], + { + #slug: slug, + #query: query, + }, + ), + )), + returnValueForMissingStub: + _i5.Future<_i3.SubPaginationModel>.value(_FakeSubPaginationModel_2( + this, + Invocation.method( + #getSubscriptions, + [], + { + #slug: slug, + #query: query, + }, + ), + )), + ) as _i5.Future<_i3.SubPaginationModel>); + + @override + _i5.Future subscribe({required String? slug}) => (super.noSuchMethod( + Invocation.method( + #subscribe, + [], + {#slug: slug}, + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future unsubscribe({required String? slug}) => (super.noSuchMethod( + Invocation.method( + #unsubscribe, + [], + {#slug: slug}, + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future uploadPhoto({required _i9.File? photo}) => + (super.noSuchMethod( + Invocation.method( + #uploadPhoto, + [], + {#photo: photo}, + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future deletePhoto() => (super.noSuchMethod( + Invocation.method( + #deletePhoto, + [], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); +}