feat: BLoC tests complets + sécurité production + freerasp 7.5.1 migration

## Tests BLoC (Task P2.4 Mobile)
- 25 nouveaux fichiers *_bloc_test.dart + mocks générés (build_runner)
- Features couvertes : authentication, admin_users, adhesions, backup,
  communication/messaging, contributions, dashboard, finance (approval/budget),
  events, explore/network, feed, logs_monitoring, notifications, onboarding,
  organizations (switcher/types/CRUD), profile, reports, settings, solidarity
- ~380 tests, > 80% coverage BLoCs

## Sécurité Production (Task P2.2)
- lib/core/security/app_integrity_service.dart (freerasp 7.5.1)
- Migration API breaking changes freerasp 7.5.1 :
  - onRootDetected → onPrivilegedAccess
  - onDebuggerDetected → onDebug
  - onSignatureDetected → onAppIntegrity
  - onHookDetected → onHooks
  - onEmulatorDetected → onSimulator
  - onUntrustedInstallationSourceDetected → onUnofficialStore
  - onDeviceBindingDetected → onDeviceBinding
  - onObfuscationIssuesDetected → onObfuscationIssues
  - Talsec.start() split → start() + attachListener()
  - const AndroidConfig/IOSConfig → final (constructors call ConfigVerifier)
  - supportedAlternativeStores → supportedStores

## Pubspec
- bloc_test: ^9.1.7 → ^10.0.0 (compat flutter_bloc ^9.0.0)
- freerasp 7.5.1

## Config
- android/app/build.gradle : ajustements release
- lib/core/config/environment.dart : URLs API actualisées
- lib/main.dart + app_router : intégrations sécurité/BLoC

## Cleanup
- Suppression docs intermédiaires (TACHES_*.md, TASK_*_COMPLETION_REPORT.md,
  TESTS_UNITAIRES_PROGRESS.md)
- .g.dart régénérés (json_serializable)
- .mocks.dart régénérés (mockito)

## Résultat
- 142 fichiers, +27 596 insertions
- Toutes les tâches P2 mobile complétées

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
dahoud
2026-04-21 12:42:35 +00:00
parent 33f5b5a707
commit 37db88672b
142 changed files with 27599 additions and 16068 deletions

View File

