diff --git a/packages/validate/test/async_test.dart b/packages/validate/test/async_test.dart deleted file mode 100644 index ab73b3a2..00000000 --- a/packages/validate/test/async_test.dart +++ /dev/null @@ -1 +0,0 @@ -void main() {} diff --git a/packages/validate/test/basic_test.dart b/packages/validate/test/basic_data_test.dart similarity index 100% rename from packages/validate/test/basic_test.dart rename to packages/validate/test/basic_data_test.dart diff --git a/packages/validate/test/complex_data_test.dart b/packages/validate/test/complex_data_test.dart new file mode 100644 index 00000000..23f0af56 --- /dev/null +++ b/packages/validate/test/complex_data_test.dart @@ -0,0 +1,66 @@ +import 'package:angel3_validate/angel3_validate.dart'; +import 'package:test/test.dart'; + +void main() { + final Validator orderItemSchema = Validator({ + 'id': [isInt, isPositive], + 'item_no': isString, + 'item_name': isString, + 'quantity': isInt, + 'description?': isString + }); + + final Validator orderSchema = Validator({ + 'id': [isInt, isPositive], + 'order_no': isString, + 'order_items*': [isList, everyElement(orderItemSchema)] + }, defaultValues: { + 'order_items': [] + }); + + group('json data', () { + test('validate with child element', () { + var orderItem = { + 'id': 1, + 'item_no': 'a1', + 'item_name': 'Apple', + 'quantity': 1 + }; + + var formData = { + 'id': 1, + 'order_no': '2', + 'order_items': [orderItem] + }; + var result = orderSchema.check(formData); + + expect(result.errors.isEmpty, true); + }); + + test('validate empty child', () { + var formData = {'id': 1, 'order_no': '2'}; + var result = orderSchema.check(formData); + + expect(result.errors.isEmpty, true); + }); + + test('validate invalid child field', () { + var orderItem = { + 'id': 1, + 'item_no': 'a1', + 'item_name': 'Apple', + 'quantity': 1, + 'description': 1 + }; + + var formData = { + 'id': 1, + 'order_no': '2', + 'order_items': [orderItem] + }; + var result = orderSchema.check(formData); + + expect(result.errors.isEmpty, false); + }); + }); +} diff --git a/packages/validate/test/context_aware_test.dart b/packages/validate/test/context_aware_test.dart deleted file mode 100644 index ab73b3a2..00000000 --- a/packages/validate/test/context_aware_test.dart +++ /dev/null @@ -1 +0,0 @@ -void main() {} diff --git a/packages/validate/test/server_test.dart b/packages/validate/test/server_test.dart index 31e0b20f..467c3f37 100644 --- a/packages/validate/test/server_test.dart +++ b/packages/validate/test/server_test.dart @@ -18,29 +18,27 @@ void printRecord(LogRecord rec) { } void main() { - Angel? app; + late Angel app; late AngelHttp http; //TestClient client; setUp(() async { app = Angel(); - http = AngelHttp(app!, useZone: false); + http = AngelHttp(app, useZone: false); - app!.chain([validate(echoSchema)]).post('/echo', + app.chain([validate(echoSchema)]).post('/echo', (RequestContext req, res) async { await req.parseBody(); res.write('Hello, ${req.bodyAsMap['message']}!'); }); - app!.logger = Logger('angel')..onRecord.listen(printRecord); + app.logger = Logger('angel3')..onRecord.listen(printRecord); //client = await connectTo(app); }); tearDown(() async { //await client.close(); await http.close(); - app = null; - //client = null; }); group('echo', () {