import 'dart:convert'; import 'package:aioa_mobile/features/tasks/data/notification_repository.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/http.dart' as http; import 'package:http/testing.dart'; void main() { final unreadJson = { 'id': 'notification-1', 'type': 'LEAVE_APPROVED', 'title': '请假申请已通过', 'body': '你的请假申请已完成审批。', 'resourceType': 'LEAVE_REQUEST', 'resourceId': 'leave-1', 'createdAt': '2026-07-18T08:00:00Z', 'readAt': null, }; test('loads own notifications with bearer token', () async { late http.Request captured; final repository = NotificationRepository( baseUrl: 'https://api.example.test/api/v1', accessToken: 'token', client: MockClient((request) async { captured = request; return http.Response( jsonEncode([unreadJson]), 200, headers: {'content-type': 'application/json; charset=utf-8'}, ); }), ); final notifications = await repository.list(); expect(notifications.single.isRead, isFalse); expect(notifications.single.title, '请假申请已通过'); expect(captured.headers['Authorization'], 'Bearer token'); }); test('marks a notification read', () async { final repository = NotificationRepository( baseUrl: 'https://api.example.test/api/v1', accessToken: 'token', client: MockClient((request) async { return http.Response( jsonEncode({...unreadJson, 'readAt': '2026-07-18T08:05:00Z'}), 200, headers: {'content-type': 'application/json; charset=utf-8'}, ); }), ); final notification = await repository.markRead('notification-1'); expect(notification.isRead, isTrue); }); }