@@ -0,0 +1,366 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:dio/dio.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:unionflow_mobile_apps/core/config/environment.dart';
import 'package:unionflow_mobile_apps/features/notifications/data/repositories/notification_feed_repository.dart';
import 'package:unionflow_mobile_apps/features/notifications/presentation/bloc/notification_bloc.dart';
import 'package:unionflow_mobile_apps/features/notifications/presentation/bloc/notification_event.dart';
import 'package:unionflow_mobile_apps/features/notifications/presentation/bloc/notification_state.dart';
@GenerateMocks([NotificationFeedRepository])
import 'notification_bloc_test.mocks.dart';
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
NotificationItem _makeItem({
String id = 'item-1',
String title = 'Test Notification',
String body = 'Corps du message',
bool isRead = false,
String category = 'system',
}) =>
NotificationItem(
id: id,
title: title,
body: body,
date: DateTime(2026, 4, 20),
isRead: isRead,
category: category,
);
DioException _cancelException() => DioException(
requestOptions: RequestOptions(path: '/notifications'),
type: DioExceptionType.cancel,
);
// ---------------------------------------------------------------------------
void main() {
late MockNotificationFeedRepository mockRepository;
setUpAll(() {
try {
AppConfig.initialize();
} catch (_) {
// Already initialized.
}
});
NotificationBloc buildBloc() => NotificationBloc(mockRepository);
setUp(() {
mockRepository = MockNotificationFeedRepository();
});
// ─── Initial state ────────────────────────────────────────────────────────
group('initial state', () {
test('is NotificationInitial', () {
expect(buildBloc().state, isA<NotificationInitial>());
});
});
// ─── LoadNotificationsRequested ───────────────────────────────────────────
group('LoadNotificationsRequested', () {
final items = [
_makeItem(),
_makeItem(id: 'item-2', title: 'Finance Alert', category: 'finance'),
_makeItem(id: 'item-3', title: 'Event', category: 'event', isRead: true),
];
blocTest<NotificationBloc, NotificationState>(
'emits [Loading, Loaded] with items on success',
build: buildBloc,
setUp: () =>
when(mockRepository.getNotifications()).thenAnswer((_) async => items),
act: (b) => b.add(LoadNotificationsRequested()),
expect: () => [
isA<NotificationLoading>(),
isA<NotificationLoaded>()
.having((s) => s.items.length, 'count', 3)
.having((s) => s.items.first.id, 'first id', 'item-1'),
],
);
blocTest<NotificationBloc, NotificationState>(
'emits [Loading, Loaded(empty)] when repository returns empty list',
build: buildBloc,
setUp: () =>
when(mockRepository.getNotifications()).thenAnswer((_) async => []),
act: (b) => b.add(LoadNotificationsRequested()),
expect: () => [
isA<NotificationLoading>(),
isA<NotificationLoaded>().having((s) => s.items, 'items', isEmpty),
],
);
blocTest<NotificationBloc, NotificationState>(
'emits [Loading, Error] on generic exception',
build: buildBloc,
setUp: () =>
when(mockRepository.getNotifications()).thenThrow(Exception('network')),
act: (b) => b.add(LoadNotificationsRequested()),
expect: () => [
isA<NotificationLoading>(),
isA<NotificationError>()
.having((e) => e.message, 'message', contains('chargement')),
],
);
blocTest<NotificationBloc, NotificationState>(
'emits [Loading, Error] on DioException (non-cancel)',
build: buildBloc,
setUp: () => when(mockRepository.getNotifications()).thenThrow(
DioException(
requestOptions: RequestOptions(path: '/notifications'),
type: DioExceptionType.connectionError,
),
),
act: (b) => b.add(LoadNotificationsRequested()),
expect: () => [
isA<NotificationLoading>(),
isA<NotificationError>(),
],
);
blocTest<NotificationBloc, NotificationState>(
'swallows DioException.cancel — no error emitted',
build: buildBloc,
setUp: () =>
when(mockRepository.getNotifications()).thenThrow(_cancelException()),
act: (b) => b.add(LoadNotificationsRequested()),
expect: () => [isA<NotificationLoading>()],
);
blocTest<NotificationBloc, NotificationState>(
'calls getNotifications exactly once',
build: buildBloc,
setUp: () =>
when(mockRepository.getNotifications()).thenAnswer((_) async => items),
act: (b) => b.add(LoadNotificationsRequested()),
verify: (_) => verify(mockRepository.getNotifications()).called(1),
);
});
// ─── NotificationMarkedAsRead ─────────────────────────────────────────────
group('NotificationMarkedAsRead', () {
final items = [
_makeItem(id: 'item-1', isRead: false),
_makeItem(id: 'item-2', isRead: false),
_makeItem(id: 'item-3', isRead: true),
];
final loadedState = NotificationLoaded(items: items);
blocTest<NotificationBloc, NotificationState>(
'emits Loaded with target item marked as read',
build: buildBloc,
seed: () => loadedState,
setUp: () =>
when(mockRepository.markAsRead('item-1')).thenAnswer((_) async {}),
act: (b) => b.add(const NotificationMarkedAsRead('item-1')),
expect: () => [
isA<NotificationLoaded>()
.having(
(s) => s.items.firstWhere((i) => i.id == 'item-1').isRead,
'item-1 isRead',
true,
)
.having(
(s) => s.items.firstWhere((i) => i.id == 'item-2').isRead,
'item-2 unchanged',
false,
),
],
);
blocTest<NotificationBloc, NotificationState>(
'preserves all other item properties after marking read',
build: buildBloc,
seed: () => loadedState,
setUp: () =>
when(mockRepository.markAsRead('item-1')).thenAnswer((_) async {}),
act: (b) => b.add(const NotificationMarkedAsRead('item-1')),
expect: () => [
isA<NotificationLoaded>().having(
(s) => s.items.firstWhere((i) => i.id == 'item-1').title,
'title preserved',
'Test Notification',
),
],
);
blocTest<NotificationBloc, NotificationState>(
'no re-emission when id not found (items unchanged, equatable dedup)',
build: buildBloc,
seed: () => loadedState,
setUp: () =>
when(mockRepository.markAsRead('unknown')).thenAnswer((_) async {}),
act: (b) => b.add(const NotificationMarkedAsRead('unknown')),
// The map returns the same object references for non-matching items,
// resulting in an identical NotificationLoaded state — no re-emission.
expect: () => [],
);
blocTest<NotificationBloc, NotificationState>(
'does nothing when state is not NotificationLoaded',
build: buildBloc,
// state is NotificationInitial
act: (b) => b.add(const NotificationMarkedAsRead('item-1')),
expect: () => [],
);
blocTest<NotificationBloc, NotificationState>(
'does nothing when state is NotificationLoading',
build: buildBloc,
seed: () => NotificationLoading(),
act: (b) => b.add(const NotificationMarkedAsRead('item-1')),
expect: () => [],
);
blocTest<NotificationBloc, NotificationState>(
'emits Error when markAsRead throws',
build: buildBloc,
seed: () => loadedState,
setUp: () =>
when(mockRepository.markAsRead(any)).thenThrow(Exception('server error')),
act: (b) => b.add(const NotificationMarkedAsRead('item-1')),
expect: () => [
isA<NotificationError>()
.having((e) => e.message, 'message', contains('marquer')),
],
);
blocTest<NotificationBloc, NotificationState>(
'swallows DioException.cancel in markAsRead',
build: buildBloc,
seed: () => loadedState,
setUp: () =>
when(mockRepository.markAsRead(any)).thenThrow(_cancelException()),
act: (b) => b.add(const NotificationMarkedAsRead('item-1')),
expect: () => [],
);
blocTest<NotificationBloc, NotificationState>(
'calls markAsRead with correct id',
build: buildBloc,
seed: () => loadedState,
setUp: () =>
when(mockRepository.markAsRead('item-2')).thenAnswer((_) async {}),
act: (b) => b.add(const NotificationMarkedAsRead('item-2')),
verify: (_) => verify(mockRepository.markAsRead('item-2')).called(1),
);
blocTest<NotificationBloc, NotificationState>(
'marking already-read item produces same state (no re-emission)',
build: buildBloc,
seed: () => loadedState,
setUp: () =>
when(mockRepository.markAsRead('item-3')).thenAnswer((_) async {}),
act: (b) => b.add(const NotificationMarkedAsRead('item-3')),
// Re-marking an already-read item rebuilds NotificationLoaded with
// identical items (isRead=true stays true). Equatable dedup prevents
// re-emission because the resulting state equals the current state.
expect: () => [],
);
});
// ─── Combined flows ───────────────────────────────────────────────────────
group('combined flows', () {
final items = [
_makeItem(id: 'a', isRead: false),
_makeItem(id: 'b', isRead: false),
];
blocTest<NotificationBloc, NotificationState>(
'load then mark as read produces correct final state',
build: buildBloc,
setUp: () {
when(mockRepository.getNotifications()).thenAnswer((_) async => items);
when(mockRepository.markAsRead('a')).thenAnswer((_) async {});
},
act: (b) async {
b.add(LoadNotificationsRequested());
await Future.delayed(Duration.zero);
b.add(const NotificationMarkedAsRead('a'));
},
expect: () => [
isA<NotificationLoading>(),
isA<NotificationLoaded>().having((s) => s.items.length, 'count', 2),
isA<NotificationLoaded>().having(
(s) => s.items.firstWhere((i) => i.id == 'a').isRead,
'a is read',
true,
),
],
);
blocTest<NotificationBloc, NotificationState>(
'reload after mark as read reflects fresh data',
build: buildBloc,
setUp: () {
final updated = [
_makeItem(id: 'a', isRead: true),
_makeItem(id: 'b', isRead: false),
];
when(mockRepository.getNotifications())
.thenAnswer((_) async => updated);
},
seed: () => NotificationLoaded(items: items),
act: (b) => b.add(LoadNotificationsRequested()),
expect: () => [
isA<NotificationLoading>(),
isA<NotificationLoaded>().having(
(s) => s.items.firstWhere((i) => i.id == 'a').isRead,
'a is read after reload',
true,
),
],
);
});
// ─── NotificationItem equality ────────────────────────────────────────────
group('NotificationItem', () {
test('two items with same data are equal', () {
final a = _makeItem();
final b = _makeItem();
expect(a, b);
});
test('items with different isRead are not equal', () {
final a = _makeItem(isRead: false);
final b = _makeItem(isRead: true);
expect(a, isNot(b));
});
test('items with different category are not equal', () {
final a = _makeItem(category: 'system');
final b = _makeItem(category: 'finance');
expect(a, isNot(b));
});
});
// ─── State equality ───────────────────────────────────────────────────────
group('State equality', () {
final items = [_makeItem()];
test('NotificationLoaded with same items are equal', () {
expect(NotificationLoaded(items: items), NotificationLoaded(items: items));
});
test('NotificationError with same message are equal', () {
expect(
const NotificationError('fail'),
const NotificationError('fail'),
);
});
});
}

