142 lines
5.4 KiB
Dart
142 lines
5.4 KiB
Dart
import 'dart:io';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:metatron_student_erp/core/api/api_client.dart';
|
|
import 'package:metatron_student_erp/core/storage/secure_storage.dart';
|
|
import 'package:metatron_student_erp/repositories/attendance_repository.dart';
|
|
import 'package:metatron_student_erp/repositories/auth_repository.dart';
|
|
import 'package:metatron_student_erp/repositories/exam_repository.dart';
|
|
import 'package:metatron_student_erp/repositories/result_repository.dart';
|
|
import 'package:metatron_student_erp/repositories/student_repository.dart';
|
|
import 'package:metatron_student_erp/repositories/timetable_repository.dart';
|
|
|
|
class TestSecureStorage extends SecureStorage {
|
|
final Map<String, String> _map = {};
|
|
|
|
TestSecureStorage() : super();
|
|
|
|
@override
|
|
Future<void> saveSessionCookie(String cookie) async {
|
|
_map['session_cookie'] = cookie;
|
|
}
|
|
|
|
@override
|
|
Future<String?> getSessionCookie() async {
|
|
return _map['session_cookie'];
|
|
}
|
|
|
|
@override
|
|
Future<void> clearSessionCookie() async {
|
|
_map.remove('session_cookie');
|
|
}
|
|
|
|
@override
|
|
Future<void> clearAll() async {
|
|
_map.clear();
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
group('Live Odoo Integration Test (End-to-End)', () {
|
|
late ApiClient apiClient;
|
|
late TestSecureStorage storage;
|
|
late AuthRepository authRepo;
|
|
late StudentRepository studentRepo;
|
|
late AttendanceRepository attendanceRepo;
|
|
late TimetableRepository timetableRepo;
|
|
late ExamRepository examRepo;
|
|
late ResultRepository resultRepo;
|
|
|
|
setUpAll(() async {
|
|
storage = TestSecureStorage();
|
|
apiClient = ApiClient(storage: storage);
|
|
authRepo = AuthRepository(apiClient: apiClient);
|
|
studentRepo = StudentRepository(apiClient: apiClient);
|
|
attendanceRepo = AttendanceRepository(apiClient: apiClient);
|
|
timetableRepo = TimetableRepository(apiClient: apiClient);
|
|
examRepo = ExamRepository(apiClient: apiClient);
|
|
resultRepo = ResultRepository(apiClient: apiClient);
|
|
});
|
|
|
|
test('1. Flutter Login against live Odoo backend returns session and user', () async {
|
|
final res = await authRepo.login(
|
|
email: 'demo.student',
|
|
password: 'Demo@Student2026',
|
|
);
|
|
|
|
expect(res.user.email, 'demo.student');
|
|
expect(res.user.role, 'student');
|
|
expect(res.student, isNotNull);
|
|
expect(res.student!.id, isPositive);
|
|
|
|
final cookie = await storage.getSessionCookie();
|
|
expect(cookie, isNotNull);
|
|
expect(cookie, contains('session_id='));
|
|
stdout.writeln('--> Captured Session Cookie: [REDACTED (session_id present)]');
|
|
});
|
|
|
|
test('2. GET /api/mobile/v1/auth/me returns active session', () async {
|
|
final me = await authRepo.getMe();
|
|
expect(me.user.email, 'demo.student');
|
|
expect(me.student, isNotNull);
|
|
stdout.writeln('--> Auth Me verified: ${me.user.name}');
|
|
});
|
|
|
|
test('3. GET /api/mobile/v1/student/profile parses student profile', () async {
|
|
final profile = await studentRepo.getProfile();
|
|
expect(profile.id, isPositive);
|
|
expect(profile.studentId, isNotEmpty);
|
|
expect(profile.fullName, isNotEmpty);
|
|
stdout.writeln('--> Profile verified: ${profile.fullName} (${profile.studentId})');
|
|
});
|
|
|
|
test('4. GET /api/mobile/v1/student/dashboard returns dashboard data', () async {
|
|
final dashboard = await studentRepo.getDashboard();
|
|
expect(dashboard.attendance, isNotNull);
|
|
expect(dashboard.attendance.percentage, isNonNegative);
|
|
stdout.writeln('--> Dashboard verified. Attendance %: ${dashboard.attendance.percentage}');
|
|
});
|
|
|
|
test('5. GET /api/mobile/v1/student/attendance returns attendance summary', () async {
|
|
final attendance = await attendanceRepo.getAttendance();
|
|
expect(attendance.summary.percentage, isNonNegative);
|
|
expect(attendance.records, isNotEmpty);
|
|
expect(attendance.summary.present, greaterThanOrEqualTo(3));
|
|
stdout.writeln('--> Attendance verified: ${attendance.records.length} records, percentage: ${attendance.summary.percentage}%');
|
|
});
|
|
|
|
test('6. GET /api/mobile/v1/student/timetable returns timetable slots', () async {
|
|
final slots = await timetableRepo.getTimetable();
|
|
expect(slots, isA<List>());
|
|
expect(slots.length, greaterThan(0));
|
|
final firstSlot = slots.first;
|
|
expect(firstSlot.id, isPositive);
|
|
expect(firstSlot.date, isNotEmpty);
|
|
expect(firstSlot.startTime, isNotEmpty);
|
|
expect(firstSlot.endTime, isNotEmpty);
|
|
expect(firstSlot.subject, isNotNull);
|
|
expect(firstSlot.subject!.name, isNotEmpty);
|
|
expect(firstSlot.room, isNotNull);
|
|
stdout.writeln('--> Timetable verified: ${slots.length} slots loaded with subjects and rooms');
|
|
});
|
|
|
|
test('7. GET /api/mobile/v1/student/exams returns exams list', () async {
|
|
final exams = await examRepo.getExams();
|
|
expect(exams, isA<List>());
|
|
stdout.writeln('--> Exams verified: ${exams.length} exams found');
|
|
});
|
|
|
|
test('8. GET /api/mobile/v1/student/results returns results', () async {
|
|
final results = await resultRepo.getResults();
|
|
expect(results, isA<List>());
|
|
stdout.writeln('--> Results verified: ${results.length} results found');
|
|
});
|
|
|
|
test('9. POST /api/mobile/v1/auth/logout ends session', () async {
|
|
await authRepo.logout();
|
|
final cookie = await storage.getSessionCookie();
|
|
expect(cookie, isNull);
|
|
stdout.writeln('--> Logout verified. Session cleared.');
|
|
});
|
|
});
|
|
}
|