62 lines
1.8 KiB
Dart
62 lines
1.8 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:cyberhybridhub/admin/services/market_history_admin_api.dart';
|
|
import 'package:cyberhybridhub/admin/widgets/admin_gate.dart';
|
|
import 'package:cyberhybridhub/theme/app_theme.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/testing.dart';
|
|
|
|
MarketHistoryAdminApi gateApiWithStatus(int status) {
|
|
return MarketHistoryAdminApi(
|
|
tokenProvider: () async => 'token',
|
|
client: MockClient(
|
|
(http.Request request) async => http.Response(
|
|
status == 200
|
|
? jsonEncode(<String, dynamic>{
|
|
'runs': <dynamic>[],
|
|
'pinned': <dynamic>[],
|
|
'nextBefore': null,
|
|
})
|
|
: 'denied',
|
|
status,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('shows child when admin probe succeeds', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: buildAppTheme(),
|
|
home: AdminGate(
|
|
api: gateApiWithStatus(200),
|
|
child: const Scaffold(body: Text('admin content')),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('admin content'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('shows forbidden when admin probe returns 403', (
|
|
WidgetTester tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: buildAppTheme(),
|
|
home: AdminGate(
|
|
api: gateApiWithStatus(403),
|
|
child: const Scaffold(body: Text('admin content')),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('admin-gate-forbidden')), findsOneWidget);
|
|
expect(find.text('Not authorized'), findsOneWidget);
|
|
expect(find.text('admin content'), findsNothing);
|
|
});
|
|
}
|