View File

@@ -0,0 +1,56 @@
// Mocks generated by Mockito 5.4.6 from annotations
// in unionflow_mobile_apps/test/features/notifications/bloc/notification_bloc_test.dart.
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i3;
import 'package:mockito/mockito.dart' as _i1;
import 'package:unionflow_mobile_apps/features/notifications/data/repositories/notification_feed_repository.dart'
as _i2;
import 'package:unionflow_mobile_apps/features/notifications/presentation/bloc/notification_state.dart'
as _i4;
// 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: must_be_immutable
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
/// A class which mocks [NotificationFeedRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockNotificationFeedRepository extends _i1.Mock
implements _i2.NotificationFeedRepository {
MockNotificationFeedRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i3.Future<List<_i4.NotificationItem>> getNotifications() =>
(super.noSuchMethod(
Invocation.method(#getNotifications, []),
returnValue: _i3.Future<List<_i4.NotificationItem>>.value(
<_i4.NotificationItem>[],
),
)
as _i3.Future<List<_i4.NotificationItem>>);
@override
_i3.Future<void> markAsRead(String? id) =>
(super.noSuchMethod(
Invocation.method(#markAsRead, [id]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
}

View File

@@ -0,0 +1,360 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:dio/dio.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:unionflow_mobile_apps/core/config/environment.dart';
import 'package:unionflow_mobile_apps/features/notifications/data/models/notification_model.dart';
import 'package:unionflow_mobile_apps/features/notifications/data/repositories/notification_repository.dart';
import 'package:unionflow_mobile_apps/features/notifications/presentation/bloc/notifications_bloc.dart';
@GenerateMocks([NotificationRepository])
import 'notifications_bloc_test.mocks.dart';
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
NotificationModel _makeNotification({
String id = 'notif-1',
String type = 'SYSTEME',
bool read = false,
String? statut,
}) =>
NotificationModel(
id: id,
typeNotification: type,
sujet: 'Sujet $id',
corps: 'Corps de la notification',
statut: statut ?? (read ? 'LUE' : 'NON_LUE'),
dateLecture: read ? DateTime(2026, 1, 1) : null,
);
DioException _makeDioException({int? statusCode, DioExceptionType? type}) =>
DioException(
requestOptions: RequestOptions(path: '/notifications'),
response: statusCode != null
? Response(
requestOptions: RequestOptions(path: '/notifications'),
statusCode: statusCode,
)
: null,
type: type ?? DioExceptionType.connectionError,
);
// ---------------------------------------------------------------------------
void main() {
late MockNotificationRepository mockRepository;
setUpAll(() {
try {
AppConfig.initialize();
} catch (_) {
// Already initialized.
}
});
NotificationsBloc buildBloc() => NotificationsBloc(mockRepository);
setUp(() {
mockRepository = MockNotificationRepository();
});
// ─── Initial state ────────────────────────────────────────────────────────
group('initial state', () {
test('is NotificationsInitial', () {
expect(buildBloc().state, const NotificationsInitial());
});
});
// ─── LoadNotifications ────────────────────────────────────────────────────
group('LoadNotifications', () {
final notifs = [
_makeNotification(),
_makeNotification(id: 'notif-2', read: true),
];
blocTest<NotificationsBloc, NotificationsState>(
'calls getMesNotifications when membreId is null',
build: buildBloc,
setUp: () =>
when(mockRepository.getMesNotifications()).thenAnswer((_) async => notifs),
act: (b) => b.add(const LoadNotifications()),
verify: (_) {
verify(mockRepository.getMesNotifications()).called(1);
verifyNever(mockRepository.getNotificationsByMembre(any));
},
);
blocTest<NotificationsBloc, NotificationsState>(
'calls getMesNotifications when membreId is empty string',
build: buildBloc,
setUp: () =>
when(mockRepository.getMesNotifications()).thenAnswer((_) async => notifs),
act: (b) => b.add(const LoadNotifications(membreId: '')),
verify: (_) {
verify(mockRepository.getMesNotifications()).called(1);
},
);
blocTest<NotificationsBloc, NotificationsState>(
'calls getNotificationsByMembre when membreId is provided',
build: buildBloc,
setUp: () => when(mockRepository.getNotificationsByMembre('membre-42'))
.thenAnswer((_) async => notifs),
act: (b) => b.add(const LoadNotifications(membreId: 'membre-42')),
verify: (_) {
verify(mockRepository.getNotificationsByMembre('membre-42')).called(1);
verifyNever(mockRepository.getMesNotifications());
},
);
blocTest<NotificationsBloc, NotificationsState>(
'emits [Loading, Loaded] with correct nonLuesCount',
build: buildBloc,
setUp: () =>
when(mockRepository.getMesNotifications()).thenAnswer((_) async => notifs),
act: (b) => b.add(const LoadNotifications()),
expect: () => [
const NotificationsLoading(),
isA<NotificationsLoaded>()
.having((s) => s.notifications.length, 'count', 2)
.having((s) => s.nonLuesCount, 'nonLues', 1),
],
);
blocTest<NotificationsBloc, NotificationsState>(
'emits [Loading, Loaded(empty)] when no notifications',
build: buildBloc,
setUp: () =>
when(mockRepository.getMesNotifications()).thenAnswer((_) async => []),
act: (b) => b.add(const LoadNotifications()),
expect: () => [
const NotificationsLoading(),
const NotificationsLoaded(notifications: [], nonLuesCount: 0),
],
);
blocTest<NotificationsBloc, NotificationsState>(
'emits [Loading, Error] with 401 message on DioException 401',
build: buildBloc,
setUp: () => when(mockRepository.getMesNotifications())
.thenThrow(_makeDioException(statusCode: 401)),
act: (b) => b.add(const LoadNotifications()),
expect: () => [
const NotificationsLoading(),
isA<NotificationsError>()
.having((e) => e.message, 'message', 'Non autorisé.'),
],
);
blocTest<NotificationsBloc, NotificationsState>(
'emits [Loading, Error] with 403 message on DioException 403',
build: buildBloc,
setUp: () => when(mockRepository.getMesNotifications())
.thenThrow(_makeDioException(statusCode: 403)),
act: (b) => b.add(const LoadNotifications()),
expect: () => [
const NotificationsLoading(),
isA<NotificationsError>()
.having((e) => e.message, 'message', 'Accès refusé.'),
],
);
blocTest<NotificationsBloc, NotificationsState>(
'emits [Loading, Error] with server error on DioException 500',
build: buildBloc,
setUp: () => when(mockRepository.getMesNotifications())
.thenThrow(_makeDioException(statusCode: 500)),
act: (b) => b.add(const LoadNotifications()),
expect: () => [
const NotificationsLoading(),
isA<NotificationsError>()
.having((e) => e.message, 'message', 'Erreur serveur.'),
],
);
blocTest<NotificationsBloc, NotificationsState>(
'emits [Loading, Error] with network error on connection error',
build: buildBloc,
setUp: () => when(mockRepository.getMesNotifications())
.thenThrow(_makeDioException()),
act: (b) => b.add(const LoadNotifications()),
expect: () => [
const NotificationsLoading(),
isA<NotificationsError>()
.having((e) => e.message, 'message', contains('réseau')),
],
);
blocTest<NotificationsBloc, NotificationsState>(
'emits [Loading, Error] on generic exception',
build: buildBloc,
setUp: () =>
when(mockRepository.getMesNotifications()).thenThrow(Exception('unexpected')),
act: (b) => b.add(const LoadNotifications()),
expect: () => [
const NotificationsLoading(),
isA<NotificationsError>()
.having((e) => e.message, 'message', contains('chargement')),
],
);
blocTest<NotificationsBloc, NotificationsState>(
'swallows DioException.cancel (no error emitted)',
build: buildBloc,
setUp: () => when(mockRepository.getMesNotifications()).thenThrow(
_makeDioException(type: DioExceptionType.cancel),
),
act: (b) => b.add(const LoadNotifications()),
expect: () => [const NotificationsLoading()],
);
});
// ─── MarkNotificationAsRead ───────────────────────────────────────────────
group('MarkNotificationAsRead', () {
final unread = _makeNotification(id: 'notif-1');
final read = _makeNotification(id: 'notif-2', read: true);
final loadedState = NotificationsLoaded(
notifications: [unread, read],
nonLuesCount: 1,
);
blocTest<NotificationsBloc, NotificationsState>(
'emits NotificationMarkedAsRead with updated list and decremented count',
build: buildBloc,
seed: () => loadedState,
setUp: () =>
when(mockRepository.marquerCommeLue('notif-1')).thenAnswer((_) async {}),
act: (b) => b.add(const MarkNotificationAsRead('notif-1')),
expect: () => [
isA<NotificationMarkedAsRead>()
.having((s) => s.nonLuesCount, 'nonLues', 0)
.having(
(s) => s.notifications.firstWhere((n) => n.id == 'notif-1').statut,
'statut',
'LUE',
),
],
);
blocTest<NotificationsBloc, NotificationsState>(
'does nothing when state is not NotificationsLoaded',
build: buildBloc,
act: (b) => b.add(const MarkNotificationAsRead('notif-1')),
expect: () => [],
);
blocTest<NotificationsBloc, NotificationsState>(
'emits Error when marquerCommeLue throws',
build: buildBloc,
seed: () => loadedState,
setUp: () =>
when(mockRepository.marquerCommeLue(any)).thenThrow(Exception('fail')),
act: (b) => b.add(const MarkNotificationAsRead('notif-1')),
expect: () => [
isA<NotificationsError>()
.having((e) => e.message, 'message', contains('marquer')),
],
);
blocTest<NotificationsBloc, NotificationsState>(
'swallows DioException.cancel in markAsRead',
build: buildBloc,
seed: () => loadedState,
setUp: () => when(mockRepository.marquerCommeLue(any)).thenThrow(
_makeDioException(type: DioExceptionType.cancel),
),
act: (b) => b.add(const MarkNotificationAsRead('notif-1')),
expect: () => [],
);
blocTest<NotificationsBloc, NotificationsState>(
'notification not in list is left unchanged',
build: buildBloc,
seed: () => loadedState,
setUp: () =>
when(mockRepository.marquerCommeLue('unknown')).thenAnswer((_) async {}),
act: (b) => b.add(const MarkNotificationAsRead('unknown')),
expect: () => [
isA<NotificationMarkedAsRead>()
.having((s) => s.nonLuesCount, 'nonLues', 1), // unchanged
],
);
});
// ─── RefreshNotifications ─────────────────────────────────────────────────
group('RefreshNotifications', () {
final notifs = [_makeNotification()];
blocTest<NotificationsBloc, NotificationsState>(
'triggers LoadNotifications with null membreId',
build: buildBloc,
setUp: () =>
when(mockRepository.getMesNotifications()).thenAnswer((_) async => notifs),
act: (b) => b.add(const RefreshNotifications()),
expect: () => [
const NotificationsLoading(),
isA<NotificationsLoaded>(),
],
);
blocTest<NotificationsBloc, NotificationsState>(
'triggers LoadNotifications with given membreId',
build: buildBloc,
setUp: () => when(mockRepository.getNotificationsByMembre('m-99'))
.thenAnswer((_) async => notifs),
act: (b) => b.add(const RefreshNotifications('m-99')),
expect: () => [
const NotificationsLoading(),
isA<NotificationsLoaded>(),
],
verify: (_) {
verify(mockRepository.getNotificationsByMembre('m-99')).called(1);
},
);
});
// ─── NotificationModel helpers ────────────────────────────────────────────
group('NotificationModel', () {
test('estLue is true when statut == LUE', () {
final n = _makeNotification(statut: 'LUE');
expect(n.estLue, true);
});
test('estLue is true when dateLecture is set', () {
final n = NotificationModel(
id: 'x',
typeNotification: 'SYSTEME',
dateLecture: DateTime.now(),
);
expect(n.estLue, true);
});
test('estLue is false when neither statut nor dateLecture', () {
final n = _makeNotification();
expect(n.estLue, false);
});
test('typeAffichage returns correct labels', () {
expect(
NotificationModel(id: 'x', typeNotification: 'EVENEMENT').typeAffichage,
'Événements',
);
expect(
NotificationModel(id: 'x', typeNotification: 'COTISATION').typeAffichage,
'Cotisations',
);
expect(
NotificationModel(id: 'x', typeNotification: 'UNKNOWN').typeAffichage,
'Système',
);
});
});
}

View File

@@ -0,0 +1,98 @@
// Mocks generated by Mockito 5.4.6 from annotations
// in unionflow_mobile_apps/test/features/notifications/bloc/notifications_bloc_test.dart.
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i3;
import 'package:mockito/mockito.dart' as _i1;
import 'package:unionflow_mobile_apps/features/notifications/data/models/notification_model.dart'
as _i4;
import 'package:unionflow_mobile_apps/features/notifications/data/repositories/notification_repository.dart'
as _i2;
// 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: must_be_immutable
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
// ignore_for_file: invalid_use_of_internal_member
/// A class which mocks [NotificationRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockNotificationRepository extends _i1.Mock
implements _i2.NotificationRepository {
MockNotificationRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i3.Future<List<_i4.NotificationModel>> getMesNotifications() =>
(super.noSuchMethod(
Invocation.method(#getMesNotifications, []),
returnValue: _i3.Future<List<_i4.NotificationModel>>.value(
<_i4.NotificationModel>[],
),
)
as _i3.Future<List<_i4.NotificationModel>>);
@override
_i3.Future<List<_i4.NotificationModel>> getMesNonLues() =>
(super.noSuchMethod(
Invocation.method(#getMesNonLues, []),
returnValue: _i3.Future<List<_i4.NotificationModel>>.value(
<_i4.NotificationModel>[],
),
)
as _i3.Future<List<_i4.NotificationModel>>);
@override
_i3.Future<List<_i4.NotificationModel>> getNotificationsByMembre(
String? membreId,
) =>
(super.noSuchMethod(
Invocation.method(#getNotificationsByMembre, [membreId]),
returnValue: _i3.Future<List<_i4.NotificationModel>>.value(
<_i4.NotificationModel>[],
),
)
as _i3.Future<List<_i4.NotificationModel>>);
@override
_i3.Future<List<_i4.NotificationModel>> getNonLuesByMembre(
String? membreId,
) =>
(super.noSuchMethod(
Invocation.method(#getNonLuesByMembre, [membreId]),
returnValue: _i3.Future<List<_i4.NotificationModel>>.value(
<_i4.NotificationModel>[],
),
)
as _i3.Future<List<_i4.NotificationModel>>);
@override
_i3.Future<_i4.NotificationModel?> getNotificationById(String? id) =>
(super.noSuchMethod(
Invocation.method(#getNotificationById, [id]),
returnValue: _i3.Future<_i4.NotificationModel?>.value(),
)
as _i3.Future<_i4.NotificationModel?>);
@override
_i3.Future<void> marquerCommeLue(String? id) =>
(super.noSuchMethod(
Invocation.method(#marquerCommeLue, [id]),
returnValue: _i3.Future<void>.value(),
returnValueForMissingStub: _i3.Future<void>.value(),
)
as _i3.Future<void>);
}