feat: complete leave approval MVP
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import 'package:aioa_mobile/core/auth/authenticated_http_client.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/testing.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'attaches refreshed bearer token only to the configured API origin',
|
||||
() async {
|
||||
final captured = <http.Request>[];
|
||||
final client = AuthenticatedHttpClient(
|
||||
inner: MockClient((request) async {
|
||||
captured.add(request);
|
||||
return http.Response('', 200);
|
||||
}),
|
||||
apiOrigin: 'https://api.example.test',
|
||||
tokenProvider: () async => 'refreshed-token',
|
||||
);
|
||||
|
||||
await client.get(Uri.parse('https://api.example.test/api/v1/me'));
|
||||
await client.put(Uri.parse('https://minio.example.test/upload'));
|
||||
|
||||
expect(captured[0].headers['Authorization'], 'Bearer refreshed-token');
|
||||
expect(captured[1].headers['Authorization'], isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'package:aioa_mobile/core/forms/schema/form_schema.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('parses server data and UI schemas into safe control models', () {
|
||||
final definition = DynamicFormDefinition.fromJson({
|
||||
'key': 'leave-request',
|
||||
'version': 1,
|
||||
'dataSchema': {
|
||||
r'$id': 'leave-request-v1',
|
||||
'title': '请假申请',
|
||||
'required': ['type'],
|
||||
'properties': {
|
||||
'type': {
|
||||
'type': 'string',
|
||||
'enum': ['PERSONAL', 'SICK'],
|
||||
},
|
||||
},
|
||||
},
|
||||
'uiSchema': {
|
||||
'description': '远程定义',
|
||||
'sections': [
|
||||
{
|
||||
'title': '请假信息',
|
||||
'controls': [
|
||||
{
|
||||
'field': 'type',
|
||||
'label': '请假类型',
|
||||
'control': 'select',
|
||||
'optionLabels': {'PERSONAL': '事假'},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(definition.dataSchema.id, 'leave-request-v1');
|
||||
expect(definition.dataSchema.required, {'type'});
|
||||
expect(definition.dataSchema.properties['type']!.enumValues, [
|
||||
'PERSONAL',
|
||||
'SICK',
|
||||
]);
|
||||
expect(
|
||||
definition.uiSchema.sections.single.controls.single.control,
|
||||
FormControlType.select,
|
||||
);
|
||||
});
|
||||
|
||||
test('unknown controls cannot enter the renderer whitelist', () {
|
||||
expect(
|
||||
() => FormControlType.values.byName('remoteScript'),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user