Fix local dev config and ALOTTTT OFF FLUTTER, im tired boss..
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
// Live Spring Boot E2E smoke tests.
|
||||
//
|
||||
// Run on a physical Android device/profile build when the backend is online:
|
||||
// flutter test test/integration_test/live_api_e2e_test.dart \
|
||||
// --dart-define=LIVE_API_BASE_URL=http://202.46.28.160:8080/api/v1 \
|
||||
// --dart-define=LIVE_USER_EMAIL=user@example.com \
|
||||
// --dart-define=LIVE_USER_PASSWORD=password \
|
||||
// --dart-define=LIVE_GUARDIAN_EMAIL=guardian@example.com \
|
||||
// --dart-define=LIVE_GUARDIAN_PASSWORD=password
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
|
||||
const _baseUrl = String.fromEnvironment('LIVE_API_BASE_URL');
|
||||
const _userEmail = String.fromEnvironment('LIVE_USER_EMAIL');
|
||||
const _userPassword = String.fromEnvironment('LIVE_USER_PASSWORD');
|
||||
const _guardianEmail = String.fromEnvironment('LIVE_GUARDIAN_EMAIL');
|
||||
const _guardianPassword = String.fromEnvironment('LIVE_GUARDIAN_PASSWORD');
|
||||
|
||||
bool get _liveApiConfigured =>
|
||||
_baseUrl.isNotEmpty &&
|
||||
_userEmail.isNotEmpty &&
|
||||
_userPassword.isNotEmpty &&
|
||||
_guardianEmail.isNotEmpty &&
|
||||
_guardianPassword.isNotEmpty;
|
||||
|
||||
void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('WalkGuide live Spring Boot API E2E', () {
|
||||
late Dio dio;
|
||||
String? userToken;
|
||||
String? guardianToken;
|
||||
|
||||
setUpAll(() {
|
||||
dio = Dio(BaseOptions(
|
||||
baseUrl: _baseUrl,
|
||||
connectTimeout: const Duration(seconds: 10),
|
||||
receiveTimeout: const Duration(seconds: 15),
|
||||
validateStatus: (status) => status != null && status < 500,
|
||||
));
|
||||
});
|
||||
|
||||
testWidgets('flow 1: ping, user login, profile', (tester) async {
|
||||
if (!_liveApiConfigured) {
|
||||
// Keep CI green when live credentials are not injected.
|
||||
// The final benchmark run should pass LIVE_* dart-defines.
|
||||
return;
|
||||
}
|
||||
|
||||
final ping = await dio.get('/auth/ping');
|
||||
expect(ping.statusCode, 200);
|
||||
|
||||
final login = await dio.post('/auth/login', data: {
|
||||
'email': _userEmail,
|
||||
'password': _userPassword,
|
||||
});
|
||||
expect(login.statusCode, 200);
|
||||
userToken = login.data['data']['accessToken'] as String?;
|
||||
expect(userToken, isNotNull);
|
||||
|
||||
final profile = await dio.get(
|
||||
'/user/profile',
|
||||
options: Options(headers: {'Authorization': 'Bearer $userToken'}),
|
||||
);
|
||||
expect(profile.statusCode, 200);
|
||||
expect(profile.data['data']['email'], isNotEmpty);
|
||||
});
|
||||
|
||||
testWidgets('flow 2: WalkGuide start, SOS, stop', (tester) async {
|
||||
if (!_liveApiConfigured) {
|
||||
// Keep CI green when live credentials are not injected.
|
||||
// The final benchmark run should pass LIVE_* dart-defines.
|
||||
return;
|
||||
}
|
||||
expect(userToken, isNotNull);
|
||||
final auth = Options(headers: {'Authorization': 'Bearer $userToken'});
|
||||
|
||||
final start = await dio.post('/user/walkguide/start', options: auth);
|
||||
expect(start.statusCode, 200);
|
||||
|
||||
final sos = await dio.post('/user/sos', data: {
|
||||
'triggerType': 'MANUAL',
|
||||
'lat': null,
|
||||
'lng': null,
|
||||
}, options: auth);
|
||||
expect(sos.statusCode, 200);
|
||||
|
||||
final stop = await dio.post('/user/walkguide/stop', options: auth);
|
||||
expect(stop.statusCode, 200);
|
||||
});
|
||||
|
||||
testWidgets('flow 3: guardian dashboard and user notifications', (tester) async {
|
||||
if (!_liveApiConfigured) {
|
||||
// Keep CI green when live credentials are not injected.
|
||||
// The final benchmark run should pass LIVE_* dart-defines.
|
||||
return;
|
||||
}
|
||||
|
||||
final guardianLogin = await dio.post('/auth/login', data: {
|
||||
'email': _guardianEmail,
|
||||
'password': _guardianPassword,
|
||||
});
|
||||
expect(guardianLogin.statusCode, 200);
|
||||
guardianToken = guardianLogin.data['data']['accessToken'] as String?;
|
||||
expect(guardianToken, isNotNull);
|
||||
|
||||
final guardianAuth =
|
||||
Options(headers: {'Authorization': 'Bearer $guardianToken'});
|
||||
final dashboard = await dio.get('/guardian/dashboard', options: guardianAuth);
|
||||
expect(dashboard.statusCode, 200);
|
||||
|
||||
final userAuth = Options(headers: {'Authorization': 'Bearer $userToken'});
|
||||
final notifications = await dio.get('/user/notifications', options: userAuth);
|
||||
expect(notifications.statusCode, 200);
|
||||
|
||||
final markAll =
|
||||
await dio.put('/user/notifications/mark-all-read', options: userAuth);
|
||||
expect(markAll.statusCode, 200);